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

Re: Exponential moving average



PureBytes Links

Trading Reference Links

I have always been very impressed with Mark Jurik's stuff since I
started using several of his tools in 1994.
I have played with MAs (as everyone has) and realized one of the best
uses of Jurik's AMA was as a preprocessing step to get rid of noise from
data before I use it in an indicator.
Ever since reading some books by Ehlers, Bressert, Chande, and Kaufman,
I have viewed using MAs as "dynamic trendlines".  It seemed that was
about all they were good for.
A couple of years ago I started coding Cynthia Kase's indicators and
found she uses alot of statistical info like standard deviation and I
started using Linear Reg and StdDev.
One of the things I have used alot is a LinearRegValue plotted from a
recent Pivot High or Pivot Low instead of a "set" look back length. 
(see code below)
I recently read in a magazine I get (as a Mech. Engineer) about second
and third order regression.  (note: I'm no mathmatician!!)

where normally the equation for a line is y = ax+b  (where a is slope, b
the intercept)
for 2nd and 3rd order reg. then y = Cx^3 + Bx^2 + Ax + b  (where C, B,
and/or A could = 0)

When using my "BP-LRVdyn" I notice that if I have a long trend develop,
the math gets very intensive because of the number of bars from the last
pivot.  And, although, I like the statistically correct behavior of the
plot (it's cycle independant), it gets too far away from the price
during these long trends.  I was wondering if anyone has coded these
second and third order regression lines, either as an ELA or DLL?  It
would be way beyond my ability to try. What I am looking for is what Bob
Fulks (great post, by the way!) calls a "polynomial moving average" like
in an Excel chart.  Is this too compicated for TS?  Is there a better
way?

Thanks!
Bob Perry
San Jose, CA


{	BP-LRVdyn : Bob Perry 10/99, 03/00, 09/00   
	Dynamically Draws LRV-Plot w/StdDevHL
	
	Plot1 = green, same as symbol, point, weight#3
	Plot2 = magenta, same as symbol, point, weight#3}
	
Inputs:		BOprice (TypicalPrice),		{ Price that Breaks Out }
		StDev(1.618) ;			{ Std Devs from LRV TL}
		
Vars:	Length (1), BarNum(0), counter(0), 
		Htotal(0), Ltotal(0), StDevH(0), StDevL(0),
		LRVH(c), LRVL(c), Trend(0), 
		PlotNum(0), PlotLen(1), BarsBak(5) ;

If Trend = 0 then begin
	Plot1(Highest(H, BarsBak)[1], "buystop");
	Plot2(Lowest(L, BarsBak)[1], "sellstop");
End;

Value3 = Upticks + DownTicks ;

{  Set Length  }
If BarNumber - BarNum > 1 then Length = Barnumber - BarNum else Length =
1;

{  Calc LRV High  }
If Trend = -1 then begin
	If Value3 >= Value3[1] then begin
		Htotal = 0;
		For counter = Length-1 downto 0 begin
			Htotal = Htotal + Square(H[counter]-LinearRegValue(High, Length+1,
counter)) ;	
		End;
		StDevH = SquareRoot(Htotal/Length);
	End;
	LRVH = LinearRegValue(High, Length+1, 0) + (StDev*StDevH);
	If Length <= BarsBak then Value1 = LRVH else Value1 =
MinList(LRVH,Plot1[1]);
	Plot1(Value1, "buystop");
	NoPlot(2);
End;

{  Calc LRV Low  }
If Trend = +1 then begin
	If Value3 >= Value3[1] then begin
		Ltotal = 0;
		For counter = Length-1 downto 0 begin
			Ltotal = Ltotal + Square(L[counter]-LinearRegValue(Low , Length+1,
counter)) ;
		End;
		StDevL = SquareRoot(Ltotal/Length);
	End;
	LRVL = LinearRegValue(Low , Length+1, 0) - (StDev*StDevL);
	If Length <= BarsBak then Value2 = LRVL else Value2 =
MaxList(LRVL,Plot2[1]);
	Plot2(Value2, "sellstop");
	NoPlot(1);
End;

{------------------------------------------------}
If BOprice crosses below Plot2 then begin
	Trend = -1;
	BarNum = BarNumber[HighestBar(High, Length)];
	BarsBak = BarNumber - BarNum + 1;
	If AlertEnabled then Alert("BO below TL");
End;
{------------------------------------------------}

{------------------------------------------------}
If BOprice crosses above Plot1 then begin
	Trend = +1;
	BarNum = BarNumber[LowestBar(Low, Length)];
	BarsBak = BarNumber - BarNum + 1;
	If AlertEnabled then Alert("BO above TL");
End;
{------------------------------------------------}