This strategy uses the crossover of the DIF line and DEA line in the MACD indicator to generate trading signals. When the DIF line crosses above the DEA line, it generates a long signal; when the DIF line crosses below the DEA line, it generates a short signal. The backtesting results of this strategy show that on the BTCUSDT trading pair, the win rate is about 40%, and the annualized return is 1.05. However, it will cause the number of assets held to increase continuously, so it cannot be used as an independent arbitrage strategy.
The MACD golden cross and death cross strategy is a simple and easy-to-understand trading strategy that is suitable for trending markets. However, the win rate of this strategy is low, and it lacks risk management measures, so it needs further optimization and improvement. By introducing trend filters, optimizing parameters, adding risk management, and combining with other analysis methods, the performance and reliability of this strategy can be improved. Nevertheless, this strategy still cannot be used as an independent arbitrage strategy and needs to be combined with other strategies to obtain better trading results.
/*backtest start: 2024-03-01 00:00:00 end: 2024-03-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // @version=5 // @description 该策略使用 MACD DIF 线与 EDA 线产生金叉与死叉时进行入场与出场操作, 回测后发现胜率约 40%, BTCUSDT 年化利率 1.05, 同时会导致持有的资产数量不断上升, 无法作为一个独立的套利策略进行使用. strategy("MACD 金叉策略", overlay=true) fastLength = input(12, "快线长度") slowLength = input(26, "慢线长度") MACDLength = input(9, "MACD 均线长度") deltaIncreaseOver0 = input(color.green,'MACD 柱在 0 线以上增长') deltaIncreaseUnder0 = input(color.rgb(153, 230, 156),'MACD 柱在 0 线以下增长') deltaDecreaseOver0 = input(color.orange,'MACD 柱在 0 线以上下跌') deltaDecreaseUnder0 = input(color.red,'MACD 柱在 0 线以下下跌') buySellEnabled = input(true, '是否显示入场与出场信号') // @variable 做多轮数 var longRound = 0 // @variable 做空轮数 var shortRound = 0 DIF = ta.ema(close, fastLength) - ta.ema(close, slowLength) // 快慢均线差值 EDA = ta.ema(DIF, MACDLength) // DIF 线的 EMA 均线 delta = DIF - EDA // MACD 柱高度 // plot(0, 'Zero', color.black) plot(DIF,'DIF', color.yellow) plot(EDA, "EDA", color.purple) isDeltaIncreasing = delta[1] < delta isDeltaOver0 = delta > 0 deltaColor = isDeltaIncreasing ? (isDeltaOver0? deltaIncreaseOver0: deltaIncreaseUnder0) :( isDeltaOver0? deltaDecreaseOver0: deltaDecreaseUnder0) plot(delta, "Delta", deltaColor, style = plot.style_columns) isDeltaV = delta > delta[1] and delta[2] > delta[1] isDeltaA = delta < delta[1] and delta[2] < delta[1] longBuy(round) => entry = str.format("做多买入 {0}",round) // log.info(str.format("{0} {1}",entry,close)) strategy.entry(entry, strategy.long, comment=entry) longSell(round) => entry = str.format("做多买入 {0}",round) exit = str.format("做多卖出 {0}",round) // log.info(str.format("{0} {1}",exit,close)) strategy.close(entry, comment=exit) shortSell(round) => entry = str.format("做空卖出 {0}",round) // log.info(str.format("{0} {1}",entry,close)) strategy.entry(entry, strategy.short, comment= entry) shortBuy(round) => entry = str.format("做空卖出 {0}",round) exit = str.format("做空买入 {0}",round) // log.info(str.format("{0} {1}",exit,close)) strategy.close(entry, comment=exit) if (buySellEnabled) if (ta.crossunder(DIF, EDA)) longSell(longRound) if (ta.crossover(DIF, EDA)) longRound := longRound + 1 longBuy(longRound)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6