Awesome, I was able to do what I wanted -- thank you guys !
--- In [email protected], "ricko8294_98" <ri...@...> wrote: > > wow > Quite complex > Try this. > > I've set the 50 as a parameter, and plotted a vertical green dashed line at > the 50th line back. It also has a green line running from its high all the > way to the right. > > By the way, the Howlong function is not my own. Found it on some message > here and thought it was neat. Don't know why or how it works either!! > > The code.... > > Lookback = Param( "Lookback Period", 50, 4, 200, 1 ); // in case you want to > change the value on the fly > LBHi = LastValue( Ref( H, -Lookback ) ); // Lookback High value > > Plot( C, "", colorYellow, 64 ); > > function Howlong( indicator, Length ) > // a length of 0 will place a dot at the last bar > { > > Start = LastValue( Cum( 1 ) - Length ) == Cum( 1 ); > Start2 = Cum( Start ) == 1; > x = ValueWhen( Start2 , indicator, 1 ) ; > return x; > } > > // next get the barindex() values > FinishBar = EndValue( BarIndex() ); > StartBar = FinishBar - Lookback ; > > // Lets plot a vertical line at the Lookback start point to know where the > analysis begins > Plot( BarIndex() == StartBar , "", colorPaleGreen, styleHistogram | > styleDashed | styleOwnScale | styleNoLabel ); > > //Then plot the High of the Lookback bar - this can be removed if it is in > the way > Plot( Howlong( LBHi , Lookback ), "", colorBrightGreen, 1 | styleNoLabel ); > > // Now plot all the highs that are higher > > for ( i = StartBar; i < Finishbar; i++ ) > { > if ( H[i] >= LBHi ) > { > Plot( Howlong( H[i] , Finishbar - i ), "", colorYellow, 1 | > styleNoLabel ); > } > } > > > > --- In [email protected], "tradinghumble" <sharp2be@> wrote: > > > > > > Rick, thank you so much for the code. I'm always impressed by people's > > ability to code in AB... I'm pretty good with coding but some aspects of it > > just go above my head :-) honestly... I understood most of it but the > > HowLong function I just can't get it into my hard head. > > > > What I'm looking to do is to draw a trendline from the point where the > > price was higher than the last 50 bars all the way to the right of the > > chart and a maximum of say 10 ocurrences... > > > > I saw the example below and is sort of what I'm looking for except that > > instead the GetYSupport should get the point where the price breaks the > > high of 50 bars ago... I can't seem to figure it out. > > > > If not too difficult and not too time consuming please share a solution. > > Thanks for your help. > > > > > > _SECTION_BEGIN("Advanced Trend Lines"); > > function GetXSupport(Lo, Percentage, Back) > > { > > return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back))); > > } > > function GetYSupport(Lo, Percentage, Back) > > { > > return (LastValue(Trough(Lo, Percentage, back))); > > } > > > > function GetXResistance(Hi, Percentage, Back) > > { > > return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back))); > > } > > function GetYResistance(Hi, Percentage, Back) > > { > > return (LastValue(Peak(Hi, Percentage, Back))); > > } > > function TD_Supply(P) > > { > > return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2)); > > } > > function TD_Demand(P) > > { > > return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2)); > > } > > //////////////////////////////////////////////////////////////////////// > > //Parameters > > Percentage = Param("Percentage", 1.5, 0.01, 100. ,0.01); > > DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes"); > > Lines = Param("Lines?", 1, 1, BarCount-2); > > DrawR = ParamList("Resistance Points", "Off|High to > > High|High to Low", 1); > > DrawS = ParamList("Support Points", "Off|Low to > > Low|Low to High", 1); > > ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 1); > > AllOrDownR = ParamToggle("Resistance Direction", "All|Down"); > > AllOrUpS = ParamToggle("Support Direction", "All|Up"); > > ShowSR = ParamToggle("Show Vert S/R","No|Yes", 1); > > SRPer = Param("S/R Percentage", 3, 1); > > SRBack = Param("S/R Back", 5, 1); > > str = ""; > > Res = Sup = 0; > > Con = 1; > > //////////////////////////////////////////////////////////////////////// > > Main = C; > > Con = ConS = ConR = 1; > > if(DrawS=="Low to Low") > > { > > Support1 = L; > > Support2 = L; > > } > > else > > { > > Support1 = L; > > Support2 = H; > > } > > if(DrawR=="High to High") > > { > > Resistance1 = H; > > Resistance2 = H; > > } > > else > > { > > Resistance1 = H; > > Resistance2 = L; > > } > > //////////////////////////////////////////////////////////////////////// > > //Plotting Area > > Plot(Main, "", IIf(C>O,colorGreen, colorRed), styleBar); > > if(DrawAllLines) > > for(i = 2; i<=Lines+1; i++) > > { > > if(DrawS!="Off") > > { > > x0 = GetXSupport(Support1, Percentage, i); > > x1 = GetXSupport(Support2, Percentage, i-1); > > y0 = GetYSupport(Support1, Percentage, i); > > y1 = GetYSupport(Support2, Percentage, i-1); > > x = LineArray(x0, y0, x1, y1, 1); > > if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1)); > > if(Con AND ConS) > > Plot(x, "", IIf(LastValue(C) < LastValue(x), > > colorBlue,colorLightBlue), styleLine|styleThick); > > } > > if(DrawR!="Off") > > { > > x0 = GetXResistance(Resistance1, Percentage, i); > > x1 = GetXResistance(Resistance2, Percentage, i-1); > > y0 = GetYResistance(Resistance1, Percentage, i); > > y1 = GetYResistance(Resistance2, Percentage, i-1); > > x = LineArray(x0, y0, x1, y1, 1); > > if(AllOrDownR) ConR = y0 > y1; > > if(Con AND ConR) > > Plot(x, "", IIf(LastValue(C) < LastValue(x), > > colorBlue,colorLightBlue), styleLine|styleThick); > > } > > } > > else > > { > > if(DrawS!="Off") > > { > > x0 = GetXSupport(Support1, Percentage, Lines+1); > > x1 = GetXSupport(Support2, Percentage, Lines); > > y0 = GetYSupport(Support1, Percentage, Lines+1); > > y1 = GetYSupport(Support2, Percentage, Lines); > > x = LineArray(x0, y0, x1, y1, 1 ); > > Sup = LastValue(LinRegSlope(x, Lines+1)); > > if(AllOrUpS) ConS = y0 < y1; > > if(Con AND ConS) > > Plot(x, "", IIf(LastValue(C) < LastValue(x), > > colorBlue,colorLightBlue), styleLine|styleThick); > > } > > if(DrawR!="Off") > > { > > x0 = GetXResistance(Resistance1, Percentage, Lines+1); > > x1 = GetXResistance(Resistance2, Percentage, Lines); > > y0 = GetYResistance(Resistance1, Percentage, Lines+1); > > y1 = GetYResistance(Resistance2, Percentage, Lines); > > x = LineArray(x0, y0, x1, y1, 1 ); > > Res = LastValue(LinRegSlope(x, Lines+1)); > > if(AllOrDownR) ConR = y0 > y1; > > if(Con AND ConR) > > Plot(x, "", IIf(LastValue(C) < LastValue(x), > > colorBlue,colorLightBlue), styleLine|styleThick); > > } > > str = "\nR Slope=("+Res+"), S Slope=("+Sup+")"; > > } > > > > if(ShowTDP) > > { > > PlotShapes(TD_Supply(H)*shapeSmallCircle, colorRed, 0, H, H*.001); > > PlotShapes(TD_Demand(L)*shapeSmallCircle, colorGreen, 0, L, -L*.001); > > } > > if(ShowSR) > > { > > for(i=1; i<=SRBack; i++) > > { > > x0 = GetXSupport(L, SRPer, i); > > x1 = BarCount-1; > > y0 = GetYSupport(L, SRPer, i); > > x = LineArray(x0, y0, x1, y0, 0); > > Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, > > colorDarkRed), styleLine|styleDashed|styleThick); > > x0 = GetXResistance(H, SRPer, i); > > y0 = GetYResistance(H, SRPer, i); > > x = LineArray(x0, y0, x1, y0, 0); > > Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, > > colorDarkRed), styleLine|styleDashed|styleThick); > > > > } > > } > > Title =FullName()+" ({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: > > "+L+", Close: "+C+StrFormat(" (%.2f %.2f\%)", C-Ref(C, -1), > > SelectedValue(ROC(C, 1)))+str; > > > > _SECTION_END(); > > > > --- In [email protected], "ricko8294_98" <ricko@> wrote: > > > > > > > > > try this... > > > > > > > > > function Howlong( indicator, Length ) > > > // a length of 0 will place a dot at the last bar > > > { > > > > > > Start = LastValue( Cum( 1 ) - Length ) == Cum( 1 ); > > > Start2 = Cum( Start ) == 1; > > > x = ValueWhen( Start2 , indicator, 1 ) ; > > > return x; > > > } > > > > > > LBPeriod = Param("Lookback Period",50,5,200,1); > > > HHValue = LastValue( Ref( HHV( H, LBPeriod ), -1 ) ); > > > HHPoint = BarsSince( H == HHValue ); > > > > > > Plot( C, "", colorRed, 64 ); > > > trigger = LastValue( Cross( C , HHValue ) ); > > > > > > if ( trigger ) > > > { > > > Plot( Howlong( HHValue , HHPoint ), "", colorYellow, 1 ); > > > } > > > > > > Best regards > > > Rick > > > --- In [email protected], "tradinghumble" <sharp2be@> wrote: > > > > > > > > I would like have a trendline every time the Close is higher than the > > > > last 50 closes... the trendline should be drawn from the point all the > > > > way to the right of the chart. > > > > > > > > Can anyone please point me in the right direction? > > > > > > > > > >
