
이 전략은 연속적인 K 선의 움직임을 기반으로, 현재 종료 가격과 이전 3개의 K 선의 종료 가격을 비교하여 입장을 여부를 판단한다. 연속적인 3개의 K 선이 상승할 때 다중 입장을 개시하고, 반대로 평점이다. 동시에, 이 전략은 동적 중지 손실을 사용하는 방법을 채택하고, 포지션 개시 가격과 설정된 중지 손실 비율에 따라 중지 손실을 결정한다. 이 방법은 스톱 손실을 동적으로 조정하여 위험을 더 잘 제어 할 수 있다.
이 전략은 연속적인 K 선의 움직임을 판단하여 평형 포지션을 결정하고 동시에 동적 상쇄 방법을 사용하여 위험을 제어합니다. 전략 논리는 명확하고 이해하기 쉽고 구현할 수 있으며 여러 시장과 품종에 적용됩니다. 그러나 실제 응용에서는 시장의 비 트렌드적 위험에 주의를 기울이고 상쇄 비율과 같은 매개 변수를 최적화해야합니다. 또한, 더 많은 기술 지표, 포지션 관리 등의 방법을 도입하면 전략 성능을 더욱 향상시킬 수 있습니다.
/*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")