The Gradient Trailing Stop Loss strategy dynamically adjusts the stop loss line to balance risk control and profit taking. It uses the Average True Range (ATR) to calculate the stop loss line and effectively tracks price trends, protecting profits while reducing unnecessary stop outs. This strategy works well for stocks with strong trends and can generate steady returns.
The strategy uses the Average True Range (ATR) as the basis for dynamic stop loss. ATR effectively reflects the volatility of a stock. The strategy first takes the ATR period as input, typically 10 days. Then the ATR value is calculated. As the price rises, the stop loss line also moves up to trail the price. When the price drops, the stop loss line remains unchanged to lock in profits. Also, the strategy allows fine tuning the stop loss distance from the price using a “factor” parameter.
Specifically, the strategy calculates the current ATR, then multiplies it by the “factor” to get the stop loss distance. If the price is above the stop loss price, a long position is opened. If the price is below, a short position is opened. Thus, the stop loss line closely follows the price, achieving a gradient trailing effect.
The Gradient Trailing Stop Loss strategy effectively balances risk and profit by dynamically adjusting the stop loss distance. With simple logic and high configurability, it is suitable for algorithmic trading. Proper parameter tuning and indicator combinations still rely on human expertise. Further optimizations can make this strategy even more profitable.
/*backtest start: 2023-10-17 00:00:00 end: 2023-10-24 00:00:00 period: 10m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Supertrend Strategy, by Ho.J.", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=15) // 백테스팅 시작일과 종료일 입력 startYear = input(2020, title="Start Year") startMonth = input(1, title="Start Month") startDay = input(1, title="Start Day") endYear = input(9999, title="End Year") endMonth = input(12, title="End Month") endDay = input(31, title="End Day") // 백테스팅 시간 범위 확인 backtestingTimeBool = (year >= startYear and month >= startMonth and dayofmonth >= startDay) and (year <= endYear and month <= endMonth and dayofmonth <= endDay) atrPeriod = input(10, "ATR Length") factor = input.float(3.0, "Factor", step = 0.01) [_, direction] = ta.supertrend(factor, atrPeriod) var bool longCondition = false var bool shortCondition = false if backtestingTimeBool prevDirection = direction[1] if direction < 0 longCondition := false shortCondition := true else if direction > 0 longCondition := true shortCondition := false if longCondition strategy.entry("My Long Entry Id", strategy.long) if shortCondition strategy.entry("My Short Entry Id", strategy.short) plot(strategy.equity, title="equity", color=color.rgb(255, 255, 255), linewidth=2, style=plot.style_area)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6