Advertisement
PineCoders

Up/Dn alerts

May 8th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. //@version=3
  2. study("Consecutive Up/Down Study", overlay=true)
  3.  
  4. consecutiveBarsUp = input(3)
  5. consecutiveBarsDown = input(3)
  6.  
  7. price = close
  8.  
  9. ups = 0.0
  10. dns = 0.0
  11. ups := price > price[1] ? nz(ups[1]) + 1 : 0
  12. dns := price < price[1] ? nz(dns[1]) + 1 : 0
  13.  
  14. goLong = ups >= consecutiveBarsUp
  15. goShort = dns >= consecutiveBarsDown
  16. // Use your own exit conditions here.
  17. outLong = dns >= consecutiveBarsDown - 1
  18. outShort = ups >= consecutiveBarsUp - 1
  19.  
  20. inLongPosition = na
  21. inShortPosition = na
  22. inLongPosition := (goLong and not inShortPosition[1]) or (inLongPosition[1] and not outLong)
  23. inShortPosition := (goShort and not inLongPosition[1]) or (inShortPosition[1] and not outShort)
  24.  
  25. enterLong = inLongPosition and not inLongPosition[1]
  26. exitLong = inLongPosition[1] and not inLongPosition
  27. enterShort = inShortPosition and not inShortPosition[1]
  28. exitShort = inShortPosition[1] and not inShortPosition
  29.  
  30. alertcondition(enterLong)
  31. alertcondition(exitLong)
  32. alertcondition(enterShort)
  33. alertcondition(exitShort)
  34.  
  35. plotshape(enterLong, location=location.belowbar, style=shape.arrowup, color=lime)
  36. plotshape(exitLong, location=location.abovebar, style=shape.arrowdown, color=green)
  37. plotshape(enterShort, location=location.abovebar, style=shape.arrowdown, color=red)
  38. plotshape(exitShort, location=location.belowbar, style=shape.arrowup, color=maroon)
  39.  
  40. // Debugging.
  41. plotchar(goLong, "goLong", "▲", location.top, size = size.tiny)
  42. plotchar(goShort, "goShort", "▼", location.bottom, size = size.tiny)
  43. plotchar(inLongPosition, "inLongPosition", "—", location.top, size = size.tiny)
  44. plotchar(inShortPosition, "inShortPosition", "—", location.bottom, size = size.tiny)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement