Creating fake ticks for MT5

 
#include <WinUser32.mqh>
#import "user32.dll"
int RegisterWindowMessageW(string lpString);
#import 
//+------------------------------------------------------------------+ 
//| script program start function | 
//+------------------------------------------------------------------+ 
int start() 
{ 
//---- 
int MT4InternalMsg = RegisterWindowMessageW("MetaTrader4_Internal_Message"); 
int hWnd = WindowHandle(Symbol(),Period()); 
PostMessageW(hWnd,MT4InternalMsg,2,1);
//---- 
return(0); 
} //+------------------------------------------------------------------+

Hello everyone, the code above creates a fake tick for MT4, am trying to do same for MT5 but it's not working. Can anyone confirm if this functionality is still possible in MT5, if yes how to do it.

Here's my attempt at converting the above code to MT5, it compiles fine, but the terminal does not react as it should.


#include <\\WinAPI\\winuser.mqh>
#import "user32.dll"
//int RegisterWindowMessageW(const string str);
#import 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   uint MT4InternalMsg = RegisterWindowMessageW("MetaTrader5_Internal_Message"); 
   long hWnd = ChartGetInteger(0,CHART_WINDOW_HANDLE);
   PostMessageW(hWnd,MT4InternalMsg,2,1);
  }
//+------------------------------------------------------------------+

Am I missing anything?

 

Of course it doesn't work, there is no such thing as "MetaTrader5_Internal_Message".

Why do you want a tick ?

 
Alain Verleyen:

Of course it doesn't work, there is no such thing as "MetaTrader5_Internal_Message".

Why do you want a tick ?

I'm trying to measure time it takes an EA to process all functions within the OnTick event. Unfortunately, markets are closed. If I could generate a fake tick, I can continue without waiting for market to open
 
holocast:
I'm trying to measure time it takes an EA to process all functions within the OnTick event. Unfortunately, markets are closed. If I could generate a fake tick, I can continue without waiting for market to open
Use a timer.
 
Alain Verleyen:
Use a timer.

Good idea. Thanks

 

I don't understand "Use a timer",  Isn't the EA dormant until it receives a real tick? Is there code to create fake ticks in MT5???  Say every 100 ms. I want a condition checked as close as possible after the last bar is closed without having to wait for the firs tick of the next bar

 
carthage1 #: I don't understand "Use a timer",  Isn't the EA dormant until it receives a real tick? Is there code to create fake ticks in MT5???  Say every 100 ms. I want a condition checked as close as possible after the last bar is closed without having to wait for the firs tick of the next bar

Use the OnTimer() event handler in conjunction with the OnTick() event handler.

Forum on trading, automated trading systems and testing trading strategies

Can a buffer update in the middle of two commands?

Fernando Carreiro, 2022.04.27 02:27

I suggest the following. Don't use sleep! Since it is multi-symbol, instead use the OnTimer() event handler in combination with OnTick() for the most active symbol (e.g. EURUSD), in order to detect time synchronisation of bar openings.

Also, there is no need to wait for a symbol's bar to close. If the bar's close time is up, then it is almost certain that it will close at the most recently received data later on, even if no new opening tick has arrived for that symbol. A way to handle this is to check if the current bar's ( open time + bar duration ) has lapsed. Based on this you will know if the current bar is pending closure or if it is a freshly created new bar.

When a new bar is supposed to have happened, you will check whether a new bar has actually been formed (and thus use the previous bar for the decision) or if the current bar is still pending a new opening tick (then you will use the current bar data as if it were already closed and in the previous bars data).

I hope my convoluted explanation made sense to you.

Forum on trading, automated trading systems and testing trading strategies

Can a buffer update in the middle of two commands?

Fernando Carreiro, 2022.04.27 21:45

The timing or frequency at which the OnTimer() event is called is up to you to decide and set wit the EventSetTimer function. Timing with OnTimer is not necessarily synchronised with the start of a minute and the can be delays or overlaps, as all triggered events are queued. So, you have to choose your frequency with that in mind.

There is also no need to separate the functionality between OnTick() and OnTimer(). Both can be made to call a common function when the events occur, and maybe use a flag parameter to distinguish the source. That function would carry out the functionality common to both and use the flag to carry out different functionality befitting the type of event.

When coding services, the only event it can handle is in fact the OnTimer event, so you can use a similar approach as well, of how to handle historical data, indicators and trading in Services.

Reason: