Three ways to use external data
What you write depends on what is in the file:- If the file contains OHLCV candles, write a
@sec_contextcallback and attach it withContext.calc_on(source=...), the same way you attach an additional instrument. See External candles from CSV. - If the rows have their own shape and each row needs processing, describe the row with a
@dataclassand write a@data_contextcallback forContext.calc_on(source=...). See Typed external data. - If you only need the latest row value on each chart bar, skip the callback and read the rows directly with
request_series[T](source=...).
sources.DataFeed and process the records with
@data_context or request_series. Feeds have no candle mode and no time frame. See
Live data from a feed.
Quick example
This indicator plots the daily close prices from an external candle CSV on any chart:External candle close
A CSV file is a snapshot
The file is fetched once, when the indicator instance is created. After that the data is frozen: the indicator works with the file’s history and receives no live updates, even if the file changes on your server. To pick up a new version, re-add the indicator to the chart. A cached copy may be served for up to about 10 minutes after the previous fetch.The platform does not archive your file. If it changes, the next run of the indicator or backtest can see different
data. Keep a stable copy of the file if you need reproducible backtests.
Rules common to all external sources
- External sources count toward the same limit as additional instruments requested with
Context.calc_on(). Identical requests are counted once. For a CSV, a request that differs in URL,time_column, time frame orlookaheadcounts as a separate instrument; for a feed, one that differs in URL orstale_afterdoes. - The time frame belongs to the call site, not to the file: you pass
time_frame=toContext.calc_on()orrequest_series(). For candle CSVs it is required, for typed data it is optional, and tick time frames are not supported. Feeds take no time frame at all. - The source must be publicly reachable over a secure scheme with a valid certificate; authentication headers cannot be sent. See CSV format and limits for file requirements and the error reference, and Feed protocol and limits for feed server requirements.
Indicators that use external data sources cannot be published to the TakeProfit marketplace.
The platform’s own TPO profiles are read through a source descriptor too, but they are internal
data: none of the rules on this page apply to
sources.Tpo, and an indicator that uses only TPO can be published like
any other.