using onBar() and onTick() at the same time

Created at 22 Sep 2016, 14:47
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
HA

harry

Joined 18.08.2016

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


@harry
Replies

... Deleted by UFO ...

harry
27 Sep 2016, 10:29

RE:

thanks for the confirmation

 

lucian said:

Yes, you can use onBar() and onTick() at the same time.

 


@harry

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