This strategy implements simple trend-following trading based on the ichimoku cloud indicator on daily charts. It generates buy and sell signals by calculating the conversion line, base line, leading span 1, leading span 2, and comparing the closing price’s position relative to the cloud. When the closing price is above the cloud, it is considered an upward trend and a buy signal is generated. When the closing price is below the cloud, it is considered a downward trend and a sell signal is generated.
The strategy mainly calculates the five lines of the ichimoku cloud indicator based on the following formulas:
Conversion Line: 9-period average of the highest high and lowest low
Base Line: 26-period average of the highest high and lowest low
Leading Span 1: average of the conversion line and base line
Leading Span 2: 52-period average of the highest high and lowest low
Lagging Span: closing price plotted 26 periods behind
When the closing price is above the cloud, it is considered an upward trend and a buy signal is generated. When the closing price is below the cloud, it is considered a downward trend and a sell signal is generated.
Specifically, the strategy implements this logic through the following steps:
Calculate the conversion line, base line, leading span 1, and leading span 2
Plot the lagging span of the closing price 26 periods behind
Check if the closing price is above the cloud (leading span 1 and 2), generate buy signal if true
Check if the closing price is below the cloud, generate sell signal if true
Enter trades on buy/sell signals based on strategy settings
The main advantages of this strategy are:
Using the ichimoku cloud can effectively identify trends and generate signals along the trend direction, avoiding unnecessary trades in range-bound markets.
The calculation parameters are optimized for daily trading.
Using both leading span 1 and 2 combines multiple signals to filter out false signals.
The lagging span delay helps reduce risk of immediate pullback after cloud breakout.
Simple and clear logic, easy to understand and implement.
No other indicators needed, complete trend following system.
There are some risks to consider:
The cloud may fail in certain market conditions, generating incorrect signals.
If parameters are not adapted to changing market dynamics, it weakens the system.
The fixed lagging span delay may miss some opportunities.
Still cannot completely avoid whipsaws.
There is some time lag, unable to capture quick reversals.
Cannot differentiate major trends vs shorter corrections, may cause losses.
Some ways to improve the strategy:
Optimize parameters like conversion line for different market conditions.
Add trend filtering indicators to confirm strength and direction.
Implement stop loss and take profit to control loss per trade.
Only take cloud breakout signals with high volume.
Use different parameter sets based on market regime.
Add machine learning to auto-optimize parameters.
Consider dynamic lagging span instead of fixed delay.
Overall, this ichimoku cloud strategy implements basic trend following rules, although improvements can be made. The core logic is sound, parameters optimized, good baseline algo trading strategy. With further cloud parameter enhancement, adding filters and risk controls, it can become a very practical quantitative trading system.
/*backtest start: 2023-09-30 00:00:00 end: 2023-10-07 00:00:00 period: 15m basePeriod: 5m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy(title="Ichimoku Cloud", shorttitle="Ichimoku", overlay=true, commission_type=strategy.commission.percent,commission_value=0.075, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100) 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=0, title="Displacement") 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=color.green, title="Lead 1") p2 = plot(leadLine2, offset = displacement, color=color.red, title="Lead 2") fill(p1, p2, color = leadLine1 > leadLine2 ? color.green : color.red) buy = close > leadLine1[26] and close > leadLine2[26] sell = close < leadLine1[26] and close < leadLine2[26] strategy.entry("Buy", strategy.long, when = buy) strategy.entry("Sell", strategy.short, when = sell)