A custom indicator as a resource

 

A custom indicator included as a resource slow down 60 times tester against using the same indicator with the same inputs (not as a resource).

Is it a bug? Or am I doing something wrong?

Here is a simple EA so you can try it:

#define INDI_AS_RESOURCE   // If you want to run the EA without a resource use // in front of this line and compile

#ifdef INDI_AS_RESOURCE
   #resource "\\Indicators\\RSI.ex4"
#endif

uint countStart=GetTickCount();


int OnInit()
  {
   countStart=GetTickCount();
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   #ifdef INDI_AS_RESOURCE
      printf("It took %I64dms with resources",GetTickCount()-countStart);
   #else
      printf("It took %I64dms without resources",GetTickCount()-countStart);
   #endif
  }

void OnTick()
  {
   double
      #ifdef INDI_AS_RESOURCE
         rsi=iCustom(_Symbol,_Period,"::Indicators\\RSI.ex4",0,0);
      #else
         rsi=iCustom(_Symbol,_Period,"RSI.ex4",0,0);
      #endif
  }
 
I confirm the big difference (40 times on my side).
 

For resources to work, the terminal has to read it out of the ex4 and create the resource, then process it as usual.

Try timing a few thousand ticks. Likely you will see a one time hit and then little difference.

 
Alain Verleyen:
I confirm the big difference (40 times on my side).

Thank you for confirmation. It's a bug in my opinion. But I don't know where I can report it.

 
William Roeder:

Try timing a few thousand ticks. Likely you will see a one time hit and then little difference.

It isn't this case in my opinion. I updated the EA. Now the EA count every tick.

#define INDI_AS_RESOURCE   // If you want to run the EA without resource use // in front of this line and compile

#ifdef INDI_AS_RESOURCE
   #resource "\\Indicators\\RSI.ex4"
#endif

uint
   countStart=GetTickCount();
ulong
   countStartOnTick,
   countTick=0,
   timeWith=0,
   timeWithout=0;
double
   rsi;

int OnInit()
  {
   countStart=GetTickCount();
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   #ifdef INDI_AS_RESOURCE
      printf("It took %I64dms with resources. %d ticks ; Average time for one tick %.2fμs",GetTickCount()-countStart,countTick,countTick>0?timeWith/countTick:double("nan"));
   #else
      printf("It took %I64dms without resources. %d ticks ; Average time for one tick %.2fμs",GetTickCount()-countStart,countTick,countTick>0?timeWithout/countTick:double("nan"));
   #endif
  }

void OnTick()
  {
   countTick++;
   #ifdef INDI_AS_RESOURCE
      countStartOnTick=GetMicrosecondCount();
      rsi=iCustom(_Symbol,_Period,"::Indicators\\RSI.ex4",0,0);
      timeWith+=GetMicrosecondCount()-countStartOnTick;
   #else
      countStartOnTick=GetMicrosecondCount();
      rsi=iCustom(_Symbol,_Period,"RSI.ex4",0,0);
      timeWithout+=GetMicrosecondCount()-countStartOnTick;
   #endif
  }


And here is the results:

Indicator as a resource:

It took 233078ms with resources. 6546038 ticks ; Average time for one tick 35.00µs


Without a resource:

It took 4531ms without resources. 6546038 ticks ; Average time for one tick 0.00µs

 
Petr Nosek:

Thank you for confirmation. It's a bug in my opinion. But I don't know where I can report it.

Done.
 
Alain Verleyen:
Done.

Thank you Alain. You're my angel ;-)

 
Petr Nosek:

Thank you Alain. You're my angel ;-)

Well, I can't guarantee they will do something. Only an angel, not god :-D
 

Same thing happens here...

Does anyone has some news about it?

Is the only way to solve the problem to embeed resource indicator code inside "main" code?

 
Fabio Cavalloni:

Same thing happens here...

Does anyone has some news about it?

Is the only way to solve the problem to embeed resource indicator code inside "main" code?

There will be no news. MT4 is not in development any more, only security issues will be fixed.

I am wondering if this also occurs with MT5, did you try ?

 
Alain Verleyen:

There will be no news. MT4 is not in development any more, only security issues will be fixed.

I am wondering if this also occurs with MT5, did you try ?

Didn't try... but from my (little) experience it can be same or worse :-D

Reason: