####Overview This strategy is based on the HalfTrend indicator and identifies buy signals by determining bullish and bearish trends. When the HalfTrend indicator switches from bearish to bullish, a stop-limit buy order is placed at the HalfTrend value of the previous bearish trend. The strategy uses the AmplitudeTrend (ATR) indicator to dynamically adjust the amplitude parameter for trend determination.
####Strategy Principle
####Strategy Advantages
####Strategy Risks
####Strategy Optimization Directions
####Summary The HalfTrend Bullish and Bearish Trend Following Stop-Limit Buy Strategy determines the timing of buying based on changes in the bullish and bearish trends of the HalfTrend indicator. It uses the low point of the previous bearish trend as the buy position, aiming to enter long positions at relatively safe low levels. This strategy incorporates common strategy elements such as trend determination, limit orders, and stop-loss orders, and it can be further optimized to improve the risk-reward ratio.
/*backtest start: 2023-05-11 00:00:00 end: 2024-05-16 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("HalfTrend Stop-Limit Buy", overlay=true) // HalfTrend indicator parameters length = 1 amplitude = 2.0 // HalfTrend calculation float ph = na float pl = na var float dir = na var float trend = na if na(trend) trend := close ph := high pl := low dir := na else if high > ph ph := high if low < pl pl := low if close > trend and na(dir) dir := 1 trend := close ph := high pl := low if close < trend and na(dir) dir := -1 trend := close ph := high pl := low if dir == 1 and close < trend - amplitude dir := -1 trend := close ph := high pl := low if dir == -1 and close > trend + amplitude dir := 1 trend := close ph := high pl := low // Buy signal based on HalfTrend buySignal = dir == 1 and ta.valuewhen(dir == -1, trend, 0) // Plot HalfTrend plot(dir == 1 ? trend : na, color=color.blue, linewidth=2, title="HalfTrend Bullish") plot(dir == -1 ? trend : na, color=color.red, linewidth=2, title="HalfTrend Bearish") // Place a stop-limit buy order if (buySignal) stopPrice = ta.valuewhen(dir == -1, trend, 0) strategy.entry("HalfTrend Buy", strategy.long, stop=stopPrice, comment="HalfTrend Buy")template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6