Advertisement
xmd79

Reversal finder

Aug 29th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © NS91 2020
  3.  
  4. //@version=4
  5. study("Reversal finder", overlay=true)
  6.  
  7. // Inputs
  8.  
  9. lookback = input(20, "Lookback period for highs and lows")
  10. malen = input(20, "SMA length for candles range")
  11. avrange = sma((high-low), malen)
  12. mult = input(1.5, "Range multiple", type=input.float)
  13. rangethreshold = input(50, "Range threshold (% of candle range)", maxval=99)/100
  14. barcol = input(false, "Highlight signal bars?", type=input.bool)
  15. trackhilo = input(false, "Highlight highest high/lowest low?", type=input.bool)
  16.  
  17. // Signal conditions
  18.  
  19. longsig = (high-low)>=(avrange*mult) and ((low<lowest(low[1],lookback))) and (close>=(high-((high-low)*rangethreshold)))
  20. shortsig = (high-low)>=(avrange*mult) and ((high>highest(high[1], lookback))) and (close<=(low+((high-low)*rangethreshold)))
  21.  
  22. // Plots for highest recent high/lowest recent low
  23.  
  24. hiplot = trackhilo ? highest(high[1], lookback) : na
  25. loplot = trackhilo ? lowest(low[1],lookback) : na
  26.  
  27. plot(loplot, title="Lowest low", color=#FF0000, transp=99, trackprice=true)
  28. plot(hiplot, title="Highest high", color=#00FF03, transp=99, trackprice=true)
  29.  
  30. // Plots for signal occurrences
  31.  
  32. plotshape(longsig, title="Long signal", style=shape.labelup, color=color.yellow, transp=1, location=location.belowbar, size=size.tiny)
  33. plotshape(shortsig, title="Short signal", style=shape.labeldown, color=color.yellow, transp=1, location=location.abovebar, size=size.tiny)
  34. plotshape((longsig and close>open), title="Long signal with up candle", style=shape.labelup, color=#00FF03, transp=1, location=location.belowbar, size=size.tiny)
  35. plotshape((shortsig and close<open), title="Short signal with down candle", style=shape.labeldown, color=#FF0000, transp=1, location=location.abovebar, size=size.tiny)
  36.  
  37. // Bar colours for use with 'highlight signals' option
  38.  
  39. barcolor(barcol ? barcol and longsig ? #00FF03 : barcol and shortsig ? #FF0000 : #4F4F4F : na)
  40.  
  41. // Alert conditions
  42.  
  43. alertcondition(longsig, title="Long signal", message="Reversal finder long signal")
  44. alertcondition(shortsig, title="Short signal", message="Reversal finder short signal")
  45. alertcondition((longsig and close>open), title="Long signal with up candle", message="Reversal finder long signal with up candle")
  46. alertcondition((shortsig and close<open), title="Short signal with down candle", message="Reversal finder short signal with down candle")
  47. alertcondition((longsig or shortsig), title="Long or short signal", message="Reversal finder signal")
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement