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.
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; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!