Advertisement
JustUncleL

Nearest Levels

Feb 11th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. //@version=2
  2.  
  3. study(title="Nearest Levels R1 by JustUncleL", shorttitle="NEARLVLS R1", overlay=true, scale=scale.right)
  4.  
  5. // By: JustUncleL
  6. // Date: 12-Feb-2017
  7. // Version: R1
  8. //
  9. // Description:
  10. // Automatically draw the two nearest Highs and Lows to last closed candle
  11. // high and low.
  12. //
  13. // Modifications:
  14. // R1 - Original
  15. //
  16.  
  17. LookBackLength = input(30,minval=10)
  18. MinimumGap = input(5,minval=1,title="Minimum Gap between Levels (Points)")
  19.  
  20. point = syminfo.mintick
  21.  
  22. nearlows(lookback) =>
  23. price = close
  24. nl1 = lowest(low[1],lookback)
  25. nl2 = nl1
  26. for i = 2 to lookback-1
  27. nl1 := (price>low[i]) and (price-low[i])<(price-nl1) ? low[i] : nl1
  28. for i = 2 to lookback-1
  29. nl2 := (price>low[i]) and (price-low[i])<(price-nl2) and (price-low[i])>(price-nl1)+point*MinimumGap? low[i] : nl2
  30. [nl1,nl2]
  31.  
  32. nearhighs(lookback) =>
  33. price = close
  34. nh1 = highest(high[1],lookback)
  35. nh2 = nh1
  36. for i = 2 to lookback-1
  37. nh1 := (high[i]>price) and (high[i]-price)<(nh1-price) ? high[i] : nh1
  38. for i = 2 to lookback-1
  39. nh2 := (high[i]>price) and (high[i]-price)<(nh2-price) and (high[i]-price)>(nh1-price)+point*MinimumGap ? high[i] : nh2
  40. [nh1,nh2]
  41.  
  42. //
  43. [nl1,nl2] = nearlows(LookBackLength)
  44. [nh1,nh2] = nearhighs(LookBackLength)
  45.  
  46. plot( nl1, title="Near Low 1", color=red, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
  47. plot( nl2, title="Near Low 2", color=red, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
  48. plot( nh1, title="Near High 1", color=green, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
  49. plot( nh2, title="Near High 2", color=green, style=linebr, linewidth=2, transp=50, trackprice = true,offset=-9999)
  50.  
  51. //EOF.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement