PureBytes Links
Trading Reference Links
|
I've found this very valuable code for drawing sup& res, so the credt goes
to Mr Anonymous.
Can someone help me to change the code that the support and resistance lines
will stop when a line is crossed by a close?
At the moment all lines are extended to the right and after some time the
chart is a little bit too confused.
It should be possible but I don't know what I have to change.
thanks
Jim
______-
inputs:LS(30 ),RS(5),TLCount(5),tlStyle(tool_dotted),tlSize(1),
DecPlaces(2), ExtendRight(true),TextVPos(0),ColorScheme(1), ShowText(true);
vars: x( 0 ), MaxTL( 100 ),color( 0 ),NoColor(GetBackGroundColor),
NumTL(TLCount),Color_Scheme(0),Color_Index(1);
array: PivotLowTL [ 3,100 ](-1);{tlID, price and textID for 100 trendlines}
array: PivotHighTL[ 3,100 ](-1);{tlID, price and textID for 100 trendlines}
array: Colors[2,8](0); { light and dark colors }
{ verify within array bounds }
if BarNumber = 1 then
begin
if NumTL > MaxTL then
NumTL = MaxTL;
{ color scheme 1 light colors }
Colors[1,1] = tool_blue;
Colors[1,2] = tool_cyan;
Colors[1,3] = tool_green;
Colors[1,4] = tool_magenta;
Colors[1,5] = tool_red;
Colors[1,6] = tool_yellow;
Colors[1,7] = tool_white;
Colors[1,8] = tool_LightGray;
{ color scheme 2 dark colors }
Colors[2,1] = tool_black;
Colors[2,2] = tool_DarkBlue;
Colors[2,3] = tool_DarkCyan;
Colors[2,4] = tool_DarkGreen;
Colors[2,5] = tool_DarkMagenta;
Colors[2,6] = tool_DarkRed;
Colors[2,7] = tool_DarkBrown;
Colors[2,8] = tool_DarkGray;
{ verify ColorScheme ok }
Color_Scheme = ColorScheme;
if Color_Scheme > 2 then
Color_Scheme = 2;
if Color_Scheme < 1 then
Color_Scheme = 1;
end;
{ see if we have a new pivot in place }
x = PivotLowVSBar(1,low,LS,RS,RS+1);
if x = RS then
begin
{ delete oldest trendline and text }
if tl_Exist( PivotLowTL[ 1,1 ] ) then
begin
tl_delete(PivotLowTL[ 1,1 ]);
if ShowText and text_exist(PivotLowTL[ 3,1 ]) then
text_delete(PivotLowTL[ 3,1 ]);
end;
{ push back array }
for x = 1 to NumTL-1
begin
PivotLowTL[ 1,x ] = PivotLowTL[ 1,x+1 ];
PivotLowTL[ 2,x ] = PivotLowTL[ 2,x+1 ];
PivotLowTL[ 3,x ] = PivotLowTL[ 3,x+1 ];
end;
{ create new trendline for new pivot }
PivotLowTL[ 2,NumTL ] = low[ RS ];
begin
PivotLowTL[ 1,NumTL ] = tl_new(date[ RS ],time[ RS ],PivotLowTL[
2,NumTL ],date,time,PivotLowTL[ 2,NumTL ]);
tl_SetStyle(PivotLowTL[ 1,NumTL ],tlStyle);
tl_SetSize(PivotLowTL[ 1,NumTL ],tlSize);
if ExtendRight then
tl_SetExtRight(PivotLowTL[ 1,NumTL ],true);
{ increment color...if at last color goto first color}
{ uses color schemes with min = 1 and max = 8 }
color_index = IFF(color_index = 8,1,color_index + 1);
{if new color = background then increment color}
color_index = IFF(colors[Color_Scheme,Color_Index] = NoColor,color_index +
1,color_index);
{if new color beyond last then goto first color }
color_index = IFF(color_index > 8,1,color_index);
color = colors[Color_Scheme,color_index];
tl_SetColor(PivotLowTL[1,NumTL],color);
if ShowText then
begin
PivotLowTL[ 3,NumTL ] = text_New(date[ RS ],time[ RS ],PivotLowTL[
2,NumTL ],NumToStr(PivotLowTL[ 2,NumTL ],DecPlaces));
text_SetColor(PivotLowTL[ 3,NumTL ],color);
text_SetStyle(PivotLowTL[ 3,NumTL ],1,TextVPos);
end;
end;
end;
{ update positions of trendlines }
if ExtendRight = false then
begin
for x = 1 to NumTL
begin
if PivotLowTL[ 1,x ] > 0 then
tl_SetEnd(PivotLowTL[ 1,x ],date,time,PivotLowTL[ 2,x ]);
end;
end;
{ see if we have a new pivot in place }
x = PivotHighVSBar(1,High,LS,RS,RS+1);
if x = RS then
begin
{ delete oldest trendline and text }
if tl_Exist( PivotHighTL[1,1] ) then
tl_delete(PivotHighTL[1,1]);
if ShowText and text_exist(PivotHighTL[3,1]) then
text_delete(PivotHighTL[3,1]);
{ push back array entries }
for x = 1 to NumTL-1
begin
PivotHighTL[ 1,x ] = PivotHighTL[ 1,x+1 ];
PivotHighTL[ 2,x ] = PivotHighTL[ 2,x+1 ];
PivotHighTL[ 3,x ] = PivotHighTL[ 3,x+1 ];
end;
{ create new trendline for new pivot }
PivotHighTL[2,NumTL] = high[RS];
begin
PivotHighTL[ 1,NumTL ] = tl_new(date[ RS ],time[ RS ],PivotHighTL[
2,NumTL ],date,time,PivotHighTL[ 2,NumTL ]);
tl_SetStyle(PivotHighTL[ 1,NumTL ],tlStyle);
tl_SetSize(PivotHighTL[ 1,NumTL ],tlSize);
if ExtendRight then
tl_SetExtRight(PivotHighTL[ 1,NumTL ],true);
{ increment color...if at last color goto first color}
{ uses color schemes with min = 1 and max = 8 }
color_index = IFF(color_index = 8,1,color_index + 1);
{if new color = background then increment color}
color_index = IFF(colors[Color_Scheme,Color_Index] = NoColor,color_index +
1,color_index);
{if new color beyond last then goto first color }
color_index = IFF(color_index > 8,1,color_index);
color = colors[Color_Scheme,color_index];
tl_SetColor(PivotHighTL[1,NumTL],color);
if ShowText then
begin
PivotHighTL[ 3,NumTL ] = text_New(date[ RS ],time[ RS ],PivotHighTL[
2,NumTL ],NumToStr(PivotHighTL[ 2,NumTL ],DecPlaces));
text_SetColor(PivotHighTL[ 3,NumTL ],color);
text_SetStyle(PivotHighTL[ 3,NumTL ],1,TextVPos);
end;
end;
end;
{ update positions of trendlines }
if ExtendRight = false then
begin
for x = 1 to NumTL
begin
if PivotHighTL[ 1,x ] > 0 then
tl_SetEnd(PivotHighTL[ 1,x ],date,time,PivotHighTL[ 2,x ]);
end;
end;
|