SIDEBAR

TradeStation code for phase calculation


by John F. Ehlers

The following code is written in EasyLanguage for use with TradeStation.

The code is reproduced below to allow our Web site browsers to easily copy and paste this information to other applications.

For the complete text of this article and sidebar, please refer to the November 1996 issue of Technical Analysis of STOCKS & COMMODITIES magazine.





inputs: DomCycle(15);
vars: RealPart(0), ImagPart(0), Weight(0), Phase(0), J(0);

for J = 0 to DomCycle -1 Begin
weight = close[J];
If DomCycle <>0 then Begin
RealPart = RealPart + Cosine(360 * J / DomCycle) * Weight;
ImagPart = ImagPart + Sine(360 * J / DomCycle) * Weight;
end;
end;

If AbsValue(RealPart) > .001 Then Begin
Phase = ArcTangent(ImagPart/RealPart);
end
else Begin
Phase = 90 * Sign(ImagPart);
end;

If RealPart < 0 then Phase = Phase +180;
Phase = Phase + 90;
If Phase < 0 then Phase = Phase + 360;
If Phase > 360 then Phase = Phase - 360;

plot1(Phase, "Phase");
Excerpted from an article originally published in the November 1996 issue of Technical Analysis of STOCKS & COMMODITIES magazine. 
© Copyright 1996, Technical Analysis, Inc. All rights reserved.

Back to Ehlers Abstract or return to November Contents