MACD + RSI

ikhwanh · study · 42 行 · 点赞 4,975 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=3
study(title="MACD + RSI", shorttitle="MACD+RSI")
 
// MACD
src = input(title="Source", type=source, defval=close)
fast_length = input(title="MACD Fast Length", type=integer, defval=12)
slow_length = input(title="MACD Slow Length", type=integer, defval=26)
signal_length = input(title="MACD Signal Smoothing", type=integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="MACD Simple MA (Oscillator)", type=bool, defval=false)
sma_signal = input(title="MACD Simple MA (Signal Line)", type=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, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
 
plot(hist, title="Histogram", 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(macd, title="MACD", color=col_macd, transp=0)
plot(signal, title="Signal", color=col_signal, transp=0)
 
 
// RSI
len = input(14, minval=1, title="RSI Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
scale = 0.0005
move = 0.05
plot(((rsi-50)*scale)-move, color=purple)
band1 = hline(((20)*scale)-move)
band0 = hline(((-20)*scale)-move)
fill(band1, band0, color=purple, transp=95)

← 返回列表