PureBytes Links
Trading Reference Links
|
You didn't say what kind of trendlines you want to work with but linear
regression trendlines are relatively simple in EL. See below for an
indicator which builds a pair of linear regression trendlines and plots a
pair of trend channels (one for last "n" periods and one for "n"
previous periods). This kind of code has many uses - I run this
indicator in 3 time periods (20, 50, 150) on both price and OBV to
instantly spot trends and divergences. All you need to do is calculate
a begin or end point and the slope and then manipulate the slope for
the required periods forward or backward. Uncomment the print
command and adjust file name as required so you can see how it
works. LR doesn't care if periods are minute, daily, weekly, etc.
All you need to do is provide code to evaluate where you are relative
to trendline or channel and then set your system entry/exit.
Earl Adamy
-----Original Message-----
From: Jay Poswolsky <jaytradr@xxxxxxxxxxxxx>
To: omega-list@xxxxxxxxxx <omega-list@xxxxxxxxxx>
Date: Wednesday, January 21, 1998 2:39 PM
Subject: EL Help - Coding Trendlines
>I've been trying to code an EL system that would exit positions when the
>price penetrates a trendline. This is often an effective way of keeping
>your profits. I am unable to follow the examples in Omega's EL book and
>would very much appreciate someone posting the code to incorporate
>Trendlines in an intraday system.
{ **************************************************************************
***
Indicator : i_LRPriceShort
Date : 8/19/95 2:56PM
Author : Earl Adamy Copyright 1995, all rights reserved.
Transfer : o:\omega\inds\lrprice
History : 8/19/95 9:06AM create indicator to mark pivot points
Purpose : Draw linear regression lines for two past periods
Notes : MaxPlotBarsBack must be long enough for pivot extreme to be
reversed
****************************************************************************
* }
Inputs : Periods(20);
vars : LRValueEnd(0),
LRSlopeEnd(0),
LRStdDevEnd(0),
LRValueBeg(0),
PlotBarsBack(0),
LRChanWidth(0);
LRValueEnd = LinearRegValue(Close, Periods, 0);
LRSlopeEnd = LinearRegSlope(Close, Periods);
LRStdDevEnd = StdDev(Close, Periods);
{
Print(file("o:\omega\i_LRPrc.log"),Date, BarNumber, " Close ", Close, "
LRVal ", LRValueEnd, " LRSlp ", LRSlopeEnd, " LRStd ", LRStdDevEnd);
}
If Date = LastCalcDate Then Begin
{Plot end of last LR period)}
PlotBarsBack = 0;
LRChanWidth = (2 * LRStdDevEnd[PlotBarsBack]);
Plot1[PlotBarsBack](LRValueEnd[PlotBarsBack],"LRP Short");
Plot2[PlotBarsBack]((LRValueEnd + LRChanWidth)[PlotBarsBack],"LRP S
Upper");
Plot3[PlotBarsBack]((LRValueEnd - LRChanWidth)[PlotBarsBack],"LRP S
Lower");
{Plot begin of last LR period)}
LRValueBeg = LRValueEnd[PlotBarsBack] + ((Periods-1) *
(LRSlopeEnd[PlotBarsBack] * -1));
PlotBarsBack = Periods - 1;
Plot1[PlotBarsBack](LRValueBeg, "LRP Short");
Plot2[PlotBarsBack]((LRValueBeg + LRChanWidth), "LRP S Upper");
Plot3[PlotBarsBack]((LRValueBeg - LRChanWidth), "LRP S Lower");
{Plot end of prev LR period)}
Plot4[Periods](LRValueEnd[Periods],"LRP S Prev");
{Plot begin of last LR period)}
LRValueBeg = LRValueEnd[Periods] + ((Periods-1) *
(LRSlopeEnd[Periods] * -1));
PlotBarsBack = (Periods * 2) - 1;
Plot4[PlotBarsBack](LRValueBeg, "LRP S Prev");
end;
|