英文:
add text on uptrend and downtrend
问题
我将2个RSI合并成了1个,但是当RSI穿过上下限时,我想添加文字。我尝试在这里添加文字
```up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput) 
但它不起作用。这是我想要的效果,请帮忙。
indicator(title="Darkforum 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(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", 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)
isBB = maTypeInput == "Bollinger Bands"
plot(rsi, "RSI", color=#7E57C2)
plot(rsiMA, "RSI-based MA", color=color.yellow)
rsiUpperBand = plot(70, "RSI Upper Band", color=#f7270b)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = plot(30, "RSI Lower Band", color=#fc2c10)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)
fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(#42f748, 2) : na, title="Bollinger Bands Background Fill")
<details>
<summary>英文:</summary>
I merged 2 rsi into 1 but when rsi cross the upper or lower band then I want to add text. I tried to add text on this 
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
but its not working. here is what i want in this pic, please help me.
[![https://i.gyazo.com/36f0e5b9072c66ec27bf25a6b0299839.png][1]][1]
    indicator(title="Darkforum 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(14, title="MA Length", group="MA Settings")
    bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", 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)
    isBB = maTypeInput == "Bollinger Bands"
    
    
    plot(rsi, "RSI", color=#7E57C2)
    plot(rsiMA, "RSI-based MA", color=color.yellow)
    rsiUpperBand = plot(70, "RSI Upper Band", color=#f7270b)
    hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
    rsiLowerBand = plot(30, "RSI Lower Band", color=#fc2c10)
    fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
    bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
    bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)
    fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(#42f748, 2) : na, title="Bollinger Bands Background Fill")
  [1]: https://i.stack.imgur.com/Hi31H.png
</details>
# 答案1
**得分**: 1
在你的图片上,当你的相对强弱指标 (RSI) 大于 70 时,你写上了 `High`,当 RSI 小于 70 时,你写上了 `Low`,你可以将以下代码添加到你的程序末尾:
```python
if ta.crossover(rsi, 70)
    label.new(bar_index, 75, "High", color=color.new(color.white, 100), style=label.style_label_down)
if ta.crossover(30, rsi)
    label.new(bar_index, 25, "Low", color=color.new(color.white, 100), style=label.style_label_up)
并得到如下效果:

英文:
On your pic, you write High when your rsi > 70 and Lowwhen your rsi < 70, you can add this to your code (at the end) :
if ta.crossover(rsi,70)
    label.new(bar_index, 75, "High", color=color.new(color.white, 100), style=label.style_label_down)
if ta.crossover(30, rsi)
    label.new(bar_index, 25, "Low", color=color.new(color.white, 100), style=label.style_label_up)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论