Ichimoku Kinko Hyo: Basic Strategy TradingView Pinescript codes

The Ichimoku Kinko Hyo indicator was originally developed by a Japanese newspaper writer to combine various technical strategies into a single indicator that could be easily implemented and interpreted. In Japanese, “ichimoku” translates to “one look,” meaning traders only have to take one look at the chart to determine momentum, support, and resistance.

Ichimoku may look very complicated to novice traders that haven’t seen it before, but the complexity quickly disappears with an understanding of what the various lines mean and why they are used.

The Ichimoku indicator is best used in conjunction with other forms of technical analysis despite its goal of being an all-in-one indicator.

Kijun Sen (blue line): Also called the standard line or base line, this is calculated by averaging the highest high and the lowest low for the past 26 periods.

Tenkan Sen (red line): This is also known as the turning line and is derived by averaging the highest high and the lowest low for the past nine periods.

Chikou Span (green line): This is called the lagging line. It is today’s closing price plotted 26 periods behind.

Senkou Span (orange lines): The first Senkou line is calculated by averaging the Tenkan Sen and the Kijun Sen and plotted 26 periods ahead.

strategy("Ichimoku Kinko Hyo: Basic Strategy", overlay=true)

//Inputs
ts_bars = input(9, minval=1, title="Tenkan-Sen Bars")
ks_bars = input(26, minval=1, title="Kijun-Sen Bars")
ssb_bars = input(52, minval=1, title="Senkou-Span B Bars")
cs_offset = input(26, minval=1, title="Chikou-Span Offset")
ss_offset = input(26, minval=1, title="Senkou-Span Offset")
long_entry = input(true, title="Long Entry")
short_entry = input(true, title="Short Entry")

middle(len) => avg(lowest(len), highest(len))

// Ichimoku Components
tenkan = middle(ts_bars)
kijun = middle(ks_bars)
senkouA = avg(tenkan, kijun)
senkouB = middle(ssb_bars)

// Plot Ichimoku Kinko Hyo
plot(tenkan, color=#0496ff, title="Tenkan-Sen")
plot(kijun, color=#991515, title="Kijun-Sen")
plot(close, offset=-cs_offset+1, color=#459915, title="Chikou-Span")
sa=plot(senkouA, offset=ss_offset-1, color=green, title="Senkou-Span A")
sb=plot(senkouB, offset=ss_offset-1, color=red, title="Senkou-Span B")
fill(sa, sb, color = senkouA > senkouB ? green : red, title="Cloud color")

ss_high = max(senkouA[ss_offset-1], senkouB[ss_offset-1])
ss_low = min(senkouA[ss_offset-1], senkouB[ss_offset-1])

// Entry/Exit Signals
tk_cross_bull = tenkan > kijun
tk_cross_bear = tenkan < kijun
cs_cross_bull = mom(close, cs_offset-1) > 0
cs_cross_bear = mom(close, cs_offset-1) < 0
price_above_kumo = close > ss_high
price_below_kumo = close < ss_low

bullish = tk_cross_bull and cs_cross_bull and price_above_kumo
bearish = tk_cross_bear and cs_cross_bear and price_below_kumo

strategy.entry("Long", strategy.long, when=bullish and long_entry)
strategy.entry("Short", strategy.short, when=bearish and short_entry)

strategy.close("Long", when=bearish and not short_entry)
strategy.close("Short", when=bullish and not long_entry)

Disclaimer:

All the pine script’s posted in this section are for learning purpose. Website does not necessarily own these pine script’s and we don’t have any intellectual property rights on them. We might copy useful pine script’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at tradingwithpawan@gmail.com