This is a trend following strategy based on the Donchian Channel indicator, combined with dynamic stop loss based on the ATR indicator to lock in profits. It belongs to the trend following strategy category.
The strategy uses a 20-period Donchian Channel, where the channel midline is the average of the highest high and lowest low. It goes long when price crosses above the channel midline and goes short when price crosses below the midline. The exit rule is when price touches the dynamic stop loss line, which is calculated as the lowest low of the recent 3 bars minus one third of the ATR value for long positions, and highest high of recent 3 bars plus one third of the ATR value for short positions.
The main advantages of this strategy are:
The main risks of this strategy include:
Some optimization directions for this strategy:
In summary, this is a simple and practical trend following strategy. It identifies trend direction via Donchian Channel and locks in profits with dynamic trailing stop loss, which can effectively follow trends. The strategy is quite practical to use, but can be further optimized in various ways for better performance in more complex market environments.
/*backtest start: 2023-11-29 00:00:00 end: 2023-12-06 00:00:00 period: 30m basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy(title = "dc", overlay = true) atrLength = input(title="ATR Length:", defval=20, minval=1) testStartYear = input(2017, "Backtest Start Year") testStartMonth = input(1, "Backtest Start Month") testStartDay = input(1, "Backtest Start Day") testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0) testEndYear = input(2018, "Backtest Start Year") testEndMonth = input(12) testEndDay = input(31, "Backtest Start Day") testPeriodEnd = timestamp(testEndYear,testEndMonth,testEndDay,0,0) testPeriod() => true //time >= testPeriodStart ? true : false dcPeriod = input(20, "Period") dcUpper = highest(close, dcPeriod)[1] dcLower = lowest(close, dcPeriod)[1] dcAverage = (dcUpper + dcLower) / 2 atrValue=atr(atrLength) useTakeProfit = na useStopLoss = na useTrailStop = na useTrailOffset = na //@version=1 Buy_stop = lowest(low[1],3) - atr(20)[1] / 3 plot(Buy_stop, color=red, title="buy_stoploss") Sell_stop = highest(high[1],3) + atr(20)[1] / 3 plot(Sell_stop, color=green, title="sell_stoploss") plot(dcLower, style=line, linewidth=3, color=red, offset=1) plot(dcUpper, style=line, linewidth=3, color=aqua, offset=1) plot(dcAverage, color=black, style=line, linewidth=3, title="Mid-Line Average") strategy.entry("simpleBuy", strategy.long, when=(close > dcAverage) and cross(close,dcAverage)) strategy.close("simpleBuy",when= ( close< Buy_stop)) strategy.entry("simpleSell", strategy.short,when=(close < dcAverage) and cross(close,dcAverage) ) strategy.close("simpleSell",when=( close > Sell_stop)) //strategy.exit("Exit simpleBuy", from_entry = "simpleBuy", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset) //strategy.exit("Exit simpleSell", from_entry = "simpleSell", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)