Davood Kumo
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mr_Amiiin_n

//@version=5
indicator('Davood Kumo', overlay=true)

//draw ichimoku cloud
conversionPeriods = input.int(9, minval=1, title='Conversion Line Length', group="Ichimoku")
basePeriods = input.int(26, minval=1, title='Base Line Length', group="Ichimoku")
laggingSpan2Periods = input.int(52, minval=1, title='Leading Span B Length', group="Ichimoku")
displacement = input.int(26, minval=1, title='Displacement', group="Ichimoku")
donchian(len) =>
    math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)

p1 = plot(leadLine1, offset=displacement - 1, color=color.new(#A5D6A7, 0), title='Leading Span A')
p2 = plot(leadLine2, offset=displacement - 1, color=color.new(#EF9A9A, 0), title='Leading Span B')
fill(p1, p2, color=leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))

//get date period
startDate = input.time(title='Start Time : ', defval=timestamp('1 aug 2022 00:00'), tooltip='first time', group="Date & Time")
endDate = input.time(title='End Time : ', defval=timestamp('1 Sep 2022 00:00'), tooltip='last time', group="Date & Time")
res = input.timeframe(title='Time Frame : ', defval='D', group="Date & Time")

//counting the period range
timeDispute = endDate - startDate
int t = 0
int divide = 0
float highst = 0.00
float lowst = 0.00
float hCloud = 0.00
float lCloud = 0.00


htp1 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.green, style=line.style_dashed)
htp2 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.green, style=line.style_dashed)
ltp1 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.red, style=line.style_dashed)
ltp2 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.red, style=line.style_dashed)


if res == '15'
    divide := timeDispute / 900000
    t := math.floor((timenow - startDate) / 900000)
    highst := high[t]
    lowst := low[t]
    hCloud := leadLine1[t + displacement - 1]
    lCloud := leadLine2[t + displacement - 1]

    for i = 0 to divide by 1
        if highst < high[t]
            highst := high[t]
            highst
        if lowst > low[t]
            lowst := low[t]
            lowst
        if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
            if hCloud < leadLine1[t + displacement - 1]
                hCloud := leadLine1[t + displacement - 1]
                hCloud
            if lCloud > leadLine2[t + displacement - 1]
                lCloud := leadLine2[t + displacement - 1]
                lCloud
        if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
            if hCloud < leadLine2[t + displacement - 1]
                hCloud := leadLine2[t + displacement - 1]
                hCloud
            if lCloud > leadLine1[t + displacement - 1]
                lCloud := leadLine1[t + displacement - 1]
                lCloud
        t -= 1
        t


if res == '60'
    divide := timeDispute / 3600000
    t := math.floor((timenow - startDate) / 3600000)
    highst := high[t]
    lowst := low[t]
    hCloud := leadLine1[t + displacement - 1]
    lCloud := leadLine2[t + displacement - 1]

    for i = 0 to divide by 1
        if highst < high[t]
            highst := high[t]
            highst
        if lowst > low[t]
            lowst := low[t]
            lowst
        if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
            if hCloud < leadLine1[t + displacement - 1]
                hCloud := leadLine1[t + displacement - 1]
                hCloud
            if lCloud > leadLine2[t + displacement - 1]
                lCloud := leadLine2[t + displacement - 1]
                lCloud
        if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
            if hCloud < leadLine2[t + displacement - 1]
                hCloud := leadLine2[t + displacement - 1]
                hCloud
            if lCloud > leadLine1[t + displacement - 1]
                lCloud := leadLine1[t + displacement - 1]
                lCloud
        t -= 1
        t



if res == '240'
    divide := timeDispute / 14400000
    t := math.floor((timenow - startDate) / 14400000)

    highst := high[t]
    lowst := low[t]
    hCloud := leadLine1[t + displacement - 1]
    lCloud := leadLine2[t + displacement - 1]

    for i = 0 to divide by 1
        if highst < high[t]
            highst := high[t]
            highst
        if lowst > low[t]
            lowst := low[t]
            lowst
        if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
            if hCloud < leadLine1[t + displacement - 1]
                hCloud := leadLine1[t + displacement - 1]
                hCloud
            if lCloud > leadLine2[t + displacement - 1]
                lCloud := leadLine2[t + displacement - 1]
                lCloud
        if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
            if hCloud < leadLine2[t + displacement - 1]
                hCloud := leadLine2[t + displacement - 1]
                hCloud
            if lCloud > leadLine1[t + displacement - 1]
                lCloud := leadLine1[t + displacement - 1]
                lCloud
        t -= 1
        t



if res == '1D'
    divide := timeDispute / 86400000
    t := math.floor((timenow - startDate) / 86400000)

    highst := high[t]
    lowst := low[t]
    hCloud := leadLine1[t + displacement - 1]
    lCloud := leadLine2[t + displacement - 1]

    for i = 0 to divide by 1
        if highst < high[t]
            highst := high[t]
            highst
        if lowst > low[t]
            lowst := low[t]
            lowst
        if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
            if hCloud < leadLine1[t + displacement - 1]
                hCloud := leadLine1[t + displacement - 1]
                hCloud
            if lCloud > leadLine2[t + displacement - 1]
                lCloud := leadLine2[t + displacement - 1]
                lCloud
        if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
            if hCloud < leadLine2[t + displacement - 1]
                hCloud := leadLine2[t + displacement - 1]
                hCloud
            if lCloud > leadLine1[t + displacement - 1]
                lCloud := leadLine1[t + displacement - 1]
                lCloud
        t -= 1
        t


if res == '1W'
    divide := timeDispute / 604800000
    t := math.floor((timenow - startDate) / 604800000)

    highst := high[t]
    lowst := low[t]
    hCloud := leadLine1[t + displacement - 1]
    lCloud := leadLine2[t + displacement - 1]

    for i = 0 to divide by 1
        if highst < high[t]
            highst := high[t]
            highst
        if lowst > low[t]
            lowst := low[t]
            lowst
        if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
            if hCloud < leadLine1[t + displacement - 1]
                hCloud := leadLine1[t + displacement - 1]
                hCloud
            if lCloud > leadLine2[t + displacement - 1]
                lCloud := leadLine2[t + displacement - 1]
                lCloud
        if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
            if hCloud < leadLine2[t + displacement - 1]
                hCloud := leadLine2[t + displacement - 1]
                hCloud
            if lCloud > leadLine1[t + displacement - 1]
                lCloud := leadLine1[t + displacement - 1]
                lCloud
        t -= 1
        t


cloudArea = (hCloud - lCloud) / 2
highTP1 = highst + cloudArea
highTP2 = highst + cloudArea * 2
lowTP1 = lowst - cloudArea
lowTP2 = lowst - cloudArea * 2

plot(cloudArea, title='cloud area', color=color.new(color.red, 0))


line.set_x1(htp1, startDate)
line.set_y1(htp1, highTP1)
line.set_x2(htp1, endDate)
line.set_y2(htp1, highTP1)
line.set_extend(htp1, extend.right)
line.delete(htp1[1])
t1=label.new(bar_index, highTP1, "First Long Target", textcolor=color.green, style=label.style_none)
label.delete(t1[1])

line.set_x1(htp2, startDate)
line.set_y1(htp2, highTP2)
line.set_x2(htp2, endDate)
line.set_y2(htp2, highTP2)
line.set_extend(htp2, extend.right)
line.delete(htp2[1])
t2=label.new(bar_index, highTP2, "Second Long Target", textcolor=color.green, style=label.style_none)
label.delete(t2[1])


line.set_x1(ltp1, startDate)
line.set_y1(ltp1, lowTP1)
line.set_x2(ltp1, endDate)
line.set_y2(ltp1, lowTP1)
line.set_extend(ltp1, extend.right)
line.delete(ltp1[1])
t3=label.new(bar_index, lowTP1, "First Short Target", textcolor=color.red, style=label.style_none)
label.delete(t3[1])


line.set_x1(ltp2, startDate)
line.set_y1(ltp2, lowTP2)
line.set_x2(ltp2, endDate)
line.set_y2(ltp2, lowTP2)
line.set_extend(ltp2, extend.right)
line.delete(ltp2[1])
t4=label.new(bar_index, lowTP2, "Second Short Target", textcolor=color.red, style=label.style_none)
label.delete(t4[1])











