What approach do you recommend for referencing an indicator "on bar close" in a real time strategy? I can think of the following two ways.
1) Adding the indicator to the strategy for calculation update on every tick and then referencing an output series one bar ago on FirstTickOfBar.
You will have to make sure somehow that the indicator is updated on the last tick of the previous bar if you want to reference the output series on FirstTickOfBar, haven't you?
2) Shift the entire code of the indicator back one value to be calculated on FirstTickOfBar as decribed in your sample "Separating logic to either calculate once on bar close or on every tick" and then referencing and output series one bar ago. (I use the varibale below to shift between COBC= true and COBC= false.)
protected override void OnBarUpdate() { if ( FirstTickOfBar ) { // Shift between RT and COBC int x = (CalculateOnBarClose || Historical) ? 0 : 1; } else { return; } Values[0][x].Set(x, myOutput); }
The first approach means that the indicator has to be calculated for every tick which is computation intense, while the second approach will need more coding for shifting the indexes one bar. Are there other better aproaches?
// Best Regards
Poseidon
Comment