
この戦略は,連続した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")