この戦略は,複数の単純な移動平均値 (SMA) とストカスティックオシレータを組み合わせたトレンドフォロー取引システムである. 価格ゾーンとトレンド識別条件を確立することによって市場のトレンドが明確に定義されたときに取引を実行する. この戦略は,市場動きに基づいてポジション管理を調整するダイナミックストップ・ロスのメカニズムを使用し,利益を保護し,早急な出口を避ける.
戦略はいくつかの主要な要素に基づいています.
この戦略は,複数の技術指標を組み合わせて包括的な取引システムを構築し,強力なトレンドフォロー機能とリスク管理メカニズムを備えています.特定の市場条件で課題に直面する場合もありますが,継続的な最適化と精製は,さまざまな市場環境で安定したパフォーマンスを維持するのに役立ちます.トレーダーはポジションサイズを制御し,適切なストップロスを設定し,ライブ取引で戦略を実行する際に市場条件に応じてパラメータを調整することをお勧めします.
/*backtest start: 2024-11-26 00:00:00 end: 2024-12-25 08:00:00 period: 4h basePeriod: 4h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Purple SMA Strategy", overlay=true) // === INPUTS === zoneLength = input.int(20, "Price Zone Length", minval=5) tickSize = input.float(1.0, "Tick Size for Hard Stop") hardStopTicks = input.int(50, "Hard Stop Loss in Ticks") // === CALCULATE ZONES === h = ta.highest(high, zoneLength) l = ta.lowest(low, zoneLength) priceRange = h - l lvl5 = h lvl4 = l + (priceRange * 0.75) // Orange line lvl3 = l + (priceRange * 0.50) // Yellow line lvl2 = l + (priceRange * 0.25) // Green line lvl1 = l // === INDICATORS === sma19 = ta.sma(close, 19) sma74 = ta.sma(close, 74) // === CANDLE COLOR CONDITIONS === isGreenCandle = close > open isRedCandle = close < open // === CONTINUOUS TREND DETECTION === isThreeGreenCandles = close > open and close[1] > open[1] and close[2] > open[2] isThreeRedCandles = close < open and close[1] < open[1] and close[2] < open[2] var bool inGreenTrend = false var bool inRedTrend = false // Update trends if isThreeGreenCandles inGreenTrend := true inRedTrend := false if isThreeRedCandles inRedTrend := true inGreenTrend := false if (inGreenTrend and isRedCandle) or (inRedTrend and isGreenCandle) inGreenTrend := false inRedTrend := false // === STOCHASTIC CONDITIONS === k = ta.stoch(close, high, low, 60) d = ta.sma(k, 10) isOverbought = d >= 80 isOversold = d <= 20 stochUp = d > d[1] stochDown = d < d[1] // === SMA COLOR LOGIC === sma19Color = if isOverbought and stochUp color.green else if isOverbought and stochDown color.red else if isOversold and stochUp color.green else if isOversold and stochDown color.red else if stochUp color.blue else if stochDown color.purple else color.gray sma74Color = sma74 < sma19 ? color.green : color.red // === CROSSING CONDITIONS === crossUpSMA = ta.crossover(close, sma74) crossDownSMA = ta.crossunder(close, sma74) // === ENTRY CONDITIONS === buyCondition = crossUpSMA and close > lvl4 sellCondition = crossDownSMA and close < lvl2 // === POSITION MANAGEMENT === var float stopLevel = na var bool xMode = false // Entry and Stop Loss if buyCondition strategy.entry(id="Long", direction=strategy.long) stopLevel := close - (hardStopTicks * tickSize) xMode := false if sellCondition strategy.entry(id="Short", direction=strategy.short) stopLevel := close + (hardStopTicks * tickSize) xMode := false // Update stops based on X's if strategy.position_size != 0 and (inGreenTrend or inRedTrend) xMode := true if strategy.position_size > 0 // Long position stopLevel := low else // Short position stopLevel := high // Exit logic if strategy.position_size > 0 // Long position if low <= stopLevel strategy.close(id="Long") else if xMode and not (inGreenTrend or inRedTrend) strategy.close(id="Long") if strategy.position_size < 0 // Short position if high >= stopLevel strategy.close(id="Short") else if xMode and not (inGreenTrend or inRedTrend) strategy.close(id="Short") // === PLOTTING === plot(sma19, "SMA 19", color=sma19Color, linewidth=2) plot(sma74, "SMA 74", color=sma74Color, linewidth=2) plot(lvl5, "Upper Zone Top", color=color.red, linewidth=2) plot(lvl4, "Upper Zone Bottom", color=color.orange, linewidth=2) plot(lvl3, "Middle Line", color=color.yellow, linewidth=2) plot(lvl2, "Lower Zone Top", color=color.green, linewidth=2) plot(lvl1, "Lower Zone Bottom", color=color.blue, linewidth=2) // Plot X signals plotshape(inGreenTrend, title="Bullish Line", style=shape.xcross, location=location.belowbar, color=color.white, size=size.tiny) plotshape(inRedTrend, title="Bearish Line", style=shape.xcross, location=location.abovebar, color=color.white, size=size.tiny) // Zone fills var p1 = plot(lvl5, display=display.none) var p2 = plot(lvl4, display=display.none) var p3 = plot(lvl2, display=display.none) var p4 = plot(lvl1, display=display.none) fill(p1, p2, color=color.new(color.red, 90)) fill(p3, p4, color=color.new(color.green, 90)) // Plot entry signals plotshape(buyCondition, title="Buy", style=shape.square, location=location.belowbar, color=color.new(color.blue, 20), size=size.tiny, text="BUY", textcolor=color.blue) plotshape(sellCondition, title="Sell", style=shape.square, location=location.abovebar, color=color.new(color.red, 20), size=size.tiny, text="SELL", textcolor=color.red)