This strategy is based on the trend of continuous candles. It determines whether to enter a position by comparing the current closing price with the closing prices of the previous three candles. When three consecutive candles are rising, it enters a long position, otherwise it closes the position. At the same time, this strategy adopts a dynamic stop loss method, where the stop loss level is determined based on the entry price and a set stop loss percentage. This method allows for dynamic adjustment of the stop loss level, better controlling risk.
This strategy makes decisions on opening and closing positions based on the trend judgment of continuous candles, while adopting a dynamic stop loss method to control risk. The strategy logic is clear, easy to understand and implement, and is applicable to various markets and instruments. However, in practical application, attention needs to be paid to the risk of non-trending markets, and parameters such as stop loss percentage need to be optimized. In addition, introducing more technical indicators, position management, and other methods can further improve strategy performance.
/*backtest start: 2023-05-28 00:00:00 end: 2024-06-02 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("4 Candle Entry and Exit Strategy", overlay=true) // Define the stop loss percentage stopLossPercent = input.float(11, title="Stop Loss Percentage", minval=0.1) / 100 // Identify if the previous 3 candles are consecutively higher longCondition = close[3] > close[4] and close[2] > close[3] and close[1] > close[2] // Identify if the previous 3 candles are consecutively lower exitCondition = close[3] < close[4] and close[2] < close[3] and close[1] < close[2] // Initialize the entry price and stop loss variables var float entryPrice = na var float stopLoss = na // Update the entry price and stop loss if the long condition is met if (longCondition) entryPrice := close[1] stopLoss := entryPrice * (1 - stopLossPercent) // Enter the long position at the open of the 4th candle if (longCondition) strategy.entry("Long", strategy.long, qty=1) // Exit the position if exit condition is met or stop loss is hit if (exitCondition or (strategy.position_size > 0 and low <= stopLoss)) strategy.close("Long") // Optional: Plot the entry and exit signals on the chart plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY") plotshape(series=exitCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")