//@version=3
strategy("Daily ATR Stop", overlay=true, pyramiding=1)

//inputs ATR
atrLkb = input(7, minval=1, title='ATR Stop Period')
atrRes = input("D", type=resolution, title='ATR Resolution')
atrMult = input(1, step=0.25, title='ATR Stop Multiplier')

//inputs Breakout Long + Profit Long
enter_Long = input(100, minval=1, title='Enter Long')
profit_Long= input(30, minval=1, title='profit Long')
//inputs Breakout Short + Profit Short
enter_Short = input(100, minval=1, title='Enter Short')
profit_Short = input(30, minval=1, title='Profit Short')

//long//
Long_Enter = highest(enter_Long)
Long_Profit = lowest(profit_Long)
//short//
Short_Enter = lowest(enter_Short)
Short_Profit = highest(profit_Short)

//longCondition + long takeprofit
longCondition = false
profit_long = false
longCondition := high >= Long_Enter and strategy.position_size == 0 ? true : false
profit_long := low <= Long_Profit and strategy.position_size > 0 ? true : false
//shortCondition + short takeprofit
shortCondition = false
profit_short = false
shortCondition := low < Short_Enter and strategy.position_size == 0 ? true : false
profit_short := high >= Short_Profit and strategy.position_size < 0 ? true : false

// ATR stoploss
atr = security(tickerid, atrRes, atr(atrLkb))

if (longCondition)
strategy.entry("Long", strategy.long)


if (shortCondition)
strategy.entry("Short", strategy.short)


// Calc ATR Stops
longStop = na
longStop := shortCondition ? na : longCondition and strategy.position_size <=0 ? close - (atr * atrMult) : longStop
shortStop = na
shortStop := longCondition ? na : shortCondition and strategy.position_size >=0 ? close + (atr * atrMult) : shortStop


// Place the exits longs,
strategy.exit("Long ATR Stop","profit_L_cond", "Long",when= longStop, when= profit_long)
// Place the exits Shorts
strategy.exit("Short ATR Stop", "profit_S_cond","Short", when=shortStop, when= profit_short)

// Plot the stoplosses
plot(longStop, style=linebr, color=red, title='Long ATR Stop')
plot(shortStop, style=linebr, color=maroon, title='Short ATR Stop')

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.