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


//@version=5
indicator(title="Ichimoku Cloud Oscillator", shorttitle="IC Oscillator", overlay=false)
conversionPeriods = input.int(30, minval=1, title="Conversion Line Length")
basePeriods = input.int(60, minval=1, title="Base Line Length")
laggingSpan2Periods = input.int(120, minval=1, title="Leading Span B Length")
displacement = input.int(60, 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)


highLine = math.max(leadLine1[displacement], leadLine2[displacement])
lowLine = math.min(leadLine1[displacement], leadLine2[displacement])


ICoscHIGH = close / highLine
ICoscLOW = close / lowLine
ICosc = ICoscLOW

if (close < highLine)
    if (close > lowLine)
        ICosc := 1
    else if (close <= lowLine)
        ICosc := ICoscLOW
else if (close >= highLine)
    ICosc := ICoscHIGH

p1 = plot(ICosc, color=color.blue, linewidth=3, title="Ichi Cloud Oscillator")
p2 = plot(ICoscLOW, color=color.green, title="Higher Bound")
p3 = plot(ICoscHIGH, color=color.red, title="Lower Bound")










