改变RSI图范围-可能与否?



我们知道RSI的绘制范围在0到100之间。

是否可以更改绘制的指示线,使其在一个扩展的范围内波动,例如-50到100 ?

简单地说,我想让它(拉伸),这样我就可以很容易地在RSI线上画出趋势线。

附件照片是我的意思是什么是完美的样本,我有一个不喜欢它。

我希望RSI穿过绿色和红色区域而不影响指示器的运动。我只希望它是拉伸的。

在这里输入图像描述输入图片描述

//@version=5
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)
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = 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(50, title="MA Length", group="MA Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
rsicolor = rsi > 70 ? color.new(#ff0057, 0) : rsi < 30 ? color.new(#ff0057, 0) : #1056ee
plot(rsi, "RSI", color=rsicolor, linewidth=2, style=plot.style_stepline)
plot(rsiMA, "RSI-based MA", color=color.rgb(120, 206, 255))

OverBought1 = input.int(80, minval=1)
OverBought2 = input.int(90, minval=1)
OverSold1 = input.int(20, minval=1)
OverSold2 = input.int(10, minval=1)

OB1 = hline(OverBought1 , color=color.red, linestyle=hline.style_dashed)
OB2 = hline(OverBought2 , color=color.red, linestyle=hline.style_dashed)
OS1 = hline(OverSold1 , color=color.green, linestyle=hline.style_dashed)
OS2 = hline(OverSold2 , color=color.green, linestyle=hline.style_dashed)
fill(OB1 , OB2, color=color.rgb(255, 82, 82, 80), title="Red Zoon Fill")
fill(OS1 , OS2 , color=color.rgb(76, 175, 79, 80), title="Green Zoon Fill")

有什么想法吗?谢谢!

科林

是否可以更改绘制的指示线,使其在一个扩展的范围内波动,例如-50到100 ?

简单地说,我想让它(拉伸),这样我就可以很容易地在RSI线上画出趋势线。

附件照片是我的意思是什么是完美的样本,我有一个不喜欢它。

我希望RSI穿过绿色和红色区域而不影响指示器的运动。我只希望它是拉伸的。

您可以使用normalize()函数:

//@version=5
indicator("My script")
normalize(_src, _min, _max) =>
// Normalizes series with unknown min/max using historical min/max.
// _src      : series to rescale.
// _min, _min: min/max values of rescaled series.
var _historicMin =  10e10
var _historicMax = -10e10
_historicMin := math.min(nz(_src, _historicMin), _historicMin)
_historicMax := math.max(nz(_src, _historicMax), _historicMax)
_min + (_max - _min) * (_src - _historicMin) / math.max(_historicMax - _historicMin, 10e-10)
rsi = ta.rsi(close, 20)
rsiNormalized = normalize(rsi, -50, 100)
plot(rsiNormalized)
hline(-50)
hline(100)

编辑

在你的例子中,因为我们知道刻度总是在0到100之间,我们可以用数学来更准确地解决这个问题:

//@version=5
indicator("My script")
rsi = ta.rsi(close, 20)    // this will give a value between 0 to 100
// find the value compared to a scale of 100
rsiPerc = rsi / 100 
// multiply by the new range to get the position of rsi on the new range
rsiOnNewScale = rsiPerc * 150
// place the newRsi on a scale of -50 to 100
newRsi = rsiOnNewScale - 50
plot(newRsi)
hline(-50)
hline(100)

或者简而言之:

//@version=5
indicator("My script")
rsi = ta.rsi(close, 20)    // this will give a value between 0 to 100
newRsi = (rsi / 100 * 150) - 50
plot(newRsi)
hline(-50)
hline(100)

最新更新