 Ichimoku w/Heikin-Ashi
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yasujiy
//@version=5
//HeikinAshi
indicator(title="IchimokuHeikinAshi", shorttitle="Ichimoku2", overlay=true)
h_close = (open + high + low + close) / 4
h_open  = float(na)
h_open := na(h_open[1]) ? (open + close) / 2 : (nz(h_open[1]) + nz(h_close[1])) / 2
h_high  = math.max(high, math.max(h_open, h_close))
h_low   = math.min(low,  math.min(h_open, h_close))
plotcandle(h_open, h_high, h_low, h_close, title= "", color = h_open < h_close ? color.white : color.blue, wickcolor=color.black)
//Ichimoku
conversionPeriods = input.int(9, minval=1, title="Conversion Line Length")
basePeriods = input.int(26, minval=1, title="Base Line Length")
laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length")
displacement = input.int(26, minval=1, title="Displacement")
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
plot(conversionLine, color=#0000FF, title="Conversion Line")
plot(baseLine, color=#FF0000, title="Base Line")
plot(close, offset = displacement - 1, color=#800080, title="Leading Lagging Span")
p1 = plot(leadLine1, offset = displacement - 1, color=#00FF00,
	 title="Leading Span A")
p2 = plot(leadLine2, offset = displacement - 1, color=#008000,
	 title="Leading Span B")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(67, 60, 71, 90))
