代码之家  ›  专栏  ›  技术社区  ›  idkmyname

RSI线在不同级别显示不同的颜色

  •  0
  • idkmyname  · 技术社区  · 3 年前

    我使用了一个基本的RSI指标,上面也有布林带作为覆盖。我希望我的RSI线在不同的层次上显示不同的颜色。我希望线在60以上时是绿色,在40以下时是红色,在60&40

    这是代码: //@版本=5 指标(“相对强弱指数上的布林带”,叠加=假)

    // INPUT CONTROLS
    
    LENGTHSMA = input.int(title = "SMA", defval = 20, minval = 1, maxval = 30, step= 1)
    MULTI = input.int(title = "MULTI", defval = 2, minval = 1, maxval = 3, step = 1)
    LENGTHRSI =  input.int(title= "LRSI", defval = 14, minval = 1, maxval = 30, step = 1) 
    
    
    // TRADING INDICATORS
    
    //SMA = ta.sma(close, LENGTHSMA)
    //STD = ta.stdev (RSI,20)
    //upperband = SMA + (STD * 2)
    //lowerband = SMA - (STD *2)
    
    // Bollinger band on RSI indicator
    RSI = ta.rsi(close, LENGTHRSI)
    STD = ta.stdev(RSI, LENGTHSMA)
    SMA= ta.sma (RSI, LENGTHSMA)
    
    upperband = SMA + (STD * MULTI) 
    lowerband = SMA - (STD * MULTI)
    
    plot (upperband)
    plot (lowerband)
    plot (SMA)
    
    plot (RSI, color = color.new(color.red, 0), linewidth = 1)
    hline (80)
    hline (60)
    hline (40)
    hline (20)
    
    I actually tried modifying the above code in accordance to different answers(from this website), but since I don't know how to write code(I got the above one on studying a YouTube video) I failed miserably.
    
    0 回复  |  直到 3 年前
        1
  •  0
  •   AmphibianTrading    3 年前

    您可以在plot语句中使用三元运算符来更改颜色

    plot (RSI, color = RSI > 60 ? color.green : RSI < 40 ? color.red : color.yellow, linewidth = 1)
    
    推荐文章