A simple question regarding SMMA

 

I need to implement the original code for:

PriceBasic = iMA(NULL,PERIOD_M30, BasePeriod,0,MODE_SMMA, PRICE_CLOSE, 1);

I code as following:

sumN1 = 0.0;

for(ij = BasePeriod; ij >= 1; ij--)
sumN1 = sumN1 + Close[ij];

SMMA1 = sumN1/BasePeriod;
TDIBasic1 = (sumN1 - SMMA1 + Close[1])/BasePeriod;

But I get the wrong result and I get blocked, is there something wrong?

 

Please edit your post . . . .

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 
sunnybeach:

I need to implement the original code for:

PriceBasic = iMA(NULL,PERIOD_M30, BasePeriod,0,MODE_SMMA, PRICE_CLOSE, 1);

Isn't this all you need ?

sumN1 = 0.0;

for(ij = BasePeriod; ij >= 1; ij--) 
sumN1 = sumN1 + Close[ij];

SMMA1 = sumN1/BasePeriod;           // <--- this is the MA
 
RaptorUK:

Isn't this all you need ?

SMMA1 = sumN1/BasePeriod

  1. Sorry RaptorUK That is SMA not SMMA
  2. Note that SMMA( L ) = EMA( 2L-1 ) See here
  3. sunnyBeach, if you want to implement SMMA, see the above link, or implement the easier EMA. The question is why. You have iMA() and iMAOnArray() both do what you want, why reinvent the wheel?
 
WHRoeder:
  1. Sorry RaptorUK That is SMA not SMMA

1. Ah . . . it's mostly Greek to me :-)
Reason: