Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

how to draw trend line indicator.

Oct 22, 2021 - 4:59 PM

Viewed 441 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/37763 COPY
  • hi community.i have created a script.in this script i cn only draw trend lines but i wanted to creat indicator.

    //@version=4
    //this study simply draws a trend line base on pivot strength configuration,
    // and also provide configuration by using the close price and show historical trend lines

    study( title=MZR AutoTrendlines, shorttitle=MZR AutoTrendlines, overlay=true)
    useclose=input(false)

    h=useclose?close:high
    l=useclose?close:low

    strength=input(10,title=left Strength, minval=5, maxval=200)

    draw_trend(High, Low, leftlen,rightlen,n)=>

    //upper trend line
    var int startx=0
    var float starty=0.0
    var int startx2=0
    var float starty2=0.0

    var int endx=0
    var float endy=0.0
    var float endy0=0.0
    var float slope=0.0
    var bool ispivothigh =false
    
    ispivothigh:=High[rightlen] == pivothigh(High,leftlen,rightlen)
    
    starty2:=valuewhen(ispivothigh,High[rightlen],n+2)
    startx2 := valuewhen(ispivothigh,bar_index,n+2)
    
    starty:=valuewhen(ispivothigh,High[rightlen],n+1)
    startx := valuewhen(ispivothigh,bar_index,n+1)
    
    endy:=valuewhen(ispivothigh,High[rightlen],n)
    endx := valuewhen(ispivothigh,bar_index,n)
    
    slope:=(endy-starty)/(endx-startx)
    
    
    valend = endy
    var float Endy=0.0
    
    Endy:=abs(endx-startx+rightlen)*slope + starty
    
    if slope<0
    
        if n==0
            upper0 = line.new(endx, Endy, startx-rightlen, starty,  width = 1, color=color.red, extend=extend.left)
            line.delete(upper0[1])
    
        upper1 = line.new(endx, Endy, startx-rightlen, starty,  width = 1, color=color.red, extend=extend.none)
        line.delete(upper1[1])
    
    var float slope2= (endy-starty2)/(endx-startx2)
    var float Endy2=0.0
    
    Endy:=abs(endx-startx2+rightlen)*slope + starty2
    if slope2<0
        upper2 = line.new(endx, Endy2, startx2-rightlen, starty2,  width = 1, color=color.red, extend=extend.none)
        line.delete(upper2[1])
    

    //lower trend line
    var int lstartx=0
    var float lstarty=0.0
    var int lstartx2=0
    var float lstarty2=0.0

    var int lendx=0
    var float lendy=0.0
    var float lendy0=0.0
    var float lslope=0.0
    var bool ispivotlow =false
    
    ispivotlow:=Low[rightlen] == pivotlow(Low,leftlen,rightlen)
    
    lstarty2:=valuewhen(ispivotlow,Low[rightlen],n+2)
    lstartx2 := valuewhen(ispivotlow,bar_index,n+2)
    
    lstarty:=valuewhen(ispivotlow,Low[rightlen],n+1)
    lstartx := valuewhen(ispivotlow,bar_index,n+1)
    
    lendy:=valuewhen(ispivotlow,Low[rightlen],n)
    lendx := valuewhen(ispivotlow,bar_index,n)
    
    lslope:=(lendy-lstarty)/(lendx-lstartx)
    var float lEndy=0.0
    
    lEndy:=abs(lendx-lstartx+rightlen)*lslope + lstarty
    
    
    if lslope>0
    
        if n==0
            Lower0 = line.new(lendx, lEndy, lstartx-rightlen, lstarty,  width = 1, color=color.green, extend=extend.left)
            line.delete(Lower0[1])
    
        Lower1 = line.new(lendx, lEndy, lstartx-rightlen, lstarty,  width = 1, color=color.green, extend=extend.none)
        line.delete(Lower1[1])
    
    var float lslope2= (lendy-lstarty2)/(lendx-lstartx2)
    var float lEndy2=0.0
    
    lEndy:=abs(lendx-lstartx2+rightlen)*lslope + lstarty2
    if lslope2>0
        lower2 = line.new(lendx, lEndy2, lstartx2-rightlen, lstarty2,  width = 1, color=color.green, extend=extend.none)
        line.delete(lower2[1])
    

    left=strength
    right=strength

    //draw current trendling
    draw_trend(h, l,left,right,0)

    showhtrend=input(true, title=Show History Trend Line)

    if showhtrend
    //show history trendling
    draw_trend(h, l,left,right,1)
    draw_trend(h, l,left,right,2)
    draw_trend(h, l,left,right,3)
    draw_trend(h, l,left,right,4)
    draw_trend(h, l,left,right,5)
    draw_trend(h, l,left,right,6)
    draw_trend(h, l,left,right,7)
    draw_trend(h, l,left,right,8)
    draw_trend(h, l,left,right,9)
    draw_trend(h, l,left,right,10)
    draw_trend(h, l,left,right,11)
    draw_trend(h, l,left,right,12)

    0
  • Hi

    I don't understand what you're trying to do and what do you need?

    Dave

    0
CONTENTS