My code has 15 Data Series Loaded, & I'm trying to make it more efficient by having the main method only run on 1 iteration of the code, and not on every dataseries.
Right now, if i move the main method into something like
if (BarsInProgress == 0)
{
Main Method();
}
or
if (BarsInProgress == 15) // ie the Last DataSeries
{
Main Method();
}
Then it will cause a delay in the Signal output.
> So right now my only option is to have it run on every DataSeries , which is unnecessary
Is there a solution to this?
Thanks in advance :-)
private bool runOnce = true;
private int LastBarsArray = 0;
protected override void OnBarUpdate()
{
if (runOnce)
{
var totalDataSeries = BarsArray.Length; // Get the total number of data series loaded
LastBarsArray = totalDataSeries - 1;
runOnce = false;
}
if (BarsInProgress != 0)
{
UpdateSeries();
GetPrices();
Main_LogicA(); // The Signal is Fine, if i put the Main Methods Here. But it Runs on every DataSeries (ie 10+ )
Main_LogicB();
}
if (BarsInProgress == LastBarsArray)
{
Main_LogicA(); // If I Put the Main Method at the end of the OnBarUpdate. Then it Causes the output Signal to delay by 1 bar
Main_LogicB();
}
}
private void Main_LogicA()
{
// Print the BarsInProgress index and the current close price for the series
Print("BarsInProgress: " + BarsInProgress + " | CurrentBar: " + CurrentBar + " | Close Price: " + Closes[BarsInProgress][0]);
}
output
BarsInProgress: 1 | CurrentBar: 20718 | Close Price: 1.08894
BarsInProgress: 2 | CurrentBar: 20718 | Close Price: 0.85164
BarsInProgress: 3 | CurrentBar: 20718 | Close Price: 1.48824
BarsInProgress: 7 | CurrentBar: 20718 | Close Price: 0.96846

Comment