iCustom and OnTimer

 

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.

 

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.

 
That would seem to be the case - thanks for confirming my suspicions
 
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.