using onBar() and onTick() at the same time
Created at 22 Sep 2016, 14:47
using onBar() and onTick() at the same time
22 Sep 2016, 14:47
Can we use onBar() and onTick() at the same time?
Or someone maybe can give me the logic by using onTick() but we can to wait until a bar is formed for condition?
Thanks
Replies
firemyst
26 Aug 2024, 02:22
> “Can we use onBar() and onTick() at the same time?”
Yes.
Example where you don't need the OnBar method:
// define at class level
private int _currentIndex;
private int _previousIndex;
//set _currentIndex in OnStart
_currentIndex = _marketSeries.OpenTimes.Count;
_previousIndex = 0;
//Do the following in OnTick
if (_currentIndex != _previousIndex)
{
//Call your OnBar Method
YourCustomOnBarForBot([parameters if any]);
//Update the previous index until it changes again
_previousIndex = _currentIndex;
}
//if needed, continue with the ontick method
//Or, if you don't want to do anything else with the tick when
//a new bar is formed, use an else clause
//else do the tick method when it's not the same tick a new bar is formed
else
{
}
@firemyst
... Deleted by UFO ...