Download MetaTrader 5

mt5 strategy tester incorrectly remembering previous input values

To add comments, please log in or register
strontiumDog
292
strontiumDog  

Hello

I'm getting this weird result from MT5 strat tester.  I have the simplest code snippet to prove that the problem is reproducable. I assign a few external input variables in the code.  I run the code and check the journal of the tester as I output the values.  When I stop the test, close the window, edit the variable values so they are different, and then restart the test from the terminal, the output in the journal log are the ones from the previous test and not the current one.  Argh!  Why is this, and how can I work around the problem?

Code:


#property copyright "Copyright 2013"
#property link          "http://a.b.com"
#property version       "2.0"

input int     gap = 7;                
input int     tss = 20;               
input int     baa = 18;                
int SL, TP, TS;

int OnInit() { 
        // Let us handle currency pairs with 5 or 3 digit prices instead of 4
        SL = gap;
        TP = tss;
        TS = baa;
        if(_Digits==5 || _Digits==3) {
                SL = SL * 10;
                TP = TP * 10;
                TS = TS * 10;
        }

        Print("INIT: SL: ", SL);
        Print("INIT: TP: ", TP);
        Print("INIT: TS: ", TS);

        return(0);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                    |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {

}

//+------------------------------------------------------------------+
//| Expert tick                                                 |
//+------------------------------------------------------------------+
void OnTick() {
}

The result of this in the tester:

2013.04.30 13:11:51     2011.07.18 00:00:00   INIT: TS: 70
2013.04.30 13:11:51     2011.07.18 00:00:00   INIT: TP: 200
2013.04.30 13:11:51     2011.07.18 00:00:00   INIT: SL: 180
2013.04.30 13:11:51       baa=7
2013.04.30 13:11:51       tss=20
2013.04.30 13:11:51       gap=18

And now I modify the code from the above EA:

input int     gap = 6;                
input int     tss = 20;               
input int     baa = 1

And the resulting output is

2013.04.30 13:23:04     2011.07.18 00:00:00   INIT: TS: 70
2013.04.30 13:23:04     2011.07.18 00:00:00   INIT: TP: 200
2013.04.30 13:23:04     2011.07.18 00:00:00   INIT: SL: 180
2013.04.30 13:23:04       baa=7
2013.04.30 13:23:04       tss=20
2013.04.30 13:23:04       gap=18

So exactly the same as the previous run.  When I edited the code and recompiled, I would expect to see an updated journal. What's happening?

Cheers

Alain Verleyen
Moderator
32833
Alain Verleyen  
strontiumDog:

Hello

...

So exactly the same as the previous run.  When I edited the code and recompiled, I would expect to see an updated journal. What's happening?

Cheers

This is not a bug, it's a feature ;-) You don't have to change your code to test with others parameters values. As you have declared them as "input", you can change these values directly from the Inputs tab on the Strategy Tester.

If you right-click within this tab, you have context menu with more options to save, load or reset to defaults.

strontiumDog
292
strontiumDog  

Oh good - an aspect I'd missed.  Cheers.

Although shortly after I read your post, I looked again.  Notice

input int     gap = 7;

and then

SL = gap;

and then

SL = SL * 10;

and then

Print("INIT: SL: ", SL);

which with my broker means the output should be 70.  But as we see above, we get

2013.04.30 13:23:04     2011.07.18 00:00:00   INIT: SL: 180
Irrespective of the constance of the input variables within the code, this doesn't look right to me or is there an explanation? Let me know if I should post this separately. 
Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
strontiumDog:

Oh good - an aspect I'd missed.  Cheers.

Although shortly after I read your post, I looked again.  Notice

and then

and then

and then

which with my broker means the output should be 70.  But as we see above, we get

Irrespective of the constance of the input variables within the code, this doesn't look right to me or is there an explanation? Let me know if I should post this separately. 
If you change the name of your EA and run it in the Strategy Tester it will take the default values,  if you change the values, even if you recompile the code,  the last used values will still be used.
Alain Verleyen
Moderator
32833
Alain Verleyen  
strontiumDog:

Oh good - an aspect I'd missed.  Cheers.

Although shortly after I read your post, I looked again.  Notice

and then

and then

and then

which with my broker means the output should be 70.  But as we see above, we get

Irrespective of the constance of the input variables within the code, this doesn't look right to me or is there an explanation? Let me know if I should post this separately. 

This is the result of running in the Strategy Tester ?

If yes, then what is the value of gap in Inputs tab of Strategy Tester ?

strontiumDog
292
strontiumDog  

Ah yes I see it is 18.  Which explains everything except how it was originally given this value.  I imagine it must have been a typo somewhere as I renamed the vars for the post.

Thanks for your help.

Alain Verleyen
Moderator
32833
Alain Verleyen  
strontiumDog:

Ah yes I see it is 18.  Which explains everything except how it was originally given this value.  I imagine it must have been a typo somewhere as I renamed the vars for the post.

Thanks for your help.

You are welcome.
To add comments, please log in or register