0

我正在尝试向 RSI 添加自定义线,但无法填充 hline 和绘图之间的背景。我的代码如下,但填充不是很干净。有什么建议么?

理想情况下,我希望能够选择手动线,然后将它们填充到某个 RSI 值以上。

indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

ma(source, length, type) =>
 switch type
     "SMA" => ta.sma(source, length)
     "Bollinger Bands" => ta.sma(source, length)
     "EMA" => ta.ema(source, length)
     "SMMA (RMA)" => ta.rma(source, length)
     "WMA" => ta.wma(source, length)
     "VWMA" => ta.vwma(source, length)

rsiLengthInput1 = input.int(2, minval=1, title="RSI 1 Length", group="RSI Settings")
rsiLengthInput2 = input.int(14, minval=1, title="RSI 2 Length", group="RSI Settings")
rsiSourceInput1 = input.source(close, "Source", group="RSI Settings")
rsiSourceInput2 = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")

up1 = ta.rma(math.max(ta.change(rsiSourceInput1), 0), rsiLengthInput1)
down1 = ta.rma(-math.min(ta.change(rsiSourceInput1), 0), rsiLengthInput1)
up2 = ta.rma(math.max(ta.change(rsiSourceInput2), 0), rsiLengthInput2)
down2 = ta.rma(-math.min(ta.change(rsiSourceInput2), 0), rsiLengthInput2)
rsi1 = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))
rsi2 = down2 == 0 ? 100 : up2 == 0 ? 0 : 100 - (100 / (1 + up2 / down2))
rsi1MA = ma(rsi1, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"

plot(rsi1, "RSI 1", color=#000000, linewidth=2)
plot(rsi2, "RSI 2", color=color.red, linewidth=2)
plot(rsi1MA, "RSI-based MA", color=color.yellow, display=display.none)
rsiUpperBand = hline(70, "RSI Upper Band", color=color.orange)
hline(50, "RSI Middle Band", color=#000000, linestyle=hline.style_solid, linewidth=2)
rsiLowerBand = hline(30, "RSI Lower Band", color=color.aqua)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
bbUpperBand = plot(isBB ? rsi1MA + ta.stdev(rsi1, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green,display=display.none)
bbLowerBand = plot(isBB ? rsi1MA - ta.stdev(rsi1, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green,display=display.none)
fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill")

//Custom Lines
rsiCustomBand1 = (hline(90, "RSI Custom Band 1", color=#e6100c, linestyle=hline.style_solid, linewidth=1))
rsiCustomBand2 = (hline(85, "RSI Custom Band 2", color=#e6100c, linestyle=hline.style_solid, linewidth=1))
rsiCustomBand3 = (hline(15, "RSI Custom Band 3", color=#008605, linestyle=hline.style_solid, linewidth=1))
rsiCustomBand4 = (hline(10, "RSI Custom Band 4", color=#008605, linestyle=hline.style_solid, linewidth=1))

plotColor = (rsi1>90) ? color.green : na

plotrsiCustomBand1 = plot(series=90, color=#e6100c, style=plot.style_line)
plotrsiCustomBand2 = plot(series=10, color=#008605, style=plot.style_line)
plotrsi1 = plot(series=rsi1, linewidth=1)


//Custom Line Fill
fill(plot1=plotrsiCustomBand1, plot2=plotrsi1, color=plotColor, title="RSI Custom Band 1 & 2 Fill")```
4

0 回答 0