Download MetaTrader 5
To add comments, please log in or register
Do you wonder how to use widgets? Read the article!
mar 2016.01.29 14:16 

Hi forum,

when I do some analysis on the weekend and I need a tick for an indicator to update some objects or whatever, I just open the indicator list and close it. Obviously that causes the OnCalculate() to run once. Then the indicators which need a tick to update are being refreshed.

Is it somehow possible to force a tick (=> execute the OnCalculate()) by programming?


Trololo Tromberino
Trololo Tromberino 2016.01.29 14:19  

I don´t think this is working on weekend....depending which broker you are using. Normally my broker tells me that i have to create a pending order.

Ticks are created by getting buy and sell orders in the real market. When you are trading OTC-things like CFD´s or so, this is not possible.

whroeder1 2016.01.29 14:24  
The indicators have already updated from the last tick. There is no new data, so there is no need for an update.
mar 2016.01.29 15:19  

An example:

I draw a horizontal line on the chart and name it "TEST". If I do that in a market with incoming ticks that example will work fine. But if I draw it on the weekend, nothing happens.

I know the solution would be to use the CHARTEVENT_OBJECT_CREATE here but my question is if it possible to execute the OnCalculate somehow with no incoming ticks?

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
   if (ObjectFind(0, "TEST")==0) {
      Alert(DoubleToString(ObjectGetDouble(0, "TEST", OBJPROP_PRICE1), Digits));
//--- return value of prev_calculated for next call
honest_knave 2016.01.29 15:35  

There are a few ways.

You can play with timers to call functions (albeit you'll struggle to call OnCalculate directly).

Or you can push a tick (using a button or again using the timer):

#property strict
#property indicator_chart_window
#include <WinUser32.mqh>

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

int OnInit()

void OnDeinit(const int reason)

void OnTimer()

int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],
                const double &open[],const double &high[],const double &low[],
                const double &close[],const long &tick_volume[],const long &volume[],const int &spread[]) 

int msg = 0;
void UpdateChartWindow()
   static int hwnd = 0;
   if(hwnd==0)           { hwnd = WindowHandle(Symbol(),ChartPeriod()); }
   if(msg ==0)           { msg  = RegisterWindowMessageW("MetaTrader4_Internal_Message"); }
   if(hwnd!=0 )          { if(PostMessageW(hwnd,WM_COMMAND,0x822c,0)==0){ hwnd = 0; } }
   if(hwnd!=0 && msg!=0) { PostMessageW(hwnd,msg,2,1); }
mar 2016.01.30 13:09  
Awesome, thank you, honest_knave! I never used timer function because I never knew how and why to use them. But now I'll have a closer look.
To add comments, please log in or register