Untitled

 avatar
unknown
plain_text
a month ago
3.9 kB
6
Indexable

//@version=5
indicator(title="CM_RSI_EMA", shorttitle="CM_RSI_EMA_", overlay=false)


src = close
len = input.int(20, minval=1, title="RSI Length")
len2 = input.int(10, minval=1, title="EMA of RSI Length")

up = ta.rma(math.max(ta.change(src), 0), len)
down = ta.rma(-math.min(ta.change(src), 0), len)

rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
emaRSI = ta.ema(rsi, len2)

// Count Logic
var int HG = na
var int LW = na
var float last_high = na
var float last_low = na
var color last_color = na

// Define Conditions
up_condition = rsi > emaRSI
down_condition = rsi < emaRSI

// Reset Counters and Track Changes
if (na(last_color) or (up_condition and last_color != color.green) or (down_condition and last_color != color.red))
    HG := 1
    LW := 1
    last_high := high
    last_low := low
    last_color := up_condition ? color.green : color.red
else
    // Update Counters Based on High and Low
    if (up_condition)
        if (high > last_high)
            HG := (HG < 9) ? (HG + 1) : 1
            last_high := high
    if (down_condition)
        if (low < last_low)
            LW := (LW < 9) ? (LW + 1) : 1
            last_low := low


//plot(x, color=color.blue, title="çizgi")

// Plot High and Low Counts
plotshape(series=HG == 1 and HG[1] != 1, style=shape.triangledown, color=color.gray, text="1", textcolor=color.gray, location=location.abovebar)
plotshape(series=HG == 2 and HG[1] != 2, style=shape.triangledown, color=color.gray, text="2", textcolor=color.gray, location=location.abovebar)
plotshape(series=HG == 3 and HG[1] != 3, style=shape.triangledown, color=color.red, text="3", textcolor=color.red, location=location.abovebar)
plotshape(series=HG == 4 and HG[1] != 4, style=shape.triangledown, color=color.gray, text="4", textcolor=color.gray, location=location.abovebar)
plotshape(series=HG == 5 and HG[1] != 5, style=shape.triangledown, color=color.gray, text="5", textcolor=color.gray, location=location.abovebar)
plotshape(series=HG == 6 and HG[1] != 6, style=shape.triangledown, color=color.red, text="6", textcolor=color.red, location=location.abovebar)
plotshape(series=HG == 7 and HG[1] != 7, style=shape.triangledown, color=color.gray, text="7", textcolor=color.gray, location=location.abovebar)
plotshape(series=HG == 8 and HG[1] != 8, style=shape.triangledown, color=color.red, text="8", textcolor=color.red, location=location.abovebar)
plotshape(series=HG == 9 and HG[1] != 9, style=shape.triangledown, color=color.red, text="9", textcolor=color.red, location=location.abovebar)

plotshape(series=LW == 1 and LW[1] != 1, style=shape.triangleup, color=color.gray, text="1", textcolor=color.gray, location=location.belowbar)
plotshape(series=LW == 2 and LW[1] != 2, style=shape.triangleup, color=color.gray, text="2", textcolor=color.gray, location=location.belowbar)
plotshape(series=LW == 3 and LW[1] != 3, style=shape.triangleup, color=color.green, text="3", textcolor=color.green, location=location.belowbar)
plotshape(series=LW == 4 and LW[1] != 4, style=shape.triangleup, color=color.gray, text="4", textcolor=color.gray, location=location.belowbar)
plotshape(series=LW == 5 and LW[1] != 5, style=shape.triangleup, color=color.gray, text="5", textcolor=color.gray, location=location.belowbar)
plotshape(series=LW == 6 and LW[1] != 6, style=shape.triangleup, color=color.green, text="6", textcolor=color.green, location=location.belowbar)
plotshape(series=LW == 7 and LW[1] != 7, style=shape.triangleup, color=color.gray, text="7", textcolor=color.gray, location=location.belowbar)
plotshape(series=LW == 8 and LW[1] != 8, style=shape.triangleup, color=color.green, text="8", textcolor=color.green, location=location.belowbar)
plotshape(series=LW == 9 and LW[1] != 9, style=shape.triangleup, color=color.green, text="9", textcolor=color.green, location=location.belowbar)
Leave a Comment