{ Function: _TLPlot Description: Draw a plot using a series of trend line segments. The zero index of arrays ID1, ID2, ID3... etc. is used to to hold a flag value indicating if trend line ID numbers have been created for this plot number in a prior call to this function. If the value of IDn(0) = 0 then the trend line number array is dimensioned and the trend line numbers are generated. if IDn(0) = 1, then array dimensioning and trend line number generation has already been done and does not have to be repeated. Arrays to hold trend line ID numbers associated with a particular PlotNr are only dimensioned the first time the PlotNr is used, preserving memory. Unused PlotNr's consume no memory. NOTE: Call only during end of bar (BarStatus(1) = 2) Author: MarkSanDiego Updated: 08/21/09 original version 10/03/09 documentation cleanup 10/21/09 improved documentation 03/12/10 increase number of plots to 8 09/23/12 increase number of plots to 10 05/20/13 set default right extend for all TL to false, as EL defaults were changed with 9.1 version 20. Usage: _______________________________________________________________________________________________________________________________ inputs: PlotNr(1), { plot number } Price(close), { Price to be plotted } Length(200), { number of bars to be plotted to the left of current bar } PriceOffset(1), { price offset } PlotOffset(0), { offset from rightmost bar of chart } TLStyle(Tool_Solid), { trend line style: [Tool_Solid, Tool_Dashed, Tool_Dotted, Tool_Dashed2, Tool_Dashed3] } TLColor(yellow), { color of trend line } TLSize(0); { width of trend line } vars: Optimizing(GetAppInfo(aiOptimizing) = 1); { plot only when not optimizing } if Optimizing = false then begin value1 = _TLPlot(PlotNr, Price, Length, PriceOffset, PlotOffset, TLStyle, TLColor, TLSize); end; _______________________________________________________________________________________________________________________________ } inputs: PlotNr(NumericSimple), { plot number } Price(NumericSeries), { Price to be plotted } Length(NumericSimple), { number of bars to be plotted to the left of current bar } PriceOffset(NumericSimple), { price offset } PlotOffset(NumericSimple), { offset from rightmost bar of plot } TLStyle(NumericSimple), TLColor(NumericSeries), TLSize(NumericSimple); vars: intrabarpersist ID(0), int j(PlotOffset + 1), int k(PlotOffset + PriceOffset + 1), int n(0), PassNr(0); Arrays: { define dynamic arrays } intrabarpersist ID1[](0), { presently defined to plot up to 10 plots of Length bars. } intrabarpersist ID2[](0), { Increase number of arrays as needed for more plots. } intrabarpersist ID3[](0), { Arrays are dimensioned only if called, to conserve memory space. } intrabarpersist ID4[](0), intrabarpersist ID5[](0), intrabarpersist ID6[](0), intrabarpersist ID7[](0), intrabarpersist ID8[](0), intrabarpersist ID9[](0), intrabarpersist ID10[](0); If Length > 0 then begin switch PlotNr begin case 1: if ID1[0] = 0 then begin Array_SetMaxIndex(ID1, Length); for n = 1 to Length begin ID1[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID1[n], false); TL_SetStyle(ID1[n], TLStyle); TL_SetColor(ID1[n], TLColor); TL_SetSize(ID1[n], TLSize); end; ID1[0] = 1; end else ID = ID1[MOD(CurrentBar, Length) + 1]; { MOD function creates a circular index for array } case 2: if ID2[0] = 0 then begin Array_SetMaxIndex(ID2, Length); for n = 1 to Length begin ID2[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID2[n], false); TL_SetStyle(ID2[n], TLStyle); TL_SetColor(ID2[n], TLColor); TL_SetSize(ID2[n], TLSize); end; ID2[0] = 1; end else ID = ID2[MOD(CurrentBar, Length) + 1]; case 3: if ID3[0] = 0 then begin Array_SetMaxIndex(ID3, Length); for n = 1 to Length begin ID3[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID3[n], false); TL_SetStyle(ID3[n], TLStyle); TL_SetColor(ID3[n], TLColor); TL_SetSize(ID3[n], TLSize); end; ID3[0] = 1; end else ID = ID3[MOD(CurrentBar, Length) + 1]; case 4: if ID4[0] = 0 then begin Array_SetMaxIndex(ID4, Length); for n = 1 to Length begin ID4[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID4[n], false); TL_SetStyle(ID4[n], TLStyle); TL_SetColor(ID4[n], TLColor); TL_SetSize(ID4[n], TLSize); end; ID4[0] = 1; end else ID = ID4[MOD(CurrentBar, Length) + 1]; case 5: if ID5[0] = 0 then begin Array_SetMaxIndex(ID5, Length); for n = 1 to Length begin ID5[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID5[n], false); TL_SetStyle(ID5[n], TLStyle); TL_SetColor(ID5[n], TLColor); TL_SetSize(ID5[n], TLSize); end; ID5[0] = 1; end else ID = ID5[MOD(CurrentBar, Length) + 1]; case 6: if ID6[0] = 0 then begin Array_SetMaxIndex(ID6, Length); for n = 1 to Length begin ID6[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID6[n], false); TL_SetStyle(ID6[n], TLStyle); TL_SetColor(ID6[n], TLColor); TL_SetSize(ID6[n], TLSize); end; ID6[0] = 1; end else ID = ID6[MOD(CurrentBar, Length) + 1]; case 7: if ID7[0] = 0 then begin Array_SetMaxIndex(ID7, Length); for n = 1 to Length begin ID7[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID7[n], false); TL_SetStyle(ID7[n], TLStyle); TL_SetColor(ID7[n], TLColor); TL_SetSize(ID7[n], TLSize); end; ID7[0] = 1; end else ID = ID7[MOD(CurrentBar, Length) + 1]; case 8: if ID8[0] = 0 then begin Array_SetMaxIndex(ID8, Length); for n = 1 to Length begin ID8[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID8[n], false); TL_SetStyle(ID8[n], TLStyle); TL_SetColor(ID8[n], TLColor); TL_SetSize(ID8[n], TLSize); end; ID8[0] = 1; end else ID = ID8[MOD(CurrentBar, Length) + 1]; case 9: if ID9[0] = 0 then begin Array_SetMaxIndex(ID9, Length); for n = 1 to Length begin ID9[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID9[n], false); TL_SetStyle(ID9[n], TLStyle); TL_SetColor(ID9[n], TLColor); TL_SetSize(ID9[n], TLSize); end; ID9[0] = 1; end else ID = ID9[MOD(CurrentBar, Length) + 1]; case 10: if ID10[0] = 0 then begin Array_SetMaxIndex(ID10, Length); for n = 1 to Length begin ID10[n] = TL_New(Date, Time, 0, Date, Time, 0); TL_SetExtRight(ID10[n], false); TL_SetStyle(ID10[n], TLStyle); TL_SetColor(ID10[n], TLColor); TL_SetSize(ID10[n], TLSize); end; ID10[0] = 1; end else ID = ID10[MOD(CurrentBar, Length) + 1]; end; { re-use the trend line segment furthest to the left by positioning it to the current bar position } { skip first 4 passes through strategy (a single bar) to avoid plotting starting value of TL = zero } PassNr = PassNr + 1; if ID > 0 and PassNr > 4 then begin TL_SetEnd(ID, Date[PlotOffset], Time[PlotOffset], Price[PlotOffset + PriceOffset]) ; TL_SetBegin(ID, Date[j], Time[j], Price[k]); TL_SetColor(ID, TLColor); // { repeat SetEnd command to eliinate smearing of TL "dots" } // TL_SetEnd(ID, Date[PlotOffset], Time[PlotOffset], Price[PlotOffset + PriceOffset]) ; end; end; _TLPlot = 0;