I want to code this indicator:
Step:
1) Initialization
- a) take 200 bars from the past and process SMA for it. ( eg. SMA mySma = SMA(barsFromThePast, 200) )
- b) derive some stats from SMA processed in 1a) (eg. minimal/maximal difference)
2) onBarUpdate
- a) use stats from 1b) to draw proper information.
In my case I'll have SMA difference range and will divide into several levels (strong downtrend = -2, weak downtrend = -1, sideways = 0 , weak uptrend = 1, strong uptrend = 2)
The output of the indicator will be a SMA difference step function which will oscillate between -2...2 values
The question is: How to get historical SMA values in point 1a) before the indicator starts to onBarUpdate?
It’s possible to do this:
protected override void OnBarUpdate()
{ {
if(CurrentBar < 200) return;
...
E.g. To wait until 200 bar elapse and everything is computed, however it would take 200 bars just to start indicator plotting the correct values! This solution is not acceptable. If I had a 1D timeframe strategy I would wait 200 days just to start working my indicator correctly???
Same goes to strategies that process some stats from history (eg. 200 or 1000 bars back) before they even start onBarUpdate calls.
How to implement such initializations?
Thank you!
Comment