Strategi ini adalah sistem perdagangan yang komprehensif yang menggabungkan beberapa penunjuk teknikal utama, termasuk sistem Sederhana Moving Average (SMA) berganda, Perbezaan Convergensi Moving Average (MACD), Indeks Kekuatan Relatif (RSI), dan analisis tahap rintangan.
Strategi ini menggunakan purata bergerak sederhana jangka pendek (10 hari) dan jangka panjang (30 hari) sebagai sistem isyarat utama. Isyarat beli dihasilkan apabila SMA jangka pendek melintasi di atas SMA jangka panjang, dan MACD menunjukkan momentum kenaikan (garis MACD di atas garis isyarat). Syarat jual menggabungkan analisis tahap rintangan, mencetuskan penutupan kedudukan apabila harga mencapai titik tertinggi dalam 20 tempoh terakhir dan MACD menunjukkan isyarat penurunan. Di samping itu, penunjuk RSI berfungsi sebagai penapis sentimen untuk pengurusan kedudukan: keluar awal pada kerugian apabila RSI melebihi 70, dan memegang kedudukan pada keuntungan apabila RSI di bawah 30.
Strategi ini membina sistem perdagangan yang lengkap dengan menggabungkan beberapa penunjuk teknikal klasik. Kekuatannya terletak pada mekanisme pengesahan isyarat berbilang dan sistem kawalan risiko yang komprehensif, walaupun keadaan pasaran harus dipantau. Melalui arah pengoptimuman yang dicadangkan, kestabilan dan daya adaptasi strategi dapat ditingkatkan lagi. Dalam perdagangan langsung, pelabur dinasihatkan untuk menyesuaikan parameter mengikut pilihan risiko dan persekitaran pasaran mereka sambil mengekalkan perhatian kepada asas pasaran.
/*backtest start: 2019-12-23 08:00:00 end: 2024-11-11 00:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("XAUUSD SMA with MACD & Market Sentiment (Enhanced RR)", overlay=true) // Input parameters for moving averages shortSMA_length = input.int(10, title="Short SMA Length", minval=1) longSMA_length = input.int(30, title="Long SMA Length", minval=1) // MACD settings [macdLine, signalLine, _] = ta.macd(close, 12, 26, 9) // Lookback period for identifying major resistance (swing highs) resistance_lookback = input.int(20, title="Resistance Lookback Period", tooltip="Lookback period for identifying major resistance") // Calculate significant resistance (local swing highs over the lookback period) major_resistance = ta.highest(close, resistance_lookback) // Calculate SMAs shortSMA = ta.sma(close, shortSMA_length) longSMA = ta.sma(close, longSMA_length) // RSI for market sentiment rsiLength = input.int(14, title="RSI Length", minval=1) rsiOverbought = input.int(70, title="RSI Overbought Level", minval=50, maxval=100) rsiOversold = input.int(30, title="RSI Oversold Level", minval=0, maxval=50) rsi = ta.rsi(close, rsiLength) // Define buy condition based on SMA and MACD buyCondition = ta.crossover(shortSMA, longSMA) and macdLine > signalLine // Define sell condition: only sell if price is at or above the identified major resistance sellCondition = close >= major_resistance and macdLine < signalLine // Define sentiment-based exit conditions closeEarlyCondition = strategy.position_size < 0 and rsi > rsiOverbought // Close losing trade early if RSI is overbought holdWinningCondition = strategy.position_size > 0 and rsi < rsiOversold // Hold winning trade if RSI is oversold // Execute strategy: Enter long position when buy conditions are met if (buyCondition) strategy.entry("Buy", strategy.long) // Close the position when the sell condition is met (price at resistance) if (sellCondition and not holdWinningCondition) strategy.close("Buy") // Close losing trades early if sentiment is against us if (closeEarlyCondition) strategy.close("Buy") // Visual cues for buy and sell signals plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY") plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL") // Add alert for buy condition alertcondition(buyCondition, title="Buy Signal Activated", message="Buy signal activated: Short SMA has crossed above Long SMA and MACD is bullish.") // Add alert for sell condition to notify when price hits major resistance alertcondition(sellCondition, title="Sell at Major Resistance", message="Sell triggered at major resistance level.") // Add alert for early close condition (for losing trades) alertcondition(closeEarlyCondition, title="Close Losing Trade Early", message="Sentiment is against your position, close trade.") // Add alert for holding winning condition (optional) alertcondition(holdWinningCondition, title="Hold Winning Trade", message="RSI indicates oversold conditions, holding winning trade.")