Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
1.0 kB
6
Indexable
Never
//@version=5

indicator("RSI Calculation", overlay=false)

// Fonksiyonlar
max(a, b) =>
    bar = a > b
    val = bar ? a : b
    val

ema(src, length) =>
    alpha = 2 / (length + 1)
    sum = 0.0
    for i = 0 to length - 1
        sum += src[i]
    ema = sum / length
    for i = length to bar_index
        ema := ema + alpha * (src[i] - ema)
    ema

rsi(src, len) =>
    up = 0.0
    down = 0.0
    rsi = 0.0
    for i = 0 to len-1
        change = src[i] - src[i+1]
        up += max(change, 0)
        down += max(-change, 0)
    
    up /= len
    down /= len
    rs = up / (down + 1e-10) // Small constant to avoid division by 0
    rsi := 100 - (100 / (1 + rs))
    rsi

// Giriş verileri
len = input.int(defval=22, title="RSI Length", minval=1)
src = close

// Hesaplamalar
fe = rsi(src, len)
fe1 = ema(fe, 66)

// Çizim
rsiColor = color.blue
emaColor = color.red
plot(fe, color=rsiColor, linewidth=2, title="RSI")
plot(fe1, color=emaColor, linewidth=2, title="EMA of RSI")
Leave a Comment