Download MetaTrader 5

Backtest bug with quantity of trades

To add comments, please log in or register
You can test an application before buying it. Find out how to do that!
Romain 2015.02.23 11:03 

Hi guys !

I am currently backtesting an EA and I have a problem with the quantity of trades . I can't seem to find a solution to that, anyone who know what it is ? :)

(SAME parameters, SAME product) ¨:  backtest for month of february (20 days)  : 23 trades.   Backtest for only february 18th (ONE DAY) : 65 trades.  How is that possible ?

Thanks to those who take the time to check my message out,



Carl Schreiber
Carl Schreiber 2015.02.23 12:50  

Without code?

whroeder1 2015.02.23 13:10  
Gobelet: How is that possible ?
  1. Your code is broken. Previous trades are affecting future ones.
  2. There are no mindreaders here. No code, no possibility of help.
Romain 2015.02.23 15:24  

Hi, thanks for your answer,  I didn't know the code was necessary for the problem. The code is pretty ugly, though, hope you don't mind, I'm not good at coding.. :)

 EDIT : it doesn't seem to accept my code in the SRC zone, it does't upload it..   I will try again tonight and in the meantime I attach the file. 

whroeder1 2015.02.23 16:33  
  1. Gobelet: How is that possible ?
    int     ATRMin                =atrMin*iATR(NULL,0,15,0);
    int     ATRMax                =atrMax*iATR(NULL,0,15,0);
    These are constant. Depends only in the first tick of tester. If you want them to update you must assign values in start.
  2.       bool BUY=false;
          bool BUY=  Check>0&&Check!=EMPTY_VALUE;
    Simplify when possible
  3.     for (int cnt = OrdersTotal(); cnt >= 0; cnt --){
          if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) {
        for (int cnt3 = OrdersTotal(); cnt3 >= 0; cnt3 --){
          if(OrderSelect(cnt3, SELECT_BY_POS, MODE_TRADES)) {
    Order positions are numbered [0 .. OrdersTotal() - 1] Your first iteration always fails.
  4.       OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
    Check your return codes. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  5.       if(OrderSymbol()!=Symbol()) continue;
          pp = MarketInfo(OrderSymbol(), MODE_POINT); 
    You know you're using current chart pair. Why use a function call instead of the predefined double _Point - MQL4 Documentation Why at all (pp not used.)

  6.    if(Hour()>=MondayToFridayStartHour && Hour()<MondayToFridayEndHour)
    Doesn't allow trading over midnight e.g. start=1900 end=0700
Romain 2015.02.23 17:02  

Thank you so much for your help !  I will give a look at this tonight and see if it solve the problems, thank you for your time again !

Edit : for the point 3)  I don't really understand. Isn't the line " >= 0" there to make sure that the first iteration does not fail ?

        4)  you are right I should check them, I'm not used to check them yet, as I've not been coding for a long time and as I code for myself (as you can see by the lack of commentaries // next to the code ;) )

        6)  I don't intend to trade before StartHour and after EndHour, which is why I wrote that line. I think the positions will be kept overnight by the robot anyway.

whroeder1 2015.02.23 19:02  
Gobelet: t 3)  I don't really understand. Isn't the line " >= 0" there to make sure that the first iteration does not fail ?
Look at your other OrderSelect loops
Keith Watford
Keith Watford 2015.02.23 19:36  
for (int cnt = OrdersTotal()-1; cnt >= 0; cnt --)
Romain 2015.02.24 12:05  

Hello guys, 


I cleaned the code and changed everything you told me to change, it all works very good now. Thank you very much for your help and your time, it is very appreciated. Hope I can turn the favuor to you someday. 



To add comments, please log in or register