[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Gapless Moving Average



PureBytes Links

Trading Reference Links

Hello omega,

  The code that follows (2 functions and 1 indicator) comes from a
newsletter I get. The author doesn't seem interested in correcting it.
But I believe it is close to achieving its objective--plotting a
moving average that is adjusted or normalized for gap opens.  The
approach is used for intraday charts.

This code plots but it is not correct.  Can anyone see the problem?

Thanks for any help.

{ ==================================================================}

FUNCTION: NORMAL.  Use with function: MANormal. Adjusts moving average
so it catches up with price quicker at gap opens than the traditional
moving average.}

Inputs: Price(numericseries);

Vars: GetGap(0);

If D <> D[1] then GetGap = GetGap + Price - Price[1];

Normal = Price - GetGap;

{====================================================================}

{====================================================================}
{FUNCTION: MANormal.  Computes  moving average adkusted for gap
openings.}

Inputs: Price(numericseries), NBars(numericsimple);

Vars: Countr(0), xSum(0);

Value1 = Value1 + 1;

Array: NormalVal [100](0);

For Countr = NBars downto 1 begin

         NormalVal[Countr] = NormalVal[countr - 1];

 end;

NormalVal[0] = Normal(Price);

xSum = 0;

For Countr = 0 to NBars - 1 begin

xSum = xSum + NormalVal[Countr];

end;

If value1 >= NBars then MANormal = xSum / NBars;

{====================================================================}

{====================================================================}

{INDICATOR:  MANormal.  Plots a normalized moving average that adjusts
for opening gaps so the MA will catch up with price more quickly.}

Inputs: Price(Close), MALen(18);

Plot1(MANormal( Price, MALen), "NormMA");

{=========================================================================}

-- 
Best regards,
 Jim Johnson                        mailto:jejohn@xxxxxxxxx