Difference between overriding OnBar/OnTick and subscribing to Bars.BarOpened/Tick event
Difference between overriding OnBar/OnTick and subscribing to Bars.BarOpened/Tick event
25 Mar 2021, 16:52
Hello there,
Every samples I saw so far override virtual methods OnBar / OnTick of the Robot class, but I recently came across the Algo.Bars.BarOpened and Algo.Bars.Tick events, which are really handy !
And I'm wondering... Is there any differences of using the overrides instead of a classic event subscription ? Or are they two ways of doing the exact same thing (which can be confusing)?
From what I tested, it looks like the same, with a few more information on the BarOpened/Tick events:
- we can be notified of bars/ticks on other timeframes than the current one if we subscribe to another Bars
- we know from the Tick event if it is the first tick of a bar (really useful !)
- events are triggered and executed before the override methods
Overall, I feel like override methods are just there to satisfy MetaTrader developers, but that there is no reason to choose them over events.
Can someone confirm / deny ?
Thanks for your answers,
Cheers,
Jerry
Replies
JerryTrader
26 Mar 2021, 09:21
RE:
amusleh said:
Hi,
BarOpened/Tick events were added in recent versions of Automate API, they were not available in older versions.Both do the same thing but if you are developing a single time frame/symbol based indicator/cBot then you should use the overridden methods because that's much easier and you don't have to subscribe for the events, and if you are developing a multi symbol/ time frame indicator/cBot then you should use the BarOpened/Tick events.
Ok, thanks for your detailed and precise answer !
Everything's clear
@JerryTrader
amusleh
26 Mar 2021, 08:39
Hi,
BarOpened/Tick events were added in recent versions of Automate API, they were not available in older versions.
Both do the same thing but if you are developing a single time frame/symbol based indicator/cBot then you should use the overridden methods because that's much easier and you don't have to subscribe for the events, and if you are developing a multi symbol/ time frame indicator/cBot then you should use the BarOpened/Tick events.
@amusleh