Forcing a tick in a quiet market (or even on the weekend) possible?

 

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?

Thanks! 

 

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.

 
The indicators have already updated from the last tick. There is no new data, so there is no need for an update.
 

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
   return(rates_total);
  }
 

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);
#import

int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }


void OnDeinit(const int reason)
  {
   EventKillTimer();
  }

void OnTimer()
  {
   UpdateChartWindow();
  }

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[]) 
  {
   return(rates_total);
  }

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); }
   return;
  }
 
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.
Reason: