0bps

Strategy vault / Mean reversion

Ichimoku and MACD Trend Reversal Trading Strategy

This strategy combines Ichimoku and MACD indicators, entering trades after confirming trend reversal. It belongs to trend reversal trading strategies.

Author
ChaoZhang
Complexity
Intermediate · 95 lines
Parameters
16
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

Overview

This strategy combines Ichimoku and MACD indicators, entering trades after confirming trend reversal. It belongs to trend reversal trading strategies.

Strategy Logic

  1. Calculate Ichimoku Tenkan line to gauge trend direction. Price above it indicates uptrend, and below downtrend.

  2. MACD death cross generates sell signal in uptrend; golden cross buy signal in downtrend.

  3. Combine Ichimoku trend bias and MACD reversal signals to trade trend reversals.

  4. Option to set trading hour control, like no trading at night or weekends, to avoid risks associated with certain times.

  5. Employ proper stop loss and take profit for profit locking and risk control.

Advantages

  1. Ichimoku intuitively displays trends and support/resistance levels.

  2. MACD sensitively captures trend reversals.

  3. Combining trend bias and reversal improves signal quality.

  4. Customizable trading hours avoid risks around major news events.

  5. Stop loss and take profit effectively manages capital risks.

Risks

  1. Ichimoku and MACD may generate false signals.

  2. Reversal strength unknown, risks of chasing tops and bottoms.

  3. Trading hour control may miss some opportunities.

  4. Improper stop loss and take profit settings lead to premature exit.

  5. Parameter optimization may lead to overfitting.

Enhancement

  1. Test Ichimoku and MACD parameters for optimal combinations.

  2. Add other indicators to confirm trading signals.

  3. Optimize stops and profits to balance risks and returns.

  4. Evaluate necessity of trading hour control and relax if appropriate.

  5. Incorporate trend filter to avoid losses from reversal trades.

  6. Research ways to gauge reversal strength and potential pullback height.

Conclusion

This strategy combines Ichimoku's trend bias and MACD's reversal signals to trade after trend reversals. Further optimization and enhancements can reduce signal errors and improve stability and efficiency as a robust trend reversal system.

Parameters

NameDefaultWhat it controls
v_input_19IchimokuTenkanPeriod
v_input_2190IchimokuKijunPeriod
v_input_352IchimokuSenkouPeriod
v_input_43MACDMainFast
v_input_510MACDMainSlow
v_input_69MACDMainSmooth
v_input_72ExitAfterBars
v_input_8135ProfitTarget
v_input_970StopLoss
v_input_10trueDontTradeOnWeekends
v_input_11trueExitAtEndOfDay
v_input_1223DayExitTimeHour
v_input_134DayExitTimeMinute
v_input_14trueExitOnFriday
v_input_1520FridayExitTimeHour
v_input_1640FridayExitTimeMinute

Source Pine Script

/*backtest
start: 2022-09-13 00:00:00
end: 2023-09-19 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Revazi

//@version=5
strategy("The Impeccable by zyberal", overlay = true)

// Inputs {
// Strategy variables
IchimokuTenkanPeriod = input(9)
IchimokuKijunPeriod = input(190)
IchimokuSenkouPeriod = input(52)
MACDMainFast = input(3)
MACDMainSlow = input(10)
MACDMainSmooth = input(9)
ExitAfterBars = input(2)
ProfitTarget = input(135)
StopLoss = input(70)

// Trading Options
DontTradeOnWeekends = input(true)
ExitAtEndOfDay = input(true)
DayExitTimeHour   = input(23)
DayExitTimeMinute = input(04)

ExitOnFriday = input(true)
FridayExitTimeHour   = input(20)
FridayExitTimeMinute = input(40)

// }



// TRADING OPTIONS LOGIC {
OpenOrdersAllowed = true

// Dont trade on weekends {
if DontTradeOnWeekends
    if dayofweek == dayofweek.saturday or
       dayofweek == dayofweek.sunday
        OpenOrdersAllowed := false
// }

// Exit on close (end of day) {
if ExitAtEndOfDay
    if timeframe.isintraday and
       time >= timestamp(year(timenow), month(timenow), dayofmonth(timenow), DayExitTimeHour, DayExitTimeMinute)
        OpenOrdersAllowed := false
// }

// Exit on Friday {
if ExitOnFriday
    if timeframe.isintraday and
       time >= timestamp(year(timenow), month(timenow), dayofmonth(timenow), FridayExitTimeHour, FridayExitTimeMinute)
        OpenOrdersAllowed := false
// }


// Rule: Trading signals {
openW3 = request.security(syminfo.tickerid, "W", open)[3]

middleDonchian(Length) => math.avg(ta.highest(Length), ta.lowest(Length))
Tenkan = middleDonchian(IchimokuTenkanPeriod)[2]

[macdLine, signalLine, _] = ta.macd(close, MACDMainFast, MACDMainSlow, MACDMainSmooth)

LongEntrySignal = openW3 > Tenkan and ta.crossunder(macdLine, signalLine)[3] //macdLine[3] < signalLine[3]
ShortEntrySignal = openW3 < Tenkan and ta.crossover(macdLine, signalLine)[3] //macdLine[3] > signalLine[3]
// }



// Calculate conditions {
IsFlat() => strategy.position_size == 0
IsLong() => strategy.position_size > 0
IsShort() => strategy.position_size < 0

longCondition  = OpenOrdersAllowed and not IsLong() and LongEntrySignal
shortCondition = OpenOrdersAllowed and not IsShort() and ShortEntrySignal

// }

// Open positions based on conditions {
strategy.order(id = "buy", direction = strategy.long, qty = 1, when = longCondition)
strategy.order(id = "sell", direction = strategy.short, qty = 1, when = shortCondition)
// }

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-20. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Ichimoku-and-MACD-Trend-Reversal-Trading-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open