Advertisement
Maurizio-Ciullo

Indicatore Stop Loss Legato All'Ingresso

Mar 3rd, 2024
690
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This Pine Scriptβ„’ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // Β© Maurizio-Ciullo
  3.  
  4. //@version=5
  5. strategy("Indicatore Stop Loss Legato All'Ingresso", overlay=true, margin_long=100, margin_short=100)
  6.  
  7. atr = ta.atr(14)
  8. p4 = plot(atr, "ATR", color = color.yellow, style = plot.style_cross)
  9.  
  10. atrNeg1 = low - atr
  11. atrPos1 = high + atr
  12.  
  13. plot(atrNeg1, title="atrNeg1")
  14. plot(atrPos1, title="atrPos1")
  15.  
  16. var stopLong = 0.0
  17. var stopShort = 0.0
  18.  
  19. mediaSemplice = ta.sma(close, 14)
  20. plot(mediaSemplice, title="mediaSemplice")
  21.  
  22.  
  23. isFlat() =>
  24.     strategy.position_size == 0
  25.  
  26. isLong() =>
  27.     strategy.position_size > 0
  28.  
  29. isShort() =>
  30.     strategy.position_size < 0
  31.  
  32.  
  33. if isFlat() and ta.crossover(close, mediaSemplice)
  34.     strategy.entry("Long IN", strategy.long)
  35.  
  36. TotalTrades() =>
  37.     strategy.closedtrades + strategy.opentrades
  38.  
  39. if  isLong() and strategy.opentrades[1] == 0
  40.     atrNeg = low - atr
  41.     atrPos = high + atr
  42.  
  43.     stopLong := atrNeg
  44.     stopShort := atrPos
  45.  
  46.  
  47. else if isFlat()
  48.     stopLong := 0.0
  49.     stopShort := 0.0
  50.  
  51. plotshape(stopLong, "ATR neg", color = color.red)
  52. plotshape(stopShort, "ATR pos", color = color.green)
  53.  
  54.  
  55. if isLong()
  56.     strategy.exit('SL e TP', from_entry="Long IN", stop= stopLong,alert_message = "Your Long SL-TP Has Been Triggered.")
Advertisement
Comments
  • tradingviewcodes
    109 days
    # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement