Stochastic RSI and MACD leader [ChuckBanger]

ChuckBanger · study · 51 行 · 点赞 1,979 · TradingView 原页

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

Pine Script

//@version=4
study(title="Stochastic RSI and MACD leader [ChuckBanger]", shorttitle="Stoch RSI MACD Leader CB", format=format.price)
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
src = input(close, title="Source")
 
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
plot(k, color=color.blue)
plot(d, color=color.orange)
h0 = hline(80)
h1 = hline(20)
fill(h0, h1, color=color.purple, transp=96)
 
shortLength = input(12, title="MACD Fast Length", minval=1)
longLength = input(26, title="MACD Slow Length", minval=1)
sigLength = input(9, title="MACD Signal Smoothing", minval=1, maxval=50)
showMACD = input(false, title="Show MACD line")
showMACDSignal = input(true, title="Show MACD Signal")
//showMACDHistogram = input(false, title="Show MACD Histogram")
type = input(defval="EMA", options=["SMA", "EMA", "WMA", "RMA", "HMA"],title="Smoothing MA Type")
 
hma(x, p)  => wma((2 * wma(x, p / 2)) - wma(x, p), round(sqrt(p)))
 
matype(_type, _src, _len) =>
    _len==0 ? _src :  _type=="SMA" ? sma(_src, _len) : _type=="EMA" ? ema(_src, _len) : _type=="WMA" ? wma(_src, _len) : _type=="RMA" ? rma(_src, _len) : _type=="HMA" ? hma(_src, _len) : na
 
 
shortEMA = matype(type, src, shortLength)
longEMA = matype(type, src, longLength)
macdLeader = (shortEMA  + matype(type, src - shortEMA, shortLength)) - (longEMA + matype(type, src - longEMA, longLength))
 
[macdLine, signalLine, histLine] = macd(src, shortLength, longLength, sigLength)
 
// Plot colors
colGrowAbove = #26A69A
colGrowBelow = #FFCDD2
colFallAbove = #B2DFDB
colFallBelow = #EF5350
colMacd = #00dcff
colSignal = #00d547
colMacdLaeder = #ff0000
 
//plot(showMACDHistogram ? histLine : na, title="Histogram", style=plot.style_columns, color=(histLine>=0 ? (histLine[1] < histLine ? colGrowAbove : colFallAbove) : (histLine[1] < histLine ? colGrowBelow : colFallBelow) ), transp=0 )
 
plot(macdLeader, title="MACD Leader", color=colMacdLaeder, linewidth=2)
plot(showMACD ? macdLine : na, title="MACD", color=colMacd)
plot(showMACDSignal ? signalLine : na, title="Signal", color=colSignal)

← 返回列表