A memory for custom indicator calculations and other things that might cause “repaint of history”.
A good example of this “repaint” issue would be when you calculate EMA(c, 20) on “this” update, and EMA(c, 10) on the next (i.e. variable period length). So to overcome this issue with changing history, this command lets you do this:
-- Load prices local o = OpenPrices() local h = HighPrices() -- Calculate EMA using Adaptive Period length local ema = CC_OptimalIndicator( -- memory is not used in this calculation, as we do not use previous values for our calculations function(i, memory) local c = c[i] local o = o[i] local period = CC_AdaptivePeriod(o, c, 3, 20, 5, 20) return ArrayGet(EMA(c, period), 1) end )
So the command takes in a callback function, and it is called with an input for an index (which is used for the offset step in warmup period). To keep it optimal as possible, always return only 1 value from your calculation – not the whole array of values.
You can also do calculations that require the previously calculated values to be known by accessing the second input parameter in your callback function (named “memory” in the example above).
Adaptive period command: https://www.haasscripts.com/t/pshaicmd-adaptive-period-length/