Chart context and requested context are different
On a 15-minute chart, requesting a 20-period hourly EMA means calculating over hourly closes before alignment. Calculating an EMA after requesting and filling hourly closes instead averages a chart-bar series with repeated values. Those are different calculations. Context also includes session settings, price adjustments, and chart type.
- For another symbol at the chart timeframe, start with timeframe.period. Do not add an HTF delay unless the intended rule requires one.
- For invalid symbols, ignore_invalid_symbol = true returns na instead of stopping the script. Handle that missing value explicitly.
| Argument | Decision to make |
|---|---|
| symbol | Use syminfo.tickerid for the chart ticker, or an explicit exchange-qualified ticker for another market. |
| timeframe | "60" means 60 minutes; "1D" means one day. An empty string uses the chart timeframe. |
| expression | Calculate in the requested context. Put the history offset inside the expression when selecting a previous HTF bar. |
| gaps | gaps_off fills missing mapped values; gaps_on leaves na where new requested data is not yet confirmed. |
| lookahead | Controls historical alignment. lookahead_off is the default; lookahead_on needs special care with HTF expressions. |