Download MetaTrader 5

Need some explanation about strategy tester:

To add comments, please log in or register
forexCoder
507
forexCoder  

Greetings everyone,

in a few of my previous posts I've managed to slander a bit on the built-in strategy tester in MT4 platform. I decided that before I continue in doing that, I'd like to first give it a very good tryout so I started it up and was about to let it run an EA of mine. That's when I realized that I had no decent knowledge on how to operate the tool. I've searched the mql4 sites for some explanation on how to use it, but there seems to be no such wiki. I was looking for something like this (for the client itself) and was left disappointed:)

So I'd be very happy If you could point me to some reference for strategy tester or if you would answer some of the questions below:

1) If you open the "Expert properties" you're greeted with a dialog with 3 tabs.

a) tab "Testing": - What is the meaning of "Optimized parameter" ? What does changing this setting change in how the EA is run through the history?

- What does the enabling "Genetic algorithm" do?

b) tab "Optimization": - What does the checking of any of the listed boxes do?

c) Why do you have to choose optimization in both a) and b) tabs? Or if I rephrase: what is the difference when you choose the "optimized parameter" in tab a) or check a limitation box in tab b)?

2) What does "Visual mode" do? Found the answer in the F1 help of the MT4.

3) What and how is being optimized if the checkbox for "Optimization" gets enabled (on the far right side of the dropdown for the tick modelling) Found the answer in the F1 help of the MT4.

Thank you all in advance,

FC

Ubzen
5394
Ubzen  

Here's a link I started with when I was a Newbie. They've updated the site allot more. And here's more.

forexCoder
507
forexCoder  
This is great! Thanks!
forexCoder
507
forexCoder  

Question:

Is there a way to modify the speed of visual tester better than the slider that's there?

To me speed 31 is way too slow and 32 is WAY too fast. I could use 4 more speeds between those 2.

whroeder1
15351
whroeder1  
forexCoder:
To me speed 31 is way too slow and 32 is WAY too fast. I could use 4 more speeds between those 2.
Agreed. Sadly no.
zzuegg
1505
zzuegg  
AFAIK there is some button F*something* to go to the next tick in pause mode. Maybe an external program could be used to send that command, similar to the fake tick generator.
forexCoder
507
forexCoder  

Thanks.

Have a new one:

How does strategy tester make a pool of the orders it creates? If for example you have open orders in client and you start the tester, will the OrdersTotal and OrderSelect go through the list of orders created in strategy tester AND in the list of orders that you actually trade or not?

If not I can cancel some conditional checks in every OrdersTotal loop. Might speed things up a bit.

Fc

Ubzen
5394
Ubzen  
AFAIK. The tester creates the pool in it's own environment. There's a tester folder where I think it holds these information. Everything in mt4 affects the speed of back-tester. From compact data/volumes to huge-programs. Sometimes it depends on how it's programmed, sometimes on the tester's setting/output. I recommend you investigate Zzuegg's option to slow the tester down. To speed things up, stream-line the code and don't process un-necessary ticks. I only use back-tester for simple ideas/codes.
Phillip
800
Phillip  
zzuegg:
AFAIK there is some button F*something* to go to the next tick in pause mode. Maybe an external program could be used to send that command, similar to the fake tick generator.

You can have your EA programmatically send keyboard commands to the tester while in visual mode to pause and unpause the backtest. You could set this up with the desired frequency of pausing and unpausing to artificially slow-down the tester when operating at speed of "32".

To have your EA detect if the visual tester is active use IsVisualMode()

It takes some playing around with to tune the desired delay between successive pausing/unpausing events, but here is the basic code structure for programmatically pausing the tester in visual mode:
               // pause chart in visual mode if backtesting
               if(IsVisualMode()==true)
                  {
                  keybd_event(19,0,0,0);  // simulate depressing the pause button on the keyboard
                  i=0;
                  while(i<1000000)        // count loop necessary to force long enough delay that the system acknowledges/recognizes the pause button was depressed
                     {
                     i++;
                     }
                  keybd_event(19,0,2,0);  // simulate unpressing the pause button on the keyboard
                  }

To unpause the backtester you have the EA execute both the pause and unpause within the same call routine (be it the init() or start() or call function, etc):
               // un-pause chart in visual mode if backtesting
               if(IsVisualMode()==true)
                  {
                  keybd_event(19,0,0,0);  // simulate depressing the pause button on the keyboard
                  i=0;
                  while(i<1000000)        // count loop necessary to force long enough delay that the system acknowledges/recognizes the pause button was depressed
                     {
                     i++;
                     }
                  keybd_event(19,0,2,0);  // simulate unpressing the pause button on the keyboard
                  }

You need to have the routine do "something" between the pausing and unpausing like counting the numbers such that the "halt" effect is the desired level of delay.

In my case I use a call function I called "manual delay"
#include <Manual_Delay_2010.12.13.mqh>

Then anywhere I would normally have my EA sleeping, when backtesting in visual mode I have it take a forced manual delay:
   Sleep(1200);                                                 // sleep 1.2 seconds
   if(IsVisualMode()==true) IsTestingDelay(1200);               // simulate a 1.2 second delay when backtesting in visual mode
whroeder1
15351
whroeder1  
zzuegg:
AFAIK there is some button F*something* to go to the next tick in pause mode. Maybe an external program could be used to send that command, similar to the fake tick generator.
F12
/*                                          PauseTest
// https://www.mql5.com/en/forum/128554 */
#include <WinUser32.mqh>
#import "user32.dll"
  int GetForegroundWindow();
#import
void PauseTest(){       datetime now = TimeCurrent();   static datetime onePerTick;
    if (IsTesting() && IsVisualMode() && IsDllsAllowed() && onePerTick != now){
        int main = GetForegroundWindow();                   onePerTick = now;
        PostMessageA(main, WM_COMMAND, 0x57a, 0);  }   // 1402. Pause
}//*/

The above an be used to programmatically pause the tester. I call it right after making any orderModify. However it doesn't reliably pause the tester at speed=32


Update, reliably pauses with the addition of

void PauseTest(){   datetime now = TimeCurrent();   static datetime onePerTick;
    if (IsTesting() && IsVisualMode() && IsDllsAllowed() && onePerTick != now){
        for(int i=0; i<100000; i++){        // Delay required for speed=32 (max)
            int main = GetForegroundWindow();               onePerTick = now;
            if (i==0) PostMessageA(main, WM_COMMAND, 0x57a, 0); // 1402. Pause
    }   }
}//*/
JC
1499
JC  
WHRoeder:
F12 [...]
...see https://www.mql5.com/en/forum/128554
12
To add comments, please log in or register