Code after the end of Calculate() scanning all history bars, and won't run again in each Calculate at last bar?
Created at 03 Jul 2023, 20:26
Code after the end of Calculate() scanning all history bars, and won't run again in each Calculate at last bar?
03 Jul 2023, 20:26
Hello, is there any way, we can run a piece of code after the end of Calculate() scanning all history bars, and it won't run again in each calculation of the last bar?
public override void Calculate(int index)
{
if (IsLastBar) { } //Calculate only at LastBar
else { } //Calculate History Bars
}
I've tried putting the code at the bottom of Initialize(), however, the piece of code will need to do some work based on the code after Calculate() scanned history bars, so the code in Initialize() won't work as my demand.
Currently, I have to manually run once after the indicator is loaded.
Any advice, thanks.
Capt.Z-Fort.Builder
03 Jul 2023, 21:14 ( Updated at: 21 Dec 2023, 09:23 )
Sorted by creating a bool scanningComplete where at the beginning of the code and to enter the code is true, at the end of the code is false.
While, it brings another interesting issue, below screen chops are debugging in VS:
At the end of Initialize() the Bars Count is more than 7K of Bars number, but in the Calculate(), when it scans each history bar, the Bars.Count() is far less than 7K. This makes the bool ScanningComplete check many times (2K+) until it reaches 7K+ the same number as in Initialize()...
Sorted, just make a new private integer to record the Bars.Count-2, and then use it in the bool ScanningComplete check (of HistoryBar scanning).
It runs only once and perfectly fits my request now...
Job done!
@Capt.Z-Fort.Builder