This strategy is based on the bull flag pattern. It buys when the price breaks out above the high of the flag range, sets the stop loss at the low of the flag range, and sets the profit target according to the risk-reward ratio. The strategy uses the highest and lowest price functions to identify the flag range and determines the breakout by comparing the current closing price with the highest price of the previous candle.
This strategy is a breakout strategy based on the classic bull flag pattern, which captures trend continuation opportunities by identifying the flag range and price breakouts. The strategy’s advantages are clear logic and controllable risk, but it faces certain risks in volatile markets or trend reversals. Improvements can be made in terms of optimizing signals, dynamic parameters, position management, etc., to enhance the strategy’s robustness and profitability.
/*backtest start: 2023-05-22 00:00:00 end: 2024-05-27 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Bull Flag Breakout", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // Параметры стратегии riskRewardRatio = 3.0 flagLength = input.int(5, title="Flag Length") stopLossBuffer = input.float(0.01, title="Stop Loss Buffer", step=0.001) // Функция для вычисления стоп-лосса и тейк-профита calcRiskRewardPrice(entryPrice, stopLossPrice, riskRewardRatio) => takeProfitPrice = entryPrice + (entryPrice - stopLossPrice) * riskRewardRatio [stopLossPrice, takeProfitPrice] // Найти минимум и максимум флага flagLow = ta.lowest(low, flagLength) flagHigh = ta.highest(high, flagLength) // Условия для формирования бычьего флага isBullFlag = high[1] < flagHigh and close > high[1] // Условия для входа в сделку if (isBullFlag) entryPrice = close stopLossPrice = flagLow - stopLossBuffer [calculatedStopLoss, calculatedTakeProfit] = calcRiskRewardPrice(entryPrice, stopLossPrice, riskRewardRatio) // Открыть длинную позицию strategy.entry("Bull Flag Long", strategy.long) strategy.exit("Take Profit", "Bull Flag Long", limit=calculatedTakeProfit) strategy.exit("Stop Loss", "Bull Flag Long", stop=calculatedStopLoss) label.new(bar_index, high, "Buy", color=color.green, textcolor=color.white, style=label.style_label_down)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6