OnTick versus OnTimer

OnTick versus OnTimer

Postby sleytus » Sun Jul 29, 2018 11:02 pm

My first post -- hopefully I created it at the right location. There are so many forums and threads here I wasn't sure.

I come from Forex Strategy Builder (FSB Pro) -- as a user -- but have written some supporting applications (mt4tracker.com). From poking around here I see the most popular EAs are using OnTimer -- as opposed to OnTick, as recommended by MetaQuotes. And I'm curious to learn more about how you came to that conclusion. I've searched the site but couldn't find an answer.

About a year ago I wrote an app called Portfolio Maker -- it bundles dozens of individual FSB Pro strategies into a *single* EA that can be attached to a single chart. I can see that people here are not into EA portfolios, but what Miroslav Popov has come up with is a very powerful concept that works (for some people, though not all).

While testing Portfolio Maker I observed that a bundled EA with dozens of strategies traded differently than strategies running individually in their own chart. For example, take a portfolio EA with 80 strategies -- perhaps only the first 10-15 would ever trade, and the latter 65 strategies never. Within the portfolio EA there is a loop and with each tick the loop is suppose to traverse all 80 strategies -- but this wasn't happening.

I'll cut to the chase -- I believe the explanation is the following, though I'm not 100% sure. MetaTrader4 uses a single thread for each chart. Furthermore, with each tick a new thread is started. All the code executes within a single thread. If a new tick arrives while the previous tick is still executing, MetaQuotes claims the old tick is allowed to complete -- but that is not 100% correct. If the previous tick is taking too long to complete -- e.g. it is executing code for 80 strategies -- then MetaTrader4 kills the thread and starts a new one. This is why only the first 10-15 strategies ever trade.

While searching for a solution to this problem I discovered that using OnTimer works -- I also use an interval of 10 seconds like you guys. Furthermore, calls to OnTimer are initiated by Windows and are allowed to run as long as they need without being killed by MetaTrader4. Just as most things in life are a trade-off -- so is using OnTimer. So long as OnTimer eventually completes in a timely manner then all is good. But if it hangs then your MetaTrader4 session is toast.

Again -- I don't have access to MetaTrader4's source code so I won't claim this is 100% correct, but this is what I've deduced. When I saw you guys also use OnTimer then that was a very pleasant surprise for me, since it helped to validate the approach I had taken. And now I'm really curious to learn what brought you around to using OnTimer (since MetaQuotes definitely does not encourage people to use it this way).


While I am at it I have an additional comment -- and this will probably get me banned. But that's okay -- by now I've grown used to rejection...

I do not share your disregard for Empty4Shit Tester. We have done lots of testing with many strategies under different scenarios. No doubt it may give misleading results, but we have found that is primarily due to the input data, along with settings for spread, commission and swap. For example. for many brokers their Demo data is different than their Real data -- so, you should *always* run Strategy Tester from a real account. But even if you don't trust the results -- there are still clues to be had. Also, for testing logic and troubleshooting bugs -- running Strategy Tester for a couple of minutes sure beats testing in a Demo account for months. And, as you are aware, there is a "disconnect" between Demo and Real accounts. So, even when you are done testing in a Demo account there is still a risk it will perform differently in a Real account -- and that doesn't even take into account that over the testing period the data patterns have changed and the constant, input settings used during testing are no longer a good match for the current data.

Steve (not Hopwood -- a different one)

OnTick versus OnTimer

Postby SteveHopwood » Mon Jul 30, 2018 1:05 am

You would have been better off staying quiet.
sleytus ยป Sun Jul 29, 2018 11:02 pm wrote:I do not share your disregard for Empty4Shit Tester.

I care not hoot whether you share our disregard for Empty4 Strategy Tester. That merely makes you an idiot incapable of learning the lessons that SHF is happy to teach you if only you were prepared to learn.

Sadly, being a dimwit results in your being unable to post at all in the future. Sod off and peddle your nonsense in forums that will accept you. SHF is for serious people, not cretins like you,

As usual when dealing with idiots, this thread is locked and the OP is on permanent moderation. My mods will only let his/her/its posts through if said post has something useful to offer.

Don't hold your breathes waiting for this this happen. My experience is this: once a dimwit, always a dimwit.

:xm: :rocket:
Read the effing manual, ok?

Global Prime is the official SHF broker. Click here to sign up for a live account with Global Prime and join the several thousand SHF members who wisely choose GP as their broker of choice.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Tommaso (milanese) for all the incredible work he does here.
User avatar
Posts: 9316
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Return to Automated trading systems

Who is online

Users browsing this forum: No registered users and 1 guest