by Capie1 » Wed Aug 11, 2010 11:07 am
Herewith the Tradestation code (2 indicators/parts):
//Chop Filter Trendlines
inputs:
LineThickness(1),
LineColour(Yellow),
LongColour(Green),
ShortColour(Red),
ResetEndWeek(False),
// LineStyle(1),
ShowReversalLines(False),
ATRperiod(100);
// FilterColour(Blue);
Variables:
ChopFilterHi(0),
ChopFilterLo(0),
TLChopFilterHi(0),
TLChopFilterLo(0),
TLLongRev(0),
TLShortRev(0),
LongRev(0),
ShortRev(0),
ChopFilter(False);
//Re-set the filter at the start of a new week
If ResetEndWeek then begin
if DayOfWeek(Date) < DayOfWeek(Date[1]) then ChopFilter = False;
end;
//Identify four inside bodies
if ChopFilter = False then begin
If ResetEndWeek = true then begin
if Open <= High[4] and
Open[1] <= High[4] and
Open[2] <= High[4] and
Open[3] <= High[4] and
Close <= High[4] and
Close[1]<= High[4] and
Close[2]<= High[4] and
Close[3]<= High[4] and
Open >= Low[4] and
Open[1] >= Low[4] and
Open[2] >= Low[4] and
Open[3] >= Low[4] and
Close >= Low[4] and
Close[1]>= Low[4] and
Close[2]>= Low[4] and
Close[3]>= Low[4]
and DayOfWeek(Date) >= DayOfWeek(Date[4])//so the filter is entirely within the current week
then begin
ChopFilter = True;
ChopFilterHi = High[4];
ChopFilterLo = Low[4];
end;
end;
If ResetEndWeek = false then begin
if Open <= High[4] and
Open[1] <= High[4] and
Open[2] <= High[4] and
Open[3] <= High[4] and
Close <= High[4] and
Close[1]<= High[4] and
Close[2]<= High[4] and
Close[3]<= High[4] and
Open >= Low[4] and
Open[1] >= Low[4] and
Open[2] >= Low[4] and
Open[3] >= Low[4] and
Close >= Low[4] and
Close[1]>= Low[4] and
Close[2]>= Low[4] and
Close[3]>= Low[4]
then begin
ChopFilter = True;
ChopFilterHi = High[4];
ChopFilterLo = Low[4];
end;
end;
end;
//Re-set the filter at the start of a new week
//if DayOfWeek(Date[1]) > DayOfWeek(Date) then ChopFilter = False;
//Identify a confirmed break of the range
If ChopFilter = True then begin
If Close > ChopFilterHi
or Close < ChopFilterLo
then ChopFilter = False;
end;
//Calculate the reversal levels
LongRev = ChopFilterLo + (AvgTrueRange(ATRperiod)data2 * 0.2);
ShortRev = ChopFilterHi - (AvgTrueRange(ATRperiod)data2 * 0.2);
//Draw the lines
if ChopFilter then
begin
if ChopFilter = true then begin
TLChopFilterHi = TL_New( Date[4], Time[4] , ChopFilterHi, Date, Time, ChopFilterHi ) ;
TL_SetExtLeft( TLChopFilterHi,false ) ;
TL_SetExtRight( TLChopFilterHi, false ) ;
TL_SetColor( TLChopFilterHi, LineColour ) ;
TL_SetSize( TLChopFilterHi, LineThickness ) ;
// TL_SetStyle( TLChopFilterHi, LineStyle ) ;
end;
if ChopFilter = true then begin
TLChopFilterLo = TL_New( Date[4], Time[4] , ChopFilterLo, Date, Time, ChopFilterLo ) ;
TL_SetExtLeft( TLChopFilterLo,false ) ;
TL_SetExtRight( TLChopFilterLo, false ) ;
TL_SetColor( TLChopFilterLo, LineColour ) ;
TL_SetSize( TLChopFilterLo, LineThickness ) ;
// TL_SetStyle( TLChopFilterLo, LineStyle ) ;
end;
if ShowReversalLines then begin
if ChopFilter = true then begin
TLLongRev = TL_New( Date[4], Time[4] , LongRev, Date, Time, LongRev ) ;
TL_SetExtLeft( TLLongRev,false ) ;
TL_SetExtRight( TLLongRev, false ) ;
TL_SetColor( TLLongRev, LongColour ) ;
TL_SetSize( TLLongRev, LineThickness ) ;
// TL_SetStyle( TLChopFilterHi, LineStyle ) ;
end;
if ChopFilter = true then begin
TLShortRev = TL_New( Date[4], Time[4] , ShortRev, Date, Time, ShortRev ) ;
TL_SetExtLeft( TLShortRev,false ) ;
TL_SetExtRight( TLShortRev, false ) ;
TL_SetColor( TLShortRev, ShortColour ) ;
TL_SetSize( TLShortRev, LineThickness ) ;
// TL_SetStyle( TLChopFilterLo, LineStyle ) ;
end;
end;
end;
Part 2
//Chop Filter (Paintbar)
inputs: ResetEndWeek(False),
FilterColour(Yellow);
Variables:
ChopFilterHi(0),
ChopFilterLo(0),
ChopFilter(False);
//Identify four inside bodies
if ChopFilter = False then begin
If ResetEndWeek = true then begin
if Open <= High[4] and
Open[1] <= High[4] and
Open[2] <= High[4] and
Open[3] <= High[4] and
Close <= High[4] and
Close[1]<= High[4] and
Close[2]<= High[4] and
Close[3]<= High[4] and
Open >= Low[4] and
Open[1] >= Low[4] and
Open[2] >= Low[4] and
Open[3] >= Low[4] and
Close >= Low[4] and
Close[1]>= Low[4] and
Close[2]>= Low[4] and
Close[3]>= Low[4]
and DayOfWeek(Date) >= DayOfWeek(Date[4])//so the filter is entirely within the current week
then begin
ChopFilter = True;
ChopFilterHi = High[4];
ChopFilterLo = Low[4];
end;
end;
If ResetEndWeek = false then begin
if Open <= High[4] and
Open[1] <= High[4] and
Open[2] <= High[4] and
Open[3] <= High[4] and
Close <= High[4] and
Close[1]<= High[4] and
Close[2]<= High[4] and
Close[3]<= High[4] and
Open >= Low[4] and
Open[1] >= Low[4] and
Open[2] >= Low[4] and
Open[3] >= Low[4] and
Close >= Low[4] and
Close[1]>= Low[4] and
Close[2]>= Low[4] and
Close[3]>= Low[4]
then begin
ChopFilter = True;
ChopFilterHi = High[4];
ChopFilterLo = Low[4];
end;
end;
end;
//Re-set the filter at the start of a new week
If ResetEndWeek then begin
if DayOfWeek(Date) < DayOfWeek(Date[1]) then ChopFilter = False;
end;
//Identify a confirmed break of the range
If ChopFilter = True then begin
If Close > ChopFilterHi
or Close < ChopFilterLo
then ChopFilter = False;
end;
if ChopFilter then
begin
PlotPaintBar( High, Low, Open, Close, "ChopFilter", FilterColour ) ;
Alert ;
end
else
NoPlot( 1 ) ; { unpaint the bar }