Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------- Inizio 41 Lezione Personale Indicatore Stop Loss Legato All'Ingresso ----------------------------------------------//
- //@version=5
- strategy("Indicatore Stop Loss Legato All'Ingresso", overlay=true, margin_long=100, margin_short=100)
- atr = ta.atr(14)
- p4 = plot(atr, "ATR", color = color.yellow, style = plot.style_cross)
- atrNeg1 = low - atr
- atrPos1 = high + atr
- plot(atrNeg1, title="atrNeg1")
- plot(atrPos1, title="atrPos1")
- var stopLong = 0.0
- var stopShort = 0.0
- mediaSemplice = ta.sma(close, 14)
- plot(mediaSemplice, title="mediaSemplice")
- isFlat() =>
- strategy.position_size == 0
- isLong() =>
- strategy.position_size > 0
- isShort() =>
- strategy.position_size < 0
- if isFlat() and ta.crossover(close, mediaSemplice)
- strategy.entry("Long IN", strategy.long)
- TotalTrades() =>
- strategy.closedtrades + strategy.opentrades
- if isLong() and strategy.opentrades[1] == 0
- atrNeg = low - atr
- atrPos = high + atr
- stopLong := atrNeg
- stopShort := atrPos
- else if isFlat()
- stopLong := 0.0
- stopShort := 0.0
- plotshape(stopLong, "ATR neg", color = color.red)
- plotshape(stopShort, "ATR pos", color = color.green)
- if isLong()
- strategy.exit('SL e TP', from_entry="Long IN", stop= stopLong,alert_message = "Your Long SL-TP Has Been Triggered.")
- //---------------------------------------------- Fine 41 Lezione Personale Indicatore Stop Loss Legato All'Ingresso ----------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement