Getting Strategy Tester (and terminal) frozen with WindowHandle() function

 
How to get Strategy Tester frozen with WindowHandle() function:
  1. using joined TEST_ST_WindowHandle.mq4 indicator with a dummy EA for the backtest
  2. start backtest in visual mode for a dummy EA with, for instance, symbol EURUSD,M1
  3. open offline another timeframe as EURUSD,M15
  4. drop TEST_ST_WindowHandle on the visual window "EURUSD,M1 (visual)" with as parameters the offline chart symbol and timeframe
  5. => the MT4 terminal freezes after a few successfull WindowHandle() retrieving the window handle of "EURUSD,M15 (offline)" window
Looks like a bug imo.
Files:
 
It works fine . . . . as long as you run the Strategy Tester very, very slowly . . . or pause it and run it a tick at a time using F12.
 
RaptorUK:
It works fine . . . . as long as you run the Strategy Tester very, very slowly . . . or pause it and run it a tick at a time using F12.


Sorry: "Even if you run the Strategy Tester very, very slowly" should be read !!!

The Strategy Tester has a slider to select the tick pace from index 1 to 32.

At pace index 5, one tick per ~4 seconds, you get the terminal frozen after ~40 ticks.

At pace index 1, one tick per ~17 seconds, you get the terminal frozen after ~136 ticks.

Doesn't work fine at all ...

 
berix:

Doesn't work fine at all ...

It's very easy to lock up MT4 by doing things that make no sense in the Strategy Tester . . . if you want to do that be my guest.

I'm sure there are plenty of other things you can try . . . I prefer to do things that solve problems.

If on the other hand you want help trying to achieve what you are actually looking to achieve then by all means explain what you are trying to achieve.

 

If you want to update an offline chart based on data created by an EA running in the Strategy Tester then don't do it from the EA.

I created an additional dummy offline timeframe (M7) with just one set of bar data in it . . . it wasn't continually updated. On this offline chart I added a script that had an infinite loop running at intervals of x ms (implemented using Sleep(x) ) the job that this script had was to refresh the offline charts that I wanted it to refresh . . . . this meant that on the offline charts I was interested in I could run other scripts.

 

RaptorUK:

I prefer to do things that solve problems.


Things that would solve that problem are:

  1. Recognize the issue
  2. Submit a bug report
  3. Wait for a planned fix

Can you explain me how is currently organized the improvement chain of the MT4 client ?
What if a user find one bug out ?
How is it relayed to the developer team ?
Can you ?

Anyway, believe me, I'm not playing around with MT4 just for the seek of unwanted behavior or side effects. I do best of my time other ways. However as many others, and you hopefully, I manage to achieve useful pieces of code facing a lot of problems due to the design of MT4. Nothing new in that.

So why anyone would call many time the WindowHandle() function with the strategy tester ? For the same reasons they call the WindowHandle() function in live mode. There are plenty of example throughout this web site.

In my case I use the Dummy EA technique, as described above, to test indicators that act as decision helpers, not over classical timeframes, but merely over derived Offline chart like renko, constant range bars and alike. As you know the process to transpose regular M1 flow into so called "Real Time Offline Charts" makes use of a signaling technique to refresh that derived Offline Chart. And to signal a refresh to the proper offline chart you need to invoke "int WindowHandle( string symbol, int timeframe)".

The derived Offline chart can either be open or not whenever the indicator starts, and can be closed at any time. So the involved logic in live mode is:

void refreshOfflineChart(string symbol, int timeframe)
{
    int winHandle = WindowHandle(symbol,timeframe);                     // Is there (still) a chart open ?
    if(winHandle > 0) PostMessageA(winHandle, WM_COMMAND, 33324, 0);    // Signal refresh whenever a chart is open
}

Works fine in live mode, and freezes with the Strategy Tester as demonstrated.

It took me a while to figure out WindowHandle() is the issue. But why does it get stuck simply reading a window's handle ?

Bug to me.

 
RaptorUK:

If you want to update an offline chart based on data created by an EA running in the Strategy Tester then don't do it from the EA.


Please, explain technically why ...
 
berix:

It took me a while to figure out WindowHandle() is the issue. But why does it get stuck simply reading a window's handle ?

Bug for me.

Perhaps it is part of the same limitation that makes this a limitation . . .

"Some functions are processed/passed without output

These are Sleep(), Alert(), SendMail(), PlaySound(), MessageBox(), WindowFind(), WindowHandle(), WindowIsVisible()"

From here: https://www.mql5.com/en/articles/1512

As I described above . . . there is a simple effective work around . . . or you can wait for MetaQuotes to fix it . . .

 
berix:

Please, explain technically why ...

Because, as you have found out, it doesn't work . . . unless you call WindowHandle() infrequently . . . and within the ST you can't control that frequency.

I'm far from an expert in offline charts . . . I only started working with them just over a week ago . . . I started by trying to get this (Link) working in the ST and came across the same issue you have found . . . so then I decided I had to solve my problem by understanding and that the short cut option was no longer an option. I read through the period_converter code, got an understanding of what was going on and I wrote my code.

I wrote an EA to run in the ST to facilitate trading methodology testing using Fibs, my EA now allows the user to view lower timeframes simultaneously . . . so with the ST set to H1 the user can also see M30, M15, M5 and M1 updating synchronously with the H1 in the ST. My script running on a minimised M7 offline chart updates the M30, M15, M5 and M1 offline charts.

 
berix:
"Even if you run the Strategy Tester very, very slowly" should be read !!!
I use this in the tester at full speed, never have had a problem. Note the IsStopped and ref https://www.mql5.com/en/forum/126618
#include <WinUser32.mqh>
#import "user32.dll"
  int GetAncestor(int, int);
#import
void PauseTest(){   datetime now = TimeCurrent();   static datetime oncePerTick;
    if (IsTesting()) if( IsVisualMode()) if( IsDllsAllowed()) if(
                oncePerTick != now){    oncePerTick = now;
        for(int i=0; i<200000; i++){        // Delay required for speed=32 (max)
            if (IsStopped()) break;         // https://forum.mql4.com/32837 WH-DL
            int main = GetAncestor(WindowHandle(Symbol(), Period()), 2);//GA_ROOT
            if (i==0) PostMessageA(main, WM_COMMAND, 0x57a, 0); // 1402. Pause
    }   }
}
 
WHRoeder:
I use this in the tester at full speed, never have had a problem. Note the IsStopped and ref https://www.mql5.com/en/forum/126618

:-) looks like I might be able to get rid of my M7 chart and looping script . . .
Reason: