Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- study(title="Nearest Levels R1 by JustUncleL", shorttitle="NEARLVLS R1", overlay=true, scale=scale.right)
- // By: JustUncleL
- // Date: 12-Feb-2017
- // Version: R1
- //
- // Description:
- // Automatically draw the two nearest Highs and Lows to last closed candle
- // high and low.
- //
- // Modifications:
- // R1 - Original
- //
- LookBackLength = input(30,minval=10)
- MinimumGap = input(5,minval=1,title="Minimum Gap between Levels (Points)")
- point = syminfo.mintick
- nearlows(lookback) =>
- price = close
- nl1 = lowest(low[1],lookback)
- nl2 = nl1
- for i = 2 to lookback-1
- nl1 := (price>low[i]) and (price-low[i])<(price-nl1) ? low[i] : nl1
- for i = 2 to lookback-1
- nl2 := (price>low[i]) and (price-low[i])<(price-nl2) and (price-low[i])>(price-nl1)+point*MinimumGap? low[i] : nl2
- [nl1,nl2]
- nearhighs(lookback) =>
- price = close
- nh1 = highest(high[1],lookback)
- nh2 = nh1
- for i = 2 to lookback-1
- nh1 := (high[i]>price) and (high[i]-price)<(nh1-price) ? high[i] : nh1
- for i = 2 to lookback-1
- nh2 := (high[i]>price) and (high[i]-price)<(nh2-price) and (high[i]-price)>(nh1-price)+point*MinimumGap ? high[i] : nh2
- [nh1,nh2]
- //
- [nl1,nl2] = nearlows(LookBackLength)
- [nh1,nh2] = nearhighs(LookBackLength)
- plot( nl1, title="Near Low 1", color=red, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
- plot( nl2, title="Near Low 2", color=red, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
- plot( nh1, title="Near High 1", color=green, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
- plot( nh2, title="Near High 2", color=green, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
- //EOF.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement