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

Part 1- Help with EasyLanguage -- Ehlers Instantaneous Trend



PureBytes Links

Trading Reference Links

Could someone on the list kindly help find out why an indicator and signal
don't agree.  I'm sending this in two part, with the chart in part2.

Facts:

1-  the max bars settings on indicator and signal are both 50 bars.
2-  I used code published in Technical Analysis of Stocks and Commodities
with one modification.  .  I inserted Data2 in the Input for Price.
3- The attached chart shows 4 trades.  However, the last 3 should not have
occurred based on the conditions of the signal, since the two lines in data2
did not cross at those points.

One possible explanation is that following line of Ehlers code references
Value11[1] in the code for Value11 itself.  Maybe this is circular
reasoning.

Value11 = .33*(Price + .5*(Price - Price[3])) + .67*Value11[1];


To avoid overwriting anyone's existing files with the same names, I have
shown the signal and indicator in text form below.


Any help would be very much appreciated.

Barry



{CODE FOR SIGNAL
****************************************************************************
*****
 Instantaneous Trend Line By John Ehlers - May 2000 article in Technical
Analysis of Stocks and Commodities

Ehlers uses a two-mode market model: trending or cycling. By removing the
dominant cycle from the price data, the
remaining information is mostly about trend. Here is the EasyLanguage Code
to plot Instantaneous Trend Line}

{WEEKLY - DATA2}

Inputs: Price((H data2 + L data2)/2 );

 Vars: InPhase(0),
  Quadrature(0),
  Phase(0),
  DeltaPhase(0),
  count(0),
  InstPeriod(0),
  Period(0),
  Trendline(0);

If CurrentBar > 5 then begin

 {Compute InPhase and Quadrature components}
 Value1 = Price - Price[6];
 Value2 =Value1[3];
 Value3 =.75*(Value1 - Value1[6]) + .25*(Value1[2] - Value1[4]);
 InPhase = .33*Value2 + .67*InPhase[1];
 Quadrature = .2*Value3 + .8*Quadrature[1];

 {Use ArcTangent to compute the current phase}
 If AbsValue(InPhase +InPhase[1]) > 0 then Phase =
ArcTangent(AbsValue((Quadrature+Quadrature[1]) / (InPhase+InPhase[1])));

 {Resolve the ArcTangent ambiguity}
 If InPhase < 0 and Quadrature > 0 then Phase = 180 - Phase;
 If InPhase < 0 and Quadrature < 0 then Phase = 180 + Phase;
 If InPhase > 0 and Quadrature < 0 then Phase = 360 - Phase;

 {Compute a differential phase, resolve phase wraparound, and limit delta
phase errors}
 DeltaPhase = Phase[1] - Phase;
 If Phase[1] < 90 and Phase > 270 then DeltaPhase = 360 + Phase[1] - Phase;
 If DeltaPhase < 1 then DeltaPhase = 1;
 If DeltaPhase > 60  then Deltaphase = 60;

 {Sum DeltaPhases to reach 360 degrees.  The sum is the instantaneous
period.}
 InstPeriod = 0;
 Value4 = 0;
 For count = 0 to 40 begin
  Value4 = Value4 + DeltaPhase[count];
  If Value4 > 360 and InstPeriod = 0 then begin
   InstPeriod = count;
  end;
 end;

 {Resolve Instantaneous Period errors and smooth}
 If InstPeriod = 0 then InstPeriod = InstPeriod[1];
 Value5 = .25*(InstPeriod) + .75*Period[1];

 {Compute Trendline as simple average over the measured dominant cycle
period}
 Period = IntPortion(Value5);
 Trendline = 0;
 For  count = 0 to Period + 1 begin
  Trendline = Trendline + Price[count];
 end;
 If Period > 0 then Trendline = Trendline / (Period + 2);

  Value11 = .33*(Price + .5*(Price - Price[3])) + .67*Value11[1];

 if CurrentBar < 26 then begin
  Trendline = Price;
  Value11 = Price;
 end;
end;

Condition20 =   value11 crosses above trendline;    {price crosses above
trendline}
Condition21 =   value11 crosses below trendline;    {price crosses below
trendline}


{Long entry}

If condition20 then
 Buy ("Buy") at open ;

{Short entry}

If condition21 then
 Sell ("Sell")  at open ;



{Fixed exits}
Inputs: LXLength(4),  SXlength(4);
If BarsSinceEntry = LXLength Then
 ExitLong ("LxBr") this Bar on close ;

If BarsSinceEntry = SXLength Then
 ExitShort ("SxBr")  on close;

If lastBarOnChart Then
 Exitlong  on close;

If lastBarOnChart Then
    Exitshort this bar on close;


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

{CODE FOR INDICATOR}

{***************************************************************************
******
 Instantaneous Trend Line By John Ehlers - May 2000 article in Technical
Analysis of Stocks and Commodities

Ehlers uses a two-mode market model: trending or cycling. By removing the
dominant cycle from the price data, the remaining information is mostly
about trend. Here is the EasyLanguage Code to plot Instantaneous Trend Line}

Inputs: Price((H+L)/2);

Vars: InPhase(0),
  Quadrature(0),
  Phase(0),
  DeltaPhase(0),
  count(0),
  InstPeriod(0),
  Period(0),
  Trendline(0);

If CurrentBar > 5 then begin

 {Compute InPhase and Quadrature components}
 Value1 = Price - Price[6];
 Value2 =Value1[3];
 Value3 =.75*(Value1 - Value1[6]) + .25*(Value1[2] - Value1[4]);
 InPhase = .33*Value2 + .67*InPhase[1];
 Quadrature = .2*Value3 + .8*Quadrature[1];

 {Use ArcTangent to compute the current phase}
 If AbsValue(InPhase +InPhase[1]) > 0 then Phase =
ArcTangent(AbsValue((Quadrature+Quadrature[1]) / (InPhase+InPhase[1])));

 {Resolve the ArcTangent ambiguity}
 If InPhase < 0 and Quadrature > 0 then Phase = 180 - Phase;
 If InPhase < 0 and Quadrature < 0 then Phase = 180 + Phase;
 If InPhase > 0 and Quadrature < 0 then Phase = 360 - Phase;

 {Compute a differential phase, resolve phase wraparound, and limit delta
phase errors}
 DeltaPhase = Phase[1] - Phase;
 If Phase[1] < 90 and Phase > 270 then DeltaPhase = 360 + Phase[1] - Phase;
 If DeltaPhase < 1 then DeltaPhase = 1;
 If DeltaPhase > 60  then Deltaphase = 60;

 {Sum DeltaPhases to reach 360 degrees.  The sum is the instantaneous
period.}
 InstPeriod = 0;
 Value4 = 0;
 For count = 0 to 40 begin
  Value4 = Value4 + DeltaPhase[count];
  If Value4 > 360 and InstPeriod = 0 then begin
   InstPeriod = count;
  end;
 end;

 {Resolve Instantaneous Period errors and smooth}
 If InstPeriod = 0 then InstPeriod = InstPeriod[1];
 Value5 = .25*(InstPeriod) + .75*Period[1];

 {Compute Trendline as simple average over the measured dominant cycle
period}
 Period = IntPortion(Value5);
 Trendline = 0;
 For  count = 0 to Period + 1 begin
  Trendline = Trendline + Price[count];
 end;
 If Period > 0 then Trendline = Trendline / (Period + 2);

  Value11 = .33*(Price + .5*(Price - Price[3])) + .67*Value11[1];

 if CurrentBar < 26 then begin
  Trendline = Price;
  Value11 = Price;
 end;
 Plot1(Trendline, "TR");
 Plot2(Value11, "ZL");
end;

----------------------------------------------------------------------------
----