// Downloaded From https://www.WiseStockTrader.com SetPositionSize(1,spsShares); _SECTION_BEGIN("BB TrendLines"); SetChartOptions(0,chartShowArrows|chartShowDates); if (ParamToggle("Candle Type","Heiken Ashi|Normal",0)) { HaClose = Close; HaOpen = Open; HaHigh = High; HaLow = Low; Color = colorBlack; } else { HACLOSE=(O+H+L+C)/4; HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); HaOpen[0] = Open[0]; HaHigh = Max( H, Max( HaClose, HaOpen ) ); HaLow = Min( L, Min( HaClose, HaOpen ) ); Halow[0] = Low[0]; color = colorWhite; } PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, Name(), color, styleCandle ); xx=BarIndex(); x=xx; Lx=LastValue(x); ShowMini = ParamToggle("TrendLines","Don't Show|Show", 1); SetBarsRequired( sbrAll, sbrAll); Periods = Param( "BB Periods", 30, 1, 250, 1 ); Width = Param( "Width", 1, 0, 5, 0.1 ); npiv_Mini = Param("Pivots to Extend TL",4,1,10,1); RespectAngle_Mini = ParamToggle("Respect TrendLine Angles","No|Yes", 1); CleanPivots_Mini = ParamToggle("Clean Pivots","No|Yes",0); showNonConfirmed_Mini = ParamToggle("Non Confirmed Pivots","Don't Show|Show", 0); showRelation_Mini = ParamToggle("Show Pivots Relation","None|HH LH LH LL", 1); BBTOp = BBandTop( HaHigh, Periods, Width ); BBBot = BBandBot( HaLow, Periods, Width ); Plot( BBTop, "BBTop", colorBlue, styleLine ); Plot( BBBOt, "BBBot", colorBlue, styleLine ); Fundo_Mini = (Low <= BBBot); Pico_Mini = (High >= BBTop); BI_Fundo_Mini = ValueWhen(Fundo_Mini, x, 0); BI_Pico_Mini = ValueWhen(Pico_Mini , x, 0); Next_Pivot_Type = BI_Pico_Mini > BI_Fundo_Mini; Fundo_Mini = Fundo_Mini AND (Next_Pivot_Type==0 OR x==BI_Fundo_Mini); Pico_Mini = Pico_Mini AND (Next_Pivot_Type==1 OR x==BI_Pico_Mini); px1=ValueWhen(Pico_mini,x,1); tx1=ValueWhen(Fundo_mini,x,1); if (shownonconfirmed_Mini==0) { Pico_Mini = Pico_Mini AND ( px1 < BI_Fundo_Mini); Fundo_Mini = Fundo_Mini AND (tx1 < BI_Pico_Mini); } if(CleanPivots_mini) { px0=ValueWhen(Pico_mini,x,0); tx0=ValueWhen(Fundo_mini,x,0); px2=ValueWhen(Pico_mini,x,2); tx2=ValueWhen(Fundo_mini,x,2); ph0=ValueWhen(Pico_mini,HaHigh,0); tl0=ValueWhen(Fundo_mini,HaLow,0); ph1=ValueWhen(Pico_mini,HaHigh,1); tl1=ValueWhen(Fundo_mini,HaLow,1); ph2=ValueWhen(Pico_mini,HaHigh,2); tl2=ValueWhen(Fundo_mini,HaLow,2); Pico_Mini = IIf((ph0>=ph1 AND tx0>px0 AND px0!=px1) OR (ph1tx1) OR (ph0>=ph1 AND tx0tx0 AND tx0!=tx1) OR (tl1>tl2 AND tx2>px1) OR (tl0<=tl1 AND px0 tl2; hh = Pico_mini AND ph1 > ph2; lh = Pico_mini AND ph1 < ph2; dt = Pico_mini AND ph1 == ph2; db = Fundo_mini AND tl1 == tl2; fvb = FirstVisibleValue( x ); lvb = LastVisibleValue( x ); for ( i = lvb;i > fvb;i-- ) { { if ( ll[i] ) PlotTextSetFont( "LL", "Arial Black", 8, i, HaLow[i], colorGreen, color, -30 ); if ( hl[i] ) PlotTextSetFont( "HL", "Arial Black", 8, i, HaLow[i], colorGreen, color, -30 ); if ( db[i] ) PlotTextSetFont( "DB", "Arial Black", 8, i+3, HaLow[i], colorGreen, color, -30 ); if ( hh[i] ) PlotTextSetFont( "HH", "Arial Black", 8, i, HaHigh[i], colorRed, color, 20 ); if ( lh[i] ) PlotTextSetFont( "LH", "Arial Black", 8, i, HaHigh[i], colorRed, color, 20 ); if ( dt[i] ) PlotTextsetFont( "DT", "Arial Black", 8, i+3, HaHigh[i], colorRed, color, 20 ); } } } if (ShowMini) { for (i=1;i<=npiv_mini;i++) { y0=ValueWhen(Fundo_mini,HaLow,i-1); y1=ValueWhen(Fundo_mini,HaLow,i); x0=ValueWhen(Fundo_mini,xx,i-1); x1=ValueWhen(Fundo_mini,xx,i); aa=(y0-y1)/(x0-x1); ls1=aa*(xx-x1)+y1; if (respectAngle_mini) { dls1=ls1-Ref(ls1,-1); ls1=IIf(dls1<0,Null,ls1); } if(i==1) Plot(ls1,"",colorBrightGreen ,styleLine|styleDashed|styleNoRescale,0,0,0,1, width = 1); if(i>1) { ls1=IIf(Fundo_mini,Null,ls1); Plot(ls1,"",colorBrightGreen,styleNoRescale,0,0,0,1,width = 2); } y0=ValueWhen(Pico_mini,HaHigh,i-1); y1=ValueWhen(Pico_mini,HaHigh,i); x0=ValueWhen(Pico_mini,xx,i-1); x1=ValueWhen(Pico_mini,xx,i); aa=(y0-y1)/(x0-x1); hs1=aa*(xx-x1)+y1; if (respectAngle_mini) { dhs1=hs1-Ref(hs1,-1); hs1=IIf(dhs1>0,Null,hs1); } if(i==1) Plot(hs1,"",colorRed,styleLine|styleDashed|styleNoRescale,0,0,0,1, width = 1); if(i>1) { hs1=IIf(Pico_mini,Null,hs1); Plot(hs1,"",colorRed,styleNoRescale,0,0,0,1, width = 2); } } } _SECTION_END();