Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study("Pivot Reversal Strategy Alerts V2", overlay=true)
- // Inputs
- leftBars = input(4)
- rightBars = input(2)
- // Calculate Pivot Points
- swh = pivothigh(leftBars, rightBars)
- swl = pivotlow(leftBars, rightBars)
- swh_cond = not na(swh)
- hprice = 0.0
- hprice := swh_cond ? swh : hprice[1]
- swl_cond = not na(swl)
- lprice = 0.0
- lprice := swl_cond ? swl : lprice[1]
- // Signals
- long = crossover(high, hprice + syminfo.mintick)
- short = crossunder(low, lprice - syminfo.mintick)
- last_signal = 0
- long_final = long and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == -1)
- short_final = short and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == 1)
- last_signal := long_final ? 1 : short_final ? -1 : last_signal[1]
- // Plotting
- plotshape(long_final, style = shape.arrowup, color = green, location = location.abovebar, text = "Long")
- plotshape(short_final, style = shape.arrowdown, color = red, location = location.belowbar, text = "Short")
- plot(lprice, color = red)
- plot(hprice, color = green)
- // Alerts
- alertcondition(long_final, "Pivot Long", "Pivot Long")
- alertcondition(short_final, "Pivot Short", "Pivot Short")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement