RSCD.txt

 avatar
unknown
plain_text
a month ago
1.9 kB
32
Indexable
//RSI
//@version=4
study(title="RSI & MACD", shorttitle="RSCD", format=format.price, precision=2, resolution="")
len_RSI = input(9, minval=1, title="Length RSI")
src_RSI = input(close, "Source RSI", type = input.source)
up_RSI = rma(max(change(src_RSI), 0), len_RSI)
down_RSI = rma(-min(change(src_RSI), 0), len_RSI)
rsi = (down_RSI == 0 ? 100 : up_RSI == 0 ? 0 : 100 - (100 / (1 + up_RSI / down_RSI)))
plot(rsi, "RSI", color=#8E1599)
band1 = hline(70, "Upper Band RSI", color=#C0C0C0)
band0 = hline(30, "Lower Band RSI", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

//MACD
// Getting inputs
fast_length = input(title="Fast Length MACD", type=input.integer, defval=12)
slow_length = input(title="Slow Length MACD", type=input.integer, defval=26)
src_MACD = input(title="Source MACD", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)
// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00
// Calculating
fast_ma = sma_source ? sma(src_MACD, fast_length) : ema(src_MACD, fast_length)
slow_ma = sma_source ? sma(src_MACD, slow_length) : ema(src_MACD, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
plot(1000*hist/src_MACD, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
plot(1000*macd/src_MACD, title="MACD", color=col_macd, transp=0)
plot(1000*signal/src_MACD, title="Signal", color=col_signal, transp=0)
Leave a Comment