I backtested on a IBFX demo and noticed this problem from data in 2008 till 2010. However testing from Jan 2010 till Jul 2010 found no problems. I find this very weird.
Tested on MBT demo account and also the same issue, however i noted 1 out of 5 the 5 long orders from Jan to Jul 2010 closed correctly, the other 4 closed as soon as long order is entered. The inconsistencies really puzzle me.
Something I'd try is to insert some Alerts where you think your problem is. The idea is that you want to see exactly what's going on when MT starts executing the possible trouble spot. For simple logical errors, this works the vast majority of the time. For example, do an Alert(Daily_ATR) and compare the results with what you expect by inspecting the chart. What I do in the backtester is open up the .txt log, do a CTRL+F to find any result, then go to the date and compare. I usually do a few trials of this (which you should do since the problem is inconsistent). Another thing you could do is use Visual Mode (that eliminates the problem of a bunch of Alerts showing up in the journal).
Just my $0.02. Hope it helps.
Something I'd try is to insert some Alerts where you think your problem is. The idea is that you want to see exactly what's going on when MT starts executing the possible trouble spot. For simple logical errors, this works the vast majority of the time. For example, do an Alert(Daily_ATR) and compare the results with what you expect by inspecting the chart. What I do in the backtester is open up the .txt log, do a CTRL+F to find any result, then go to the date and compare. I usually do a few trials of this (which you should do since the problem is inconsistent). Another thing you could do is use Visual Mode (that eliminates the problem of a bunch of Alerts showing up in the journal).
Just my $0.02. Hope it helps.
Hi
Thanks for the advice. Actually i had alerts in the code but i stripped them off to the bare minimum to post it here for easier and quicker reading. I am too using visualisation. The red(Buy) and aqua(Close) arrows showed up just adjacent to each other. I will follow you advice and insert the Alert for Daily_ATR just to be sure.
Have removed the Daily_ATR from the equation and replaced it with an arbitary number of 0.0100 and all the errors are gone.
So the problem was putting the Daily_ATR in the equation, does anyone have any idea why the Daily_ATR was causing the problem? I would really like to use the Daily_ATR rather than an arbitary no. of pips value
since the price range for different pairs differs
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I would need some help with my code. I have stripped it to the bare minimum and posted it below. Basically the code below says when 12EMA crosses above 26EMA and if the current price is above the closing price of Bar[1]+30pips, i would enter into a long order for 2 lots. I will then close 1 lot when price>=orderopenprice+DailyATR.
Now the problem is as soon as i long 2 lots, 1 lot will automatically close within 1-2 minutes. Im sure it is due to the part which is underlined but i am unable to find anything wrong with it. This happened on backtesting on MT4 on a demo account with 2 different brokers. The order so far had not closed on forward testing. I previously had an earlier version of the code and it worked as expected but i have deleted it. Does anyone know what is wrong?