Download MetaTrader 5
To add comments, please log in or register
Have you found a good programmer? Make a targeted order!
honest_knave
955
honest_knave 2014.07.14 10:48 

I'm not sure if this is already documented, but I thought I'd share my findings from experimenting with iCustom and OnTimer.

Basically, it doesn't work.

Consider the following simple code:

double TestBuffer[];
double TestValue = 1;

int OnInit() {
   IndicatorBuffers(1);
   SetIndexBuffer(0,TestBuffer);
   EventSetTimer(5);
   return(INIT_SUCCEEDED);}

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

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[]) {

   TestBuffer[0]=TestValue;
   return(rates_total);}

void OnTimer() {
   TestValue++;}

 

If you now call this with a simple iCustom:

 Print(iCustom(NULL,0,"TestIndicator",0,0));

 

It will return 1 every time i.e. the OnTimer event of TestIndicator is not firing.

 

If you add the TestValue++ into the OnCalculate event, the returned iCustom value steadily increases.

Halley
198
Halley 2014.07.14 11:16  

Thanks for sharing.

My understanding is that Indicator initiated via iCustom does not listen to any event. It just runs OnInit once and OnCalculate every time before the buffer access.

honest_knave
955
honest_knave 2014.07.14 11:37  
That would seem to be the case - thanks for confirming my suspicions
Ian Venner
2583
Ian Venner 2014.07.14 18:56  
if you put a print() in OnTimer it is not executed when the indicator is called via iCustom so the OnTimer event does not work when you use iCustom.
/
To add comments, please log in or register