Warm-up
An indicator that averages 14 bars has nothing to say until it has seen 14 bars. Those bars are its warm-up. Forge leaves them empty instead of inventing a value.
How the empty bars are marked
A missing value is NaN in arrays and null in JSON. It is never 0 and never a special number such as MQL5's EMPTY_VALUE. A comparison with NaN is false, so a condition built on a value still in warm-up does not fire.
An indicator states its warm-up with warmup, either a whole number or a function of its settings:
import forge as fg
from forge import param, ta
FORGE_API = 1
class Smooth(fg.Indicator):
name = "Smooth"
pane = "price"
period = param.Int(20, min=2, max=200)
avg = fg.Output.line("Average")
warmup = lambda self: self.period
def calculate(self, bars, start) -> None:
self.out.avg[start:] = ta.sma(bars.close, self.period)[start:]Chained indicators add up
An indicator built on another indicator starts later than either. A 14-bar average of a 14-bar RSI has no value for its first 27 bars: 14 for the RSI, then 13 more before the average has 14 values to work with.
On the chart and in a run
The chart and the test use the same warm-up. A chart window that starts later than the test still loads the bars before it, so the values on screen are the values the run used.