Something really weird

 

Hi guys, here is my indicator:

#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---

   Print("WTF?!?!");

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

The indicator is already attached to a chart when I start the MT4.

This is the result (at least 100-150 lines) on Experts tab:

wtf

What is it?! What is the trigger for countless OnCalculate?

 

It looks ok.

You should read about OnCalculate in the manual.

 
eddie:

It looks ok.

You should read about OnCalculate in the manual.


I couldn't find anything about it. Help me a bit.
 

OnCalculate is called on every tick.

And dont't read only the first sentence in the manual. There is also information in the second.

 
eddie:

OnCalculate is called on every tick.

And dont't read only the first sentence in the manual. There is also information in the second.

My friend, you probably missed something.

What every tick?! On Saturday, when market is closed?!

 
ggekko: What every tick?! On Saturday, when market is closed?!
Have you forgotten that it also has to process all the previous bar data in the history and not just the incoming ticks?

Please read the documentation completely and I quote:
... If since the last call of OnCalculate() price data has changed (a deeper history downloaded or history blanks filled), the value of the input parameter prev_calculated will be set to zero by the terminal. ...
EDIT2: NB! In other words, while history data is being downloaded or verified, the OnCalculate() event handler can be called several times, every time it recycles the history data!
 
FMIC:
Have you forgotten that it also has to process all the previous bar data in the history and not just the incoming ticks?

Please read the documentation completely and I quote:
... If since the last call of OnCalculate() price data has changed (a deeper history downloaded or history blanks filled), the value of the input parameter prev_calculated will be set to zero by the terminal. ...


Maybe my English is weak enough, but I don't understand it.

There are approx. 150 lines of "WTF". Although, there are approx. 5000 bars in the history.

 
ggekko:

(I deleted my "fckn" post ...)

Maybe my English is weak enough, but I don't understand it.

There are approx. 150 lines of "WTF". Although, there are approx. 5000 bars in the history.

When you start MT4, it is still connecting to the broker and after that it still needs to download the history data in chunks and during this process it will reset/recycle the call to the OnCaclulate() event handler.

This is related to the 4066 and 4073 errors when using Multi-Currency or Multi-Time-frames and all these situations suffer similar scenarios in the system - hence why it can easily be called 150 times during this initial period.

Only when it stabalises does it then resort to only updating on new ticks!

 

OK FMIC, thank you, now it's clear.

Although, imho this is not so good thus. It is pretty meaningless to call OnCalculate needlessly before history download is finished completely.

 
ggekko:

OK FMIC, thank you, now it's clear.

Although, imho this is not so good thus. It is pretty meaningless to call OnCalculate needlessly before history download is finished completely.

Correct! That is why on another post here, I insisted with the OP that they should verify the connection status before doing anything else. You should do the same.

PS! You can also verify the value of "rates_total" between calls and only proceed when it has stabalised. However, once stabalised you should not filter out any further events where the parameter changes.

 
ggekko:

Hi guys, here is my indicator:

The indicator is already attached to a chart when I start the MT4.

This is the result (at least 100-150 lines) on Experts tab:


What is it?! What is the trigger for countless OnCalculate?

I guess you have an EA calling your indicator that is using the function OnTimer()?
Reason: