This strategy implements a configurable percentage trailing stop loss to manage trade risk. It allows setting long and short stop loss percentage from entry price for dynamic stop loss tracking.
The main logic is:
The strategy allows customizing stop percentage, e.g. 10%. For longs, it dynamically calculates 10% above the low as the stop line. For shorts, 10% below the high.
This way, the stop line keeps moving favorably to maximize profit protection while controlling risk.
Mitigations:
Enhancement opportunities:
This strategy provides an effective percentage trailing stop method to dynamically adjust stop loss. It maximizes profit protection while controlling risk. Enhancements through parameter optimization, indicator integration can make the stops more intelligent.
/*backtest start: 2023-08-19 00:00:00 end: 2023-09-18 00:00:00 period: 2h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // © theCrypster //@version=4 strategy("Percent Trailing Stop %", overlay=true) //ENTER SOME SETUP TRADES FOR TSL EXAMPLE longCondition = crossover(sma(close, 10), sma(close, 20)) if (longCondition) strategy.entry("My Long Entry Id", strategy.long) shortCondition = crossunder(sma(close, 10), sma(close, 20)) if (shortCondition) strategy.entry("My Short Entry Id", strategy.short) //TRAILING STOP CODE trailStop = input(title="Long Trailing Stop (%)", type=input.float, minval=0.0, step=0.1, defval=10) * 0.01 longStopPrice = 0.0 shortStopPrice = 0.0 longStopPrice := if strategy.position_size > 0 stopValue = close * (1 - trailStop) max(stopValue, longStopPrice[1]) else 0 shortStopPrice := if strategy.position_size < 0 stopValue = close * (1 + trailStop) min(stopValue, shortStopPrice[1]) else 999999 //PLOT TSL LINES plot(series=strategy.position_size > 0 ? longStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Long Trail Stop", offset=1, title="Long Trail Stop") plot(series=strategy.position_size < 0 ? shortStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Short Trail Stop", offset=1, title="Short Trail Stop") //EXIT TRADE @ TSL if strategy.position_size > 0 strategy.exit(id="Close Long", stop=longStopPrice) if strategy.position_size < 0 strategy.exit(id="Close Short", stop=shortStopPrice)