Untitled

 avatar
unknown
plain_text
4 months ago
4.0 kB
7
Indexable
//@version=5
indicator(title="DCA-X", shorttitle="DCA-X", overlay=true)

// Inputs
Length = input.int(21, minval=1, title="Length")
xPrice = close

xvnoise = math.abs(xPrice - xPrice[1])
var float x = 0.0
nfastend = 0.666
nslowend = 0.0645

nsignal = math.abs(xPrice - xPrice[Length])
nnoise = math.sum(xvnoise, Length)
nefratio = nnoise != 0 ? nsignal / nnoise : 0
nsmooth = math.pow(nefratio * (nfastend - nslowend) + nslowend, 2)
x := nz(x[1]) + nsmooth * (xPrice - nz(x[1]))

// 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 = close > x
down_condition = close < x

// 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)
Editor is loading...
Leave a Comment