The SMA Ichimoku crossover strategy is a common trading strategy. This strategy uses the gold cross and dead cross principles of moving averages, combined with the Ichimoku cloud and SMA smooth moving average, to form a relatively complete trading system. This strategy can automatically open and close stock positions.
This strategy mainly judges buying and selling stocks through the comparison between the conversion line and base line in the Ichimoku indicator and the crossovers of short-term and long-term SMA moving averages.
Specifically, the code defines the conversion line, base line, leading span 1 and leading span 2 of the Ichimoku indicator. At the same time, the long-term SMA moving average ma1 and short-term SMA moving average ma2 are defined.
When judging for buying, the conversion line needs to be lower than the base line, and the short-term moving average lower than the long-term moving average, that is, a golden cross occurs.
When judging for selling, the conversion line needs to be higher than the base line, and the short-term moving average higher than the long-term moving average, that is, a dead cross occurs.
In addition, the code also defines some auxiliary conditions, such as the closing price higher than the previous day, and using the difference and division of moving average values to judge the slope. This can determine the momentum and direction of moving average crossovers.
This strategy combines the advantages of multiple technical indicators and has the following advantages:
Ichimoku cloud itself contains trend judgment, combined with SMA moving averages can form a powerful trend judgment.
SMA moving averages itself can determine price trends and momentum. Fast MA crossing slow MA can determine trading points.
Adding closing price judgment can avoid unnecessary opening and closing of positions.
The calculation of moving average slope increases judgment on the momentum of moving average crossovers and can filter false crossovers.
Overall, this strategy has relatively accurate trend judgment, can reduce unnecessary trading, and has some room for optimization.
This strategy also has some risks:
Both Ichimoku and SMA may lag and fail to reflect price changes in time.
The combination of multiple conditions increases complexity and probability of errors.
The strategy is solely based on technical indicators and cannot judge the impact of major news.
The strategy does not set stop loss conditions, with the risk of enlarging losses.
The strategy does not consider special market conditions such as consolidation.
Improper parameter settings can also affect strategy performance.
This strategy can be optimized in the following aspects:
Set stop loss conditions to automatically stop loss when losses enlarge.
Increase judgment on major news events to avoid their impact.
Increase judgment on special market conditions such as increasing trading range or adjusting parameters.
Test and optimize parameter combinations to find optimal parameters.
Introduce machine learning algorithms for parameter optimization and market judgment.
Add momentum indicators to avoid false breakouts.
Combine more fundamentals such as changes in volume.
In summary, this SMA Ichimoku crossover strategy integrates the advantages of Ichimoku and SMA moving averages to form a relatively complete stock trading strategy. This strategy has strong ability to determine trends and can effectively capture trend opportunities. But there are also problems like lag, high complexity, lack of stop loss. This gives great room for optimizing this strategy. By setting stop loss, judging major news events, optimizing parameters and more, this strategy can be continuously improved to become a stable and reliable quantitative trading strategy.
/*backtest start: 2023-09-15 00:00:00 end: 2023-10-15 00:00:00 period: 2h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=3 // strategy("Ichimoku+SMAsmoothed", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills= true, calc_on_every_tick=true, pyramiding=0) // conversionPeriods = input(9, minval=1, title="Conversion Line Periods"), basePeriods = input(26, minval=1, title="Base Line Periods") laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Periods"), displacement = input(26, minval=1, title="Displacement") SMA1=input(title="SMA LONG",defval=21) SMA2=input(title="SMA SHORT",defval=19) p=ohlc4[1] donchian(len) => avg(lowest(len), highest(len)) conversionLine = donchian(conversionPeriods) baseLine = donchian(basePeriods) leadLine1 = avg(conversionLine, baseLine) leadLine2 = donchian(laggingSpan2Periods) //plot(conversionLine, color=#0496ff, title="Conversion Line") //plot(baseLine, color=#991515, title="Base Line") //plot(close, offset = -displacement, color=#459915, title="Lagging Span") //p1 = plot(leadLine1, offset = displacement, color=green, // title="Lead 1") //p2 = plot(leadLine2, offset = displacement, color=red, // title="Lead 2") //fill(p1, p2, color = leadLine1 > leadLine2 ? green : red) ma1=sma(p, SMA1) ma2=sma(p, SMA2) p_a = ma1*2 p_b = ma1 p_c = p_a - p_b p_d = p_c/24 p_e = ma2*2 p_f = ma2 p_g = p_e - p_f p_h = p_g/24 closelong = ohlc4<ohlc4[SMA1] and ohlc4<ohlc4[1]// and leadLine1<leadLine2 and p_h<p_d if (closelong) strategy.close("Long") closeshort = ohlc4>ohlc4[SMA1] and ohlc4>ohlc4[1]// and leadLine1>leadLine2 and p_h>p_d if (closeshort) strategy.close("Short") longCondition = ohlc4>ohlc4[1] and leadLine1>leadLine2 and p_h>p_d if (longCondition) strategy.entry("Long",strategy.long) shortCondition = ohlc4<ohlc4[1] and leadLine1<leadLine2 and p_h<p_d if (shortCondition) strategy.entry("Short",strategy.short)