この戦略は,移動平均値 (MA) の傾斜とMAに対する価格の相対位置に基づいて取引決定を行う.MA傾斜が最小傾斜の
この戦略は,移動平均の傾斜と移動平均に対する価格の相対的位置に基づいてトレンドを決定する.トレーリングストップ損失と条件付き再入行メカニズムを使用して取引を管理する.戦略の強みは,トレンドフォロー能力,ダイナミックストップ損失保護,再入行機会の把握にある.しかし,この戦略にはパラメータ敏感性,トレンド認識エラー,ストップ損失頻度,再入行リスクなどの潜在的な欠点もあります.最適化方向性には,トレンド認識,ストップ損失方法,再入行条件,ポジションサイズを精製することが含まれます.戦略を実践する際には,特定の市場特性と取引スタイルに基づいて慎重に評価し調整することが重要です.
/*backtest start: 2024-05-01 00:00:00 end: 2024-05-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("MA Incline Strategy with Trailing Stop-Loss and Conditional Re-Entry", overlay=true, calc_on_every_tick=true) // Input parameters windowSize = input.int(10, title="Window Size") maLength = input.int(150, title="Moving Average Length") minSlope = input.float(0.001, title="Minimum Slope") trailingStopPercentage = input.float(2.8, title="Trailing Stop Percentage (%)") / 100 reEntryPercentage = input.float(4.2, title="Re-Entry Percentage Above MA (%)") / 100 // Calculate the moving average ma = ta.sma(close, maLength) // Calculate the slope of the moving average over the window size previousMa = ta.sma(close[windowSize], maLength) slopeMa = (ma - previousMa) / windowSize // Check conditions isAboveMinSlope = slopeMa > minSlope isAboveMa = close > ma // Variables to track stop loss and re-entry condition var bool stopLossOccurred = false var float trailStopPrice = na // Buy condition buyCondition = isAboveMinSlope and isAboveMa and ((not stopLossOccurred) or (stopLossOccurred and low < ma * (1 + reEntryPercentage))) // Execute strategy if (buyCondition and strategy.opentrades == 0) if (stopLossOccurred and close < ma * (1 + reEntryPercentage)) strategy.entry("Long", strategy.long) stopLossOccurred := false else if (not stopLossOccurred) strategy.entry("Long", strategy.long) // Trailing stop-loss if (strategy.opentrades == 1) // Calculate the trailing stop price trailStopPrice := close * (1 - trailingStopPercentage) // Use the built-in strategy.exit function with the trailing stop strategy.exit("Trail Stop", "Long", stop=close * (1 - trailingStopPercentage)) // Exit condition sellCondition = ta.crossunder(close, ma) if (sellCondition and strategy.opentrades == 1) strategy.close("Long") // Check if stop loss occurred if (strategy.closedtrades > 0) lastExitPrice = strategy.closedtrades.exit_price(strategy.closedtrades - 1) if (not na(trailStopPrice) and lastExitPrice <= trailStopPrice) stopLossOccurred := true // Reset stop loss flag if the price crosses below the MA if (ta.crossunder(close, ma)) stopLossOccurred := false