MQL4 Real Time Clock (second by second) - page 4

 

Good, but this is not real-time solution, because we can't control the time of response for non-tick events.
In case of "sleep()" we can.

 

So if we combine tick by tick and stale prices with sleep then we can have a real time clock :)

 

As i said, if this solution is implemented in an EA there is no need anymore for TimeCurrent() and the Loop is controlled by Sleep(Interval-Runtime) (in ms)

Most of the code stays the same, redraw() will not be needed anymore. Also if you need to increase speed of the code you can use some (ah im missing the english word) arrays with rotation zero point to get rid of the shift loop.

AFAIK this (or similar) is best solution which can be done in pure MQL in a indicator. There surely exist better solution when you use a DLL an export the calculations in an external program

 
spidermagos:

So if we combine tick by tick and stale prices with sleep then we can have a real time clock :)

Yes, but Sleep is not possible in Indicators, thats your problem since the beginning of this thread
 
zzuegg:
Yes, but Sleep is not possible in Indicators, thats your problem since the beginning of this thread

Can an EA call an indicator ?
 
Yes, but only trough icustom which won't solve your problem
 
You can attach a script to the chart that sends a fake tick every second to the chart. This is what I usually do to update multi-pair indicators and EAs in regular intervals.
 
7bit:
You can attach a script to the chart that sends a fake tick every second to the chart. This is what I usually do to update multi-pair indicators and EAs in regular intervals.
You need a dll for that or is this possible without?
 
zzuegg:
You need a dll for that or is this possible without?

Its just a handful of lines in mql4 (of course you need DLL calls allowed to call the windows API, but you don't need to install anything):

/**
* MT4/experts/scripts/ticks.mq4
* send a fake tick every 1000ms to the chart and
* all its indicators and EA until this script is removed.
*/

#property copyright "© Bernd Kreuss"

#import "user32.dll"
   int PostMessageA(int hWnd, int Msg, int wParam, int lParam);
   int RegisterWindowMessageA(string lpString);
#import

int start(){
   int hwnd = WindowHandle(Symbol(), Period());
   int msg = RegisterWindowMessageA("MetaTrader4_Internal_Message");
   while(!IsStopped()){
      PostMessageA(hwnd, msg, 2, 1);
      Sleep(1000);
   }
}

I have this script in my favorites and when I need ticks I just drag it to the chart.


I also have a variation of this without the loop that only sends one tick and then exits and have bound this (one_tick.mq4) to hotkey ALT+T and now I can send a tick to the active chart by just pressing ALT-T. I need this for some of my stat-arb EAs when experimenting during the weekend to enforce start() to trigger their calculations and plotting of their graphs (I can move lines on the chart to change the interval and then I need a new tick to update their calculations).

 

nice one. thanks for sharing

Reason: