The Multi Timeframe MACD Strategy is a quantitative trading strategy that tracks trends using the MACD indicator across multiple time frames. This strategy generates trading signals by judging whether price trends are consistent across different periods (3 mins, 5 mins, 15 mins, 30 mins).
The core logic of this strategy is to calculate the MACD indicator crossing situation across multiple time frames (3 mins, 5 mins, 15 mins, 30 mins). Firstly, the MACD indicator is calculated on each time frame to judge the price trend (up or down) under that time frame. Then, price trends across multiple time frames are judged comprehensively:
By judging the trend across time frames, short-term market noise can be effectively filtered out, making trading signals more reliable.
This strategy has the following advantages:
This strategy also has the following risks:
Corresponding solutions:
This strategy can be further optimized in the following aspects:
The Multi Timeframe MACD Strategy utilizes the trend judgment capability of the MACD indicator to detect price movements across time frames, which can effectively filter out noise and improve signal quality. This strategy can be flexibly adapted to different products and market environments through parameter tuning and rule optimization, and has strong practicality.
/*backtest start: 2023-10-28 00:00:00 end: 2023-11-27 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 strategy("[RichG] Easy MTF Strategy", overlay=false) TF_1_time = input("3", "Timeframe 1") TF_2_time = input("5", "Timeframe 2") TF_3_time = input("15", "Timeframe 3") TF_4_time = input("30", "Timeframe 4") fastLen = input(title="Fast Length", defval=12) slowLen = input(title="Slow Length", defval=26) sigLen = input(title="Signal Length", defval=9) [macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen) width = 5 upcolor = green downcolor = red neutralcolor = blue linestyle = line TF_1 = request.security(syminfo.tickerid, TF_1_time, open) < request.security(syminfo.tickerid, TF_1_time, close) ? true:false TF_1_color = TF_1 ? upcolor:downcolor TF_2 = request.security(syminfo.tickerid, TF_2_time, open) < request.security(syminfo.tickerid, TF_2_time, close) ? true:false TF_2_color = TF_2 ? upcolor:downcolor TF_3 = request.security(syminfo.tickerid, TF_3_time, open) < request.security(syminfo.tickerid, TF_3_time, close) ? true:false TF_3_color = TF_3 ? upcolor:downcolor TF_4 = request.security(syminfo.tickerid, TF_4_time, open) < request.security(syminfo.tickerid, TF_4_time, close) ? true:false TF_4_color = TF_4 ? upcolor:downcolor TF_global = TF_1 and TF_2 and TF_3 and TF_4 TF_global_bear = TF_1 == false and TF_2 == false and TF_3 == false and TF_4 == false TF_global_color = TF_global ? green : TF_global_bear ? red : white TF_trigger_width = TF_global ? 6 : width plot(1, style=linestyle, linewidth=width, color=TF_1_color) plot(5, style=linestyle, linewidth=width, color=TF_2_color) plot(10, style=linestyle, linewidth=width, color=TF_3_color) plot(15, style=linestyle, linewidth=width, color=TF_4_color) plot(25, style=linestyle, linewidth=4, color=TF_global_color) exitCondition_Long = TF_global_bear exitCondition_Short = TF_global longCondition = TF_global if (longCondition) strategy.entry("MTF_Long", strategy.long) shortCondition = TF_global_bear if (shortCondition) strategy.entry("MTF_Short", strategy.short) strategy.close("MTF_Long", when=exitCondition_Long) strategy.close("MTF_Short", when=exitCondition_Short)