Download MetaTrader 5
To add comments, please log in or register
Carry on your private correspondence in your profile. It is secure!
tbaronetti
26
tbaronetti 2015.08.12 18:40 

Newbie query:

Can anyone help me with my understanding of the EA OnTick Function?

I have developed a simple custom indicator and I access this indicator from within a custom EA I have also developed. I am using the OnTick function to process each tick and assess aganist the indicator values to determine whether the tick price (bid/ask) has crossed a specific value as determined by the indicator. However, I was surprsied to note that when I run the EA against EUR/USD daily history, if the strategy tester is set to process data in fast mode, it skips a great many ticks (minutes or even hours) because the OnTick function simply is not called while it (OnTick) is still busy processing a previous tick. It appears that the Strategy Tester simply continues processing subsequent tick data, while the EA is busy processing its current tick. When OnTick has completed processing a tick, the strategy tester simply passes to the EA the current tick it happens to be processing itself, which is often many ticks later than the one the EA has just completed processing. This results in incorrect backtesting results as the trades as executed later than they should be.

A solution to the problem is simpy to slow down the Strategy Tester to a  speed whicj my local processor can handle, and that's fine. But what worries me is that there is no warning indicating that ticks are being dropped. Whilst that is a serious issue for backtesting, it is perhaps equally important when the EA is trading in a live environment, as the market may have moved quite significantly by the time an actual live trade is triggered, if the market is particulary active. I see also that MT5 gruops ticks together in very active market conditions, so it may not become an issue in the live trading mode.

Is there a way to ensure that the strategy tester does not skip ticks or at least warns a user when it does? Any help appreciated.

Alain Verleyen
Moderator
28518
Alain Verleyen 2015.08.12 18:56  
tbaronetti:

...

OnTick function simply is not called while it (OnTick) is still busy processing a previous tick.

...

Wrong, that never happens within the ST. The MT5 Strategy Tester don't skips any tick. It process ALL ticks provided by the chosen mode. If your EA is "tick" depending you need to use Every tick mode.

Of course if you set "Open prices only" or "1 minute OHLC" you will only get 1 or 4 ticks by candle respectively.

tbaronetti
26
tbaronetti 2015.08.13 15:02  
Alain Verleyen:

Wrong, that never happens within the ST. The MT5 Strategy Tester don't skips any tick. It process ALL ticks provided by the chosen mode. If your EA is "tick" depending you need to use Every tick mode.

Of course if you set "Open prices only" or "1 minute OHLC" you will only get 1 or 4 ticks by candle respectively.

Thank you for your prompt response, Alain. Firstly, just to be clear, I am not referring to testing an EA, but testing an indicator on historical data. My previous post was incorrect as it was the OnCalculate function I was referring to and not the onTick function. My mistake. However, as I was Printing tick prices to the ST Journal, it is possible that all ticks were indeed processed, but not all were written to the journal. I will continue testing as it may be an issue with my own MQL5 code.

Alain Verleyen
Moderator
28518
Alain Verleyen 2015.08.13 16:20  
tbaronetti:

Thank you for your prompt response, Alain. Firstly, just to be clear, I am not referring to testing an EA, but testing an indicator on historical data. My previous post was incorrect as it was the OnCalculate function I was referring to and not the onTick function. My mistake. However, as I was Printing tick prices to the ST Journal, it is possible that all ticks were indeed processed, but not all were written to the journal. I will continue testing as it may be an issue with my own MQL5 code.

If there is too much output to the logs they don't all appears in the Journal window. You have to open file (or the Viewer) to see the all the logs.
Rizal Dwi Satria
326
Rizal Dwi Satria 2016.05.30 09:40  
tbaronetti:

Newbie query:

Can anyone help me with my understanding of the EA OnTick Function?

I have developed a simple custom indicator and I access this indicator from within a custom EA I have also developed. I am using the OnTick function to process each tick and assess aganist the indicator values to determine whether the tick price (bid/ask) has crossed a specific value as determined by the indicator. However, I was surprsied to note that when I run the EA against EUR/USD daily history, if the strategy tester is set to process data in fast mode, it skips a great many ticks (minutes or even hours) because the OnTick function simply is not called while it (OnTick) is still busy processing a previous tick. It appears that the Strategy Tester simply continues processing subsequent tick data, while the EA is busy processing its current tick. When OnTick has completed processing a tick, the strategy tester simply passes to the EA the current tick it happens to be processing itself, which is often many ticks later than the one the EA has just completed processing. This results in incorrect backtesting results as the trades as executed later than they should be.

A solution to the problem is simpy to slow down the Strategy Tester to a  speed whicj my local processor can handle, and that's fine. But what worries me is that there is no warning indicating that ticks are being dropped. Whilst that is a serious issue for backtesting, it is perhaps equally important when the EA is trading in a live environment, as the market may have moved quite significantly by the time an actual live trade is triggered, if the market is particulary active. I see also that MT5 gruops ticks together in very active market conditions, so it may not become an issue in the live trading mode.

Is there a way to ensure that the strategy tester does not skip ticks or at least warns a user when it does? Any help appreciated.

better make manual not auto like ontick , using manual function would be less cpu cost

if you use onTick, all tick on currencies that you open will trigger OnTick

/
To add comments, please log in or register