I am trying to limit my code to executing only once per day while having COBC = false. I started with what I found previously:
if (CurrentBar < 2) return;
if (Time[0].DayOfWeek != Time[1].DayOfWeek) // new day, reset bool flag
{
signalMadeToday = false;
}
if(signalMadeToday = false)
{....Code...
signalMadeToday = true;
}
But when I have COBC = false, it constantly resets. I took a look at the printed output with the following and can see the first print shows a bool of True, while the second shows False.
if (CurrentBar < 2) return;
if (Time[0].DayOfWeek != Time[1].DayOfWeek) // new day, reset bool flag
{
Print(signalMadeToday.ToString());
signalMadeToday = false;
Print(signalMadeToday.ToString());
}
What is the issue here? I saw a post about this that recommended to do the following:
if (Bars.FirstBarOfSession)
{
// Store the strategy's prior number of trades
priorTradesCount = Performance.AllTrades.Count;
}
{
// Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
return;
}
But this caused my strategy to not function properly. I didn't spend too much time looking at this option, but even if it will work, it only pertains to trades (which is most important). But I also want to limit emails, drawing objects, etc., and I don't think this will do that.
So what is the issue with the bool being reset even though the logic says it should not reset until the next day? How can I get it to stay true throughout the day with COBC = false? Or what other way can I simply limit the code to executing once per day whatever it may be?
Thank you,
Regards,
Lee
Comment