EA recommendations

HarriMQL5
330
HarriMQL5  

Hello

I have an EA that performs well in backtest and I am trying to take it to the next level - performing on a demo account. But I am lost as to what is good practice to make it reliable, robust to recover from MT4 crash.

E.g. - error handling. Apart from (obviously) logging the error, exactly how do you "handle" it? Some error codes suggest waiting for some time, then retrying, but if the error you get is not one of these, then what? Have the EA disable itself (is this possible from mql code)?

I have recently setup a VPS, and discovered the big difference between running in backtest vs forward-test on demo account. The first thing I doscovered was the "old tick" message (after login messages), and my EA was not functioning. From searching the forums I discovered the meaning of this message, but not the appropriate way to handle it.

Are there any recommendations available for people to look at? I have some programming experience (15 years, albeit NOT in MQL), and I know how to read documentation. Just need some guidelines.

IF anyone has any insights, they would be welcome! (I'm hoping cloudbreaker sees this post). Unless the EA is totally lying to me in backtest, it looks very promising - see attachment.

cheers

P.S. - I've

Ubzen
5301
Ubzen  

Starting from bottom up. Didn't attach...I hope it was the EA you're trying to attach as that would provide better insight than a Equity Curve. CloudBreaker is not active anymore. Your guideline is the Documentations. The best examples and advise I've seen are the OrderReliable.inclued file. Articles can be helpful too, like here and here.

Generally, you wanna program the EA to avoid these errors ahead of time. During the error itself is not the best place to solve the problem. Disable the program is usually recommended by the docs. But Imo it depends on the type of error. Most ppl here use the OrderReliable in addition to some Pre-Checks. Some people log error messages away, I'm thinking of saving the last error message in a Terminal Variable.

HarriMQL5
330
HarriMQL5  
ubzen:

Starting from bottom up. Didn't attach...I hope it was the EA you're trying to attach as that would provide better insight than a Equity Curve. CloudBreaker is not active anymore. Your guideline is the Documentations. The best example's and advise I've seen are the OrderReliable.inclued file. Articles can be helpful too, like here and here.

Generally, you wanna program the EA to avoid these errors ahead of time. During the error itself is not the best place to solve the problem. Disable the program is usually recommended by the docs. But Imo it depends on the type of error. Most ppl here use the OrderReliable in addition to some Pre-Checks. Some people log error messages away, I'm thinking of saving the last error message in a Terminal Variable.

Ok, thanks for replying and the links. I will go through them carefully. I already know about OrderReliable and I already handle the more obvious "common" errors. My post was more to do with: how do you recover in MT4 when the connection is lost to the quotes server. or something along similar lines.
Ubzen
5301
Ubzen  

I'm of the opinion that there's no such thing as bullet-proofing. Cb- preached a sermon about Disaster Recovery, from (IMO) a stand-point which seemed more like a System Administrator. For me, it's not that serious (at least not at this point in time). If your VPS crashes/lose-its-connection then it's defeating it's purpose. Having 3 other Vps's mirrored, Live and Raid seems a bit redundant. Even if the EA is sitting on the broker's server, it can miss a beat.

The best thing I can think of is an EA which reports it's self as being connected every so often through email. If it misses the check in then a back-up Vps may take over. Most Vps providers should provide these types of services during times of maintenance. But it'll be interesting to see what others say about Crash/Connection Bullet-Proofing.

brewmanz
486
brewmanz  

I try to always have a TP & SL set just in case my connection goes AWOL, even if I keep adjusting them in line with my strategy.

The question I ask myself is, "Should my computer die, would I be happy to exit & take loss or profit at these prices?"

HarriMQL5
330
HarriMQL5  
ubzen:

I'm of the opinion that there's no such thing as bullet-proofing. Cb- preached a sermon about Disaster Recovery, from (IMO) a stand-point which seemed more like a System Administrator. For me, it's not that serious (at least not at this point in time). If your VPS crashes/lose-its-connection then it's defeating it's purpose. Having 3 other Vps's mirrored, Live and Raid seems a bit redundant. Even if the EA is sitting on the broker's server, it can miss a beat.

The best thing I can think of is an EA which reports it's self as being connected every so often through email. If it misses the check in then a back-up Vps may take over. Most Vps providers should provide these types of services during times of maintenance. But it'll be interesting to see what others say about Crash/Connection Bullet-Proofing.



Ok, I hear what you're saying. My main concern is not that the VPS crashes/loses connection (which is not impossible), but how MetaTrader and my EA recovers after the VPS comes back. The reason why I went the VPS+EA route is I do not have to sit there all the time waiting for a signal to come in. I travel a bit, and I may not be able to physically get to an Internet connection in time to enter/close a trade. So it's got to be automatic.

As you mentioned the EA-heartbeat idea, I had the same idea, which I think will go into the next version.

William Roeder
23729
William Roeder  
HarriMQL4:
I have an EA that performs well in backtest
Unless the EA is totally lying to me in backtest,

Optimize in one period of time, then run those settings in a un-optimized period.

Nice video series at Optimizing Your Parameters for Maximum Performance | Invest Press - Forex Trading Research and News You Can Use



Ubzen
5301
Ubzen  

...but how MetaTrader and my EA recovers after the VPS comes back...

The EA should be programmed to Not make assumptions about the last state still being the current state.

Example: I had an EA with fibonacci lot sizing (another poor excuse for martingale like sizing); double Size[]={1, 2, 3, 5, 8, 13, 21, 34, 55}. I had a global variable called Cnt which when up by 1 each time to stack the position going against me. Cnt kept the position of the progression, but it was bad idea to use a save-state variable for lots of reasons. The safer option would be to cycle through the last order(s) and check their sizes, in case of a reboot.

Example: my EA had a global extern variable called int Mode (1=Trend, -1=counterTrend). This ea was attached to the 6 major currencies when my woman kicked my power cord :). EurUsd was in Trend mode and UsdJpy was in cTrend mode etc. When the computer rebooted all the symbols mode went back to the compiled state Trend. To solve this problem, I had to choose between file-read-write variable Mode(state) or Terminal Variables, I've opted for Terminal Variables.

The options of where you save and how u retrieve State are limitless. Global, File, Email, Online Server or even in Remote wireless drive locked in a FireProof/FloodProof briefcase. All have their advantages and dis-advantages. I just said skip it, like brewmanz said save a stop-loss you can live with. In addition to that Check-In every 15min/Hour/Day depending on how critical this account is to me. If Ea/Broker down, spring into action and Telephone the broker.

I like you, am trying to create the world's greatest dont-bother-me EA, I just don't wanna give myself the false era that it's bullet-proof (tho we should strive to bullet-proof). I mean we're still Traders ;) are we not.

Added: If you're asking how mt4 auto-reboots after a restart. Then thats more of a question for your vps provider.

HarriMQL5
330
HarriMQL5  
ubzen:

...but how MetaTrader and my EA recovers after the VPS comes back...

The EA should be programmed to Not make assumptions about the last state still being the current state.

Example: I had an EA with fibonacci lot sizing (another poor excuse for martingale like sizing); double Size[]={1, 2, 3, 5, 8, 13, 21, 34, 55}. I had a global variable called Cnt which when up by 1 each time to stack the position going against me. Cnt kept the position of the progression, but it was bad idea to use a save-state variable for lots of reasons. The safer option would be to cycle through the last order(s) and check their sizes, in case of a reboot.

Example: my EA had a global extern variable called int Mode (1=Trend, -1=counterTrend). This ea was attached to the 6 major currencies when my woman kicked my power cord :). EurUsd was in Trend mode and UsdJpy was in cTrend mode etc. When the computer rebooted all the symbols mode went back to the compiled state Trend. To solve this problem, I had to choose between file-read-write variable Mode(state) or Terminal Variables, I've opted for Terminal Variables.

The options of where you save and how u retrieve State are limitless. Global, File, Email, Online Server or even in Remote wireless drive locked in a FireProof/FloodProof briefcase. All have their advantages and dis-advantages. I just said skip it, like brewmanz said save a stop-loss you can live with. In addition to that Check-In every 15min/Hour/Day depending on how critical this account is to me. If Ea/Broker down, spring into action and Telephone the broker.

I like you, am trying to create the world's greatest dont-bother-me EA, I just don't wanna give myself the false era that it's bullet-proof (tho we should strive to bullet-proof). I mean we're still Traders ;) are we not.

Added: If you're asking how mt4 auto-reboots after a restart. Then thats more of a question for your vps provider.



In the init() of the EA I set the magic number (in case I'm foolish/greedy enough to run on more than one currency at a time!) and store that number in a Global Var and to file. On deinit(), the var and file are deleted/removed. If the EA comes back after a crash, it will check to see if it's magic number is in globals. If not there, then it will check for the existence of the file. And that way pick up the orders that were left management-less when the crash happened. That's the theory, anyway :))

I've just successfully tested a server restart that will bring up MetaTrader automatically, and the EA with it. :) Now I have follow another suggestion and do an optimized run....

HarriMQL5
330
HarriMQL5  
WHRoeder:

Optimize in one period of time, then run those settings in a un-optimized period.

Nice video series at Optimizing Your Parameters for Maximum Performance | Invest Press - Forex Trading Research and News You Can Use





Very nice link, thank you! Unfortunately, I've just realized that I cannot optimise my EA because it must be run in visual mode to work. Why? Because of the indicator issue described here: https://forum.mql4.com/5980#470715 (you can see also this reference: https://book.mql4.com/samples/icustom)

Basically, to get around this issue, I have the indicator running on the chart (ie, in visual mode in StrategyTester) and it writes to global variables which the EA then reads. But optimizer cannot be run in visual mode.

Good job the indicator is A+ in giving signals, and I'm pretty happy with the indicator settings as they are. But I cannot do much about optimizing the EA variables, or can I?