在上升趋势和下降趋势上添加文本。

huangapple go评论63阅读模式
英文:

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=&quot;Darkforum RSI&quot;, format=format.price, precision=2, timeframe=&quot;&quot;, timeframe_gaps=true)
    
    ma(source, length, type) =&gt;
        switch type
            &quot;SMA&quot; =&gt; ta.sma(source, length)
            &quot;Bollinger Bands&quot; =&gt; ta.sma(source, length)
            &quot;EMA&quot; =&gt; ta.ema(source, length)
            &quot;SMMA (RMA)&quot; =&gt; ta.rma(source, length)
            &quot;WMA&quot; =&gt; ta.wma(source, length)
            &quot;VWMA&quot; =&gt; ta.vwma(source, length)
    
    rsiLengthInput = input.int(14, minval=1, title=&quot;RSI Length&quot;, group=&quot;RSI Settings&quot;)
    rsiSourceInput = input.source(close, &quot;Source&quot;, group=&quot;RSI Settings&quot;)
    maTypeInput = input.string(&quot;SMA&quot;, title=&quot;MA Type&quot;, options=[&quot;SMA&quot;, &quot;Bollinger Bands&quot;, &quot;EMA&quot;, &quot;SMMA (RMA)&quot;, &quot;WMA&quot;, &quot;VWMA&quot;], group=&quot;MA Settings&quot;)
    maLengthInput = input.int(14, title=&quot;MA Length&quot;, group=&quot;MA Settings&quot;)
    bbMultInput = input.float(2.0, minval=0.001, maxval=50, title=&quot;BB StdDev&quot;, group=&quot;MA Settings&quot;)
    
    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 == &quot;Bollinger Bands&quot;
    
    
    plot(rsi, &quot;RSI&quot;, color=#7E57C2)
    plot(rsiMA, &quot;RSI-based MA&quot;, color=color.yellow)
    rsiUpperBand = plot(70, &quot;RSI Upper Band&quot;, color=#f7270b)
    hline(50, &quot;RSI Middle Band&quot;, color=color.new(#787B86, 50))
    rsiLowerBand = plot(30, &quot;RSI Lower Band&quot;, color=#fc2c10)
    fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title=&quot;RSI Background Fill&quot;)
    bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = &quot;Upper Bollinger Band&quot;, color=color.green)
    bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = &quot;Lower Bollinger Band&quot;, color=color.green)
    fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(#42f748, 2) : na, title=&quot;Bollinger Bands Background Fill&quot;)


  [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, &quot;High&quot;, color=color.new(color.white, 100), style=label.style_label_down)
if ta.crossover(30, rsi)
    label.new(bar_index, 25, &quot;Low&quot;, color=color.new(color.white, 100), style=label.style_label_up)

and get :
在上升趋势和下降趋势上添加文本。

huangapple
  • 本文由 发表于 2023年5月11日 06:50:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223062.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定