Please advise best practice for structuring computationally intensive Indicators hosted by a multi-time frame, single Instrument Strategy (e.g. ES 09-22).
Hosted Indicators are set to Calculate = Calculate.OnPriceChange, which allows current (intra-bar) Indicator exposed values to be accessed on all time frames. The Strategy evaluates all BarsArrays just before the close of a 1min bar. So, Indicator exposed values are only required at this time, the point of evaluation.
As the hosted Indicators calculate OnPriceChange, they are computationally intensive when calculating exposed values for Bar[0] on each PriceChange. It is sufficient to calculate and display Indicator exposed values for Bar[1] on IsFirstTickOfBar.
As the hosed Indicators only require update when 1) referenced by the Strategy and 2) on IsFirstTickOfBar, is it advisable to:
- Set all OnBarUpdate calculations to occur on IsFirstTickOfBar evaluating Bar[1], and
- Set a public method (EvaluateCurrentBar()) to be called by the hosting Strategy to evaluate Bar[0] after Update().
[FONT=Arial]protected override void OnBarUpdate()[/FONT] [FONT=Arial]{[/FONT] [FONT=Arial] if (IsFirstTickOfBar)[/FONT] [FONT=Arial] {[/FONT] [FONT=Arial] const int barsAgo = 1;[/FONT] [FONT=Arial] EvaluateBar(barsAgo);[/FONT] [FONT=Arial] }[/FONT] [FONT=Arial]}[/FONT] [FONT=Arial]public void EvaluateCurrentBar()[/FONT] [FONT=Arial]{[/FONT] [FONT=Arial] Update();[/FONT] [FONT=Arial] const int barsAgo = 0;[/FONT] [FONT=Arial] EvaluateBar(barsAgo);[/FONT] [FONT=Arial]}[/FONT] [FONT=Arial]private void EvaluateBar(int barsAgo)[/FONT] [FONT=Arial]{[/FONT] [FONT=Arial] // Do stuff[/FONT] [FONT=Arial]}[/FONT]
As always, thanks
Shannon
Comment