Create LWMA of an indicator

 

All,

Can anyone advise a better (read: quicker) way for code to be processed when creating a LWMA of an indicator?

i.e. I create a LWMA of an indicator called SDO, but I need to use a 75 period LWMA. So I end up creating 75 lines of iCustom code 9one for each 75 period) and doing the LWMA calculation. Unfortunately this drastically slows down testing in the strategy tester.

Is there a better way?

Thanks,

Paul

Files:
SDO_LWMA.JPG  117 kb
 

porko: So I end up creating 75 lines of iCustom code 9one for each 75 period) and doing the LWMA calculation. Is there a better way?

Unfortunately this drastically slows down testing in the strategy tester.

  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please don't post a link to or attach an image, just insert the image.
              Messages Editor

  3. "Is there a better way?" Of course there is, write a loop.
    Not compiled, not tested.
    const int   length=75,  iBeg=1;
    double      Evw=0,      Ew=0;
    int iBar=iBeg+length, weight=0; while(iBar > iBeg){
       --iBar; ++weight;
       double   v = iCustom(MyMarket, PERIOD_CURRENT, "Simple Decycler Oscillator",
                            SDOHighPassPeriod, SDOPrice, SDOKParam,
                            0, iBar);
       Evw += v * weight;   Ew += weight;
    }
    double LWma = Evw / Ew;
    
    Not compiled, not tested.
  4. Loop or in-line code, will execute the same. No problem with the tester. That problem is elsewhere.
 
porko:

All,

Can anyone advise a better (read: quicker) way for code to be processed when creating a LWMA of an indicator?

i.e. I create a LWMA of an indicator called SDO, but I need to use a 75 period LWMA. So I end up creating 75 lines of iCustom code 9one for each 75 period) and doing the LWMA calculation. Unfortunately this drastically slows down testing in the strategy tester.

Is there a better way?

Thanks,

Paul

try below code.
not tested.

int limit = 75;
double sdo = 0,
       x = 0,
       y = 0,
       sdolwma = 0;
for (int i = 1; i<=limit; i++) {
   sdo = iCustom(MyMarket,PERIOD_CURRENT,"Simple Decycle Oscillator",SDOHighPassPeriod,SDOPrice,SDOKParam,0,i);
   x += sdo*(limit-i+1);
   y += i;
}

if(y>0) sdolwma = x/y;
 
Show your code. So it will be easier to help.
Reason: