Advertisement
Maurizio-Ciullo

41 Indicatore Stop Loss Legato

Mar 3rd, 2024
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //---------------------------------------------- Inizio 41 Lezione Personale Indicatore Stop Loss Legato All'Ingresso ----------------------------------------------//
  2.  
  3. //@version=5
  4. strategy("Indicatore Stop Loss Legato All'Ingresso", overlay=true, margin_long=100, margin_short=100)
  5.  
  6. atr = ta.atr(14)
  7. p4 = plot(atr, "ATR", color = color.yellow, style = plot.style_cross)
  8.  
  9. atrNeg1 = low - atr
  10. atrPos1 = high + atr
  11.  
  12. plot(atrNeg1, title="atrNeg1")
  13. plot(atrPos1, title="atrPos1")
  14.  
  15. var stopLong = 0.0
  16. var stopShort = 0.0
  17.  
  18. mediaSemplice = ta.sma(close, 14)
  19. plot(mediaSemplice, title="mediaSemplice")
  20.  
  21.  
  22. isFlat() =>
  23.     strategy.position_size == 0
  24.  
  25. isLong() =>
  26.     strategy.position_size > 0
  27.  
  28. isShort() =>
  29.     strategy.position_size < 0
  30.  
  31.  
  32. if isFlat() and ta.crossover(close, mediaSemplice)
  33.     strategy.entry("Long IN", strategy.long)
  34.  
  35. TotalTrades() =>
  36.     strategy.closedtrades + strategy.opentrades
  37.  
  38. if  isLong() and strategy.opentrades[1] == 0
  39.     atrNeg = low - atr
  40.     atrPos = high + atr
  41.  
  42.     stopLong := atrNeg
  43.     stopShort := atrPos
  44.  
  45.  
  46. else if isFlat()
  47.     stopLong := 0.0
  48.     stopShort := 0.0
  49.  
  50. plotshape(stopLong, "ATR neg", color = color.red)
  51. plotshape(stopShort, "ATR pos", color = color.green)
  52.  
  53.  
  54. if isLong()
  55.     strategy.exit('SL e TP', from_entry="Long IN", stop= stopLong,alert_message = "Your Long SL-TP Has Been Triggered.")
  56.  
  57. //---------------------------------------------- Fine 41 Lezione Personale Indicatore Stop Loss Legato All'Ingresso ----------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement