Strategi ini menggabungkan penunjuk MACD dengan purata bergerak, pergi lama apabila kedua-duanya memberikan isyarat sejajar.
Logikanya ialah:
Mengira MACD FAST, biasanya EMA 12 hari
Mengira MACD perlahan, biasanya EMA 26 hari
MACD adalah pantas tolak perlahan
Garis isyarat biasanya MA 9 hari MACD
Mengira MA 9 hari dan 26 hari
Pertimbangkan panjang apabila MACD melintasi di atas garis isyarat
Pergi panjang apabila MA 9 hari melintasi MA 26 hari
Tutup panjang apabila MACD melintasi di bawah garis isyarat dan MA 9 hari melintasi di bawah MA 26 hari
Strategi ini memanfaatkan penanda perbandingan overbought-oversold MACD
Pengadil MACD terlalu banyak beli/terlalu banyak jual, MA menentukan trend
Gabungan menyediakan peluang jangka panjang yang tinggi
Peraturan yang jelas mudah dilaksanakan
Memerlukan pengoptimuman untuk menentukan parameter terbaik
LANG-hanya tidak dapat menggunakan peluang jangka pendek
Perdagangan dengan trend boleh memperbesar kerugian
Strategi ini menggunakan kekuatan MACD dan MA
/*backtest start: 2023-09-06 00:00:00 end: 2023-09-13 00:00:00 period: 30m basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy("MACD Cross+MA", overlay=true) //@version=4 // Getting inputs fast_length = input(title="Fast Length", type=input.integer, defval=12) slow_length = input(title="Slow Length", type=input.integer, defval=26) src = input(title="Source", type=input.source, defval=close) signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9) sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false) sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false) // === INPUT BACKTEST RANGE === FromYear = input(defval = 2019, title = "From Year", minval = 2009) FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12) FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31) ToYear = input(defval = 9999, title = "To Year", minval = 2009) ToMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12) ToDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31) // === FUNCTION EXAMPLE === start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window window() => time >= start and time <= finish ? true : false // create function "within window of time" // Calculating fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length) slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length) macd = fast_ma - slow_ma signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length) hist = macd - signal //plot plot(sma(close,9),color=color.red) plot(sma(close,26),color=color.green) //Condition BMacdcondition= (macd>signal) SMacdcondition= (macd<signal) longCondition = crossover(sma(close, 9), sma(close, 26)) shortCondition = crossunder(sma(close, 9), sma(close, 26)) //entry if (BMacdcondition) and window() (longCondition) strategy.entry("LONG", strategy.long) if (shortCondition) and window() (SMacdcondition) strategy.close("LONG", qty_percent=100 , comment="หนีตาย")