Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pine script 结合两个内置的pine脚本指示器,以解决缩放问题_Pine Script - Fatal编程技术网

Pine script 结合两个内置的pine脚本指示器,以解决缩放问题

Pine script 结合两个内置的pine脚本指示器,以解决缩放问题,pine-script,Pine Script,我正在编写一个脚本,将两个内置指标组合在一个脚本中(RSI和技术评级) 但我面临着缩放问题,我已经尝试并达到了这个结果,你可以在这张图片中看到,我已经成功地将标签的y位置放置在RSI中,但其他指标的直方图在红色圆圈中向下标记,这看起来像是经过大量放大后的结果 因此,我希望这两个指示器彼此重叠,如图所示,这是通过在一个窗格中移动两个指示器来完成的,但我希望仅使用一个pine脚本就可以得到相同的结果 有人能帮我吗 多谢各位 这是我的组合代码 //@version=4 study(title=&quo

我正在编写一个脚本,将两个内置指标组合在一个脚本中(RSI和技术评级) 但我面临着缩放问题,我已经尝试并达到了这个结果,你可以在这张图片中看到,我已经成功地将标签的y位置放置在RSI中,但其他指标的直方图在红色圆圈中向下标记,这看起来像是经过大量放大后的结果

因此,我希望这两个指示器彼此重叠,如图所示,这是通过在一个窗格中移动两个指示器来完成的,但我希望仅使用一个pine脚本就可以得到相同的结果 有人能帮我吗

多谢各位

这是我的组合代码

//@version=4
study(title="Technical Ratings", shorttitle="Technicals", precision=2)
res = input("", title="Indicator Timeframe", type=input.resolution)
ratingSignal = input(defval = "All", title = "Rating is based on", options = ["MAs", "Oscillators", "All"])
// Awesome Oscillator
AO() => 
    sma(hl2, 5) - sma(hl2, 34)
// Stochastic RSI
StochRSI() =>
    rsi1 = rsi(close, 14)
    K = sma(stoch(rsi1, rsi1, rsi1, 14), 3)
    D = sma(K, 3)
    [K, D]
// Ultimate Oscillator
tl() => close[1] < low ? close[1]: low
uo(ShortLen, MiddlLen, LongLen) =>
    Value1 = sum(tr, ShortLen)
    Value2 = sum(tr, MiddlLen)
    Value3 = sum(tr, LongLen)
    Value4 = sum(close - tl(), ShortLen)
    Value5 = sum(close - tl(), MiddlLen)
    Value6 = sum(close - tl(), LongLen)
    float UO = na
    if Value1 != 0 and Value2 != 0 and Value3 != 0
        var0 = LongLen / ShortLen
        var1 = LongLen / MiddlLen
        Value7 = (Value4 / Value1) * (var0)
        Value8 = (Value5 / Value2) * (var1)
        Value9 = (Value6 / Value3)
        UO := (Value7 + Value8 + Value9) / (var0 + var1 + 1)
    UO
// Ichimoku Cloud
donchian(len) => avg(lowest(len), highest(len))
ichimoku_cloud() =>
    conversionLine = donchian(9)
    baseLine = donchian(26)
    leadLine1 = avg(conversionLine, baseLine)
    leadLine2 = donchian(52)
    [conversionLine, baseLine, leadLine1, leadLine2]
    
calcRatingMA(ma, src) => na(ma) or na(src) ? na : (ma == src ? 0 : ( ma < src ? 1 : -1 ))
calcRating(buy, sell) => buy ? 1 : ( sell ? -1 : 0 )
calcRatingAll() =>
    //============== MA =================
    SMA10 = sma(close, 10)
    SMA20 = sma(close, 20)
    SMA30 = sma(close, 30)
    SMA50 = sma(close, 50)
    SMA100 = sma(close, 100)
    SMA200 = sma(close, 200)
    
    EMA10 = ema(close, 10)
    EMA20 = ema(close, 20)
    EMA30 = ema(close, 30)
    EMA50 = ema(close, 50)
    EMA100 = ema(close, 100)
    EMA200 = ema(close, 200)
    
    HullMA9 = hma(close, 9)
    
    // Volume Weighted Moving Average (VWMA)
    VWMA = vwma(close, 20)
    
    [IC_CLine, IC_BLine, IC_Lead1, IC_Lead2] = ichimoku_cloud()
    
    // ======= Other =============
    // Relative Strength Index, RSI
    RSI = rsi(close,14)
    
    // Stochastic
    lengthStoch = 14
    smoothKStoch = 3
    smoothDStoch = 3
    kStoch = sma(stoch(close, high, low, lengthStoch), smoothKStoch)
    dStoch = sma(kStoch, smoothDStoch)
    
    // Commodity Channel Index, CCI
    CCI = cci(close, 20)
    
    // Average Directional Index
    float adxValue = na, float adxPlus = na, float adxMinus = na
    [P, M, V] = dmi(14, 14)
    adxValue := V
    adxPlus := P
    adxMinus := M
    // Awesome Oscillator
    ao = AO()
    
    // Momentum
    Mom = mom(close, 10)
    // Moving Average Convergence/Divergence, MACD
    [macdMACD, signalMACD, _] = macd(close, 12, 26, 9)
    // Stochastic RSI
    [Stoch_RSI_K, Stoch_RSI_D] = StochRSI()
    // Williams Percent Range
    WR = wpr(14)
    
    // Bull / Bear Power
    BullPower = high - ema(close, 13)
    BearPower = low - ema(close, 13)
    // Ultimate Oscillator
    UO = uo(7,14,28)
    if not na(UO)
        UO := UO * 100
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    PriceAvg = ema(close, 50)
    DownTrend = close < PriceAvg
    UpTrend = close > PriceAvg
    // calculate trading recommendation based on SMA/EMA
    float ratingMA = 0
    float ratingMAC = 0
    
    if not na(SMA10)
        ratingMA := ratingMA + calcRatingMA(SMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA20)
        ratingMA := ratingMA + calcRatingMA(SMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA30)
        ratingMA := ratingMA + calcRatingMA(SMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA50)
        ratingMA := ratingMA + calcRatingMA(SMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA100)
        ratingMA := ratingMA + calcRatingMA(SMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA200)
        ratingMA := ratingMA + calcRatingMA(SMA200, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA10)
        ratingMA := ratingMA + calcRatingMA(EMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA20)
        ratingMA := ratingMA + calcRatingMA(EMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA30)
        ratingMA := ratingMA + calcRatingMA(EMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA50)
        ratingMA := ratingMA + calcRatingMA(EMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA100)
        ratingMA := ratingMA + calcRatingMA(EMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA200)
        ratingMA := ratingMA + calcRatingMA(EMA200, close)
        ratingMAC := ratingMAC + 1
    
    if not na(HullMA9)
        ratingHullMA9 = calcRatingMA(HullMA9, close)
        ratingMA := ratingMA + ratingHullMA9
        ratingMAC := ratingMAC + 1
    
    if not na(VWMA)
        ratingVWMA = calcRatingMA(VWMA, close)
        ratingMA := ratingMA + ratingVWMA
        ratingMAC := ratingMAC + 1
    
    float ratingIC = na
    if not (na(IC_Lead1) or na(IC_Lead2) or na(close) or na(close[1]) or na(IC_BLine) or na(IC_CLine))
        ratingIC := calcRating(
         IC_Lead1 > IC_Lead2 and close > IC_Lead1 and close < IC_BLine and close[1] < IC_CLine and close > IC_CLine,
         IC_Lead2 > IC_Lead1 and close < IC_Lead2 and close > IC_BLine and close[1] > IC_CLine and close < IC_CLine)
    if not na(ratingIC)
        ratingMA := ratingMA + ratingIC
        ratingMAC := ratingMAC + 1
    
    ratingMA := ratingMAC > 0 ? ratingMA / ratingMAC : na
    
    float ratingOther = 0
    float ratingOtherC = 0
    
    ratingRSI = RSI
    if not(na(ratingRSI) or na(ratingRSI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingRSI < 30 and ratingRSI[1] < ratingRSI, ratingRSI > 70 and ratingRSI[1] > ratingRSI)
    
    if not(na(kStoch) or na(dStoch) or na(kStoch[1]) or na(dStoch[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(kStoch < 20 and dStoch < 20 and kStoch > dStoch and kStoch[1] < dStoch[1], kStoch > 80 and dStoch > 80 and kStoch < dStoch and kStoch[1] > dStoch[1])
    
    ratingCCI = CCI
    if not(na(ratingCCI) or na(ratingCCI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingCCI < -100 and ratingCCI > ratingCCI[1], ratingCCI > 100 and ratingCCI < ratingCCI[1])
    
    if not(na(adxValue) or na(adxPlus[1]) or na(adxMinus[1]) or na(adxPlus) or na(adxMinus))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(adxValue > 20 and adxPlus[1] < adxMinus[1] and adxPlus > adxMinus, adxValue > 20 and adxPlus[1] > adxMinus[1] and adxPlus < adxMinus)
    
    if not(na(ao) or na(ao[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(crossover(ao,0) or (ao > 0 and ao[1] > 0 and ao > ao[1] and ao[2] > ao[1]), crossunder(ao,0) or (ao < 0 and ao[1] < 0 and ao < ao[1] and ao[2] < ao[1]))
    
    if not(na(Mom) or na(Mom[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(Mom > Mom[1], Mom < Mom[1])
    
    if not(na(macdMACD) or na(signalMACD))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(macdMACD > signalMACD, macdMACD < signalMACD)
    
    float ratingStoch_RSI = na
    if not(na(DownTrend) or na(UpTrend) or na(Stoch_RSI_K) or na(Stoch_RSI_D) or na(Stoch_RSI_K[1]) or na(Stoch_RSI_D[1]))
        ratingStoch_RSI := calcRating(
         DownTrend and Stoch_RSI_K < 20 and Stoch_RSI_D < 20 and Stoch_RSI_K > Stoch_RSI_D and Stoch_RSI_K[1] < Stoch_RSI_D[1],
         UpTrend and Stoch_RSI_K > 80 and Stoch_RSI_D > 80 and Stoch_RSI_K < Stoch_RSI_D and Stoch_RSI_K[1] > Stoch_RSI_D[1])
    if not na(ratingStoch_RSI)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingStoch_RSI
    
    float ratingWR = na
    if not(na(WR) or na(WR[1]))
        ratingWR := calcRating(WR < -80 and WR > WR[1], WR > -20 and WR < WR[1])
    if not na(ratingWR)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingWR
    
    float ratingBBPower = na
    if not(na(UpTrend) or na(DownTrend) or na(BearPower) or na(BearPower[1]) or na(BullPower) or na(BullPower[1]))
        ratingBBPower := calcRating(
         UpTrend and BearPower < 0 and BearPower > BearPower[1],
         DownTrend and BullPower > 0 and BullPower < BullPower[1])
    if not na(ratingBBPower)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingBBPower
    
    float ratingUO = na
    if not(na(UO))
        ratingUO := calcRating(UO > 70, UO < 30)
    if not na(ratingUO)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingUO
    
    ratingOther := ratingOtherC > 0 ? ratingOther / ratingOtherC : na
    
    float ratingTotal = 0
    float ratingTotalC = 0
    if not na(ratingMA)
        ratingTotal := ratingTotal + ratingMA
        ratingTotalC := ratingTotalC + 1
    if not na(ratingOther)
        ratingTotal := ratingTotal + ratingOther
        ratingTotalC := ratingTotalC + 1
    ratingTotal := ratingTotalC > 0 ? ratingTotal / ratingTotalC : na
    
    [ratingTotal, ratingOther, ratingMA, ratingOtherC, ratingMAC]
[ratingTotal, ratingOther, ratingMA, ratingOtherC, ratingMAC]  = security(syminfo.tickerid, res, calcRatingAll())
StrongBound = 0.5
WeakBound = 0.1
getSignal(ratingTotal, ratingOther, ratingMA) =>
    float _res = ratingTotal
    if ratingSignal == "MAs"
        _res := ratingMA
    if ratingSignal == "Oscillators"
        _res := ratingOther
    _res
tradeSignal = getSignal(ratingTotal, ratingOther, ratingMA)


poscol = input(color.blue, "Buy Color")
neutralcolor = input(color.gray, "Neutral Color")
negcol = input(color.red, "Sell Color")
poscond = tradeSignal > WeakBound
negcond = tradeSignal < -WeakBound
posseries = poscond ? tradeSignal : 0
negseries = negcond ? tradeSignal : 0
count_rising(plot) =>
    v_plot = plot > 0 ? plot : -plot
    var count = 0
    if v_plot == 0
        count := 0
    else if v_plot >= v_plot[1]
        count := min(5, count + 1)
    else if v_plot < v_plot[1]
        count := max(1, count - 1)
    count
poscount = count_rising(posseries)
negcount = count_rising(negseries)
_pc = poscond ? poscount : negcond ? negcount : 0
colorTransp(col, transp) =>
    red = color.r(col)
    green = color.g(col)
    blue = color.b(col)
    color.rgb(red, green, blue, transp)
hline(70, color=colorTransp(poscol, 50), linestyle=hline.style_solid)
hline(0.5, color=colorTransp(poscol, 50), linestyle=hline.style_dashed)
hline(-1, color=colorTransp(negcol, 50), linestyle=hline.style_solid)
hline(-0.5, color=colorTransp(negcol, 50), linestyle=hline.style_dashed)
getTimeOfNextBar() =>
    currentTime = time(timeframe.period)
    changeTime = change(currentTime)
    minChange = if (not na(changeTime))
        var float minChange = changeTime
        minChange := min(minChange, changeTime)
    int(currentTime + minChange)
drawInfo(txt, value) =>
    var info = label.new(50, 50, "", yloc = yloc.price, xloc = xloc.bar_time, textalign = text.align_left, textcolor = color.white)
    label.set_x(info, getTimeOfNextBar())
    label.set_text(info, txt)
    label.set_color(info, poscond ? poscol : negcond ? negcol : color.gray)
    label.set_style(info, label.style_label_left)
calcRatingStatus(value) =>
    if -StrongBound > value
        "Strong Sell"
    else if value < -WeakBound
        "Sell"
    else if value > StrongBound
        "Strong Buy"
    else if value > WeakBound
        "Buy"
    else
        "Neutral"
MAText = ratingMAC == 0 ? "" : "MAs:     " + calcRatingStatus(ratingMA) + "\n"
OtherText = ratingOtherC == 0 ? "" : "Oscillators: " + calcRatingStatus(ratingOther) + "\n"
TotaText = "All:  " + calcRatingStatus(ratingTotal)
drawInfo(MAText + OtherText + TotaText, tradeSignal)
col_buy = color.from_gradient(tradeSignal, 0.0, 0.2, neutralcolor, poscol)
col_sell = color.from_gradient(tradeSignal, -0.2, 0.0, negcol, neutralcolor)
col_gradient = color.from_gradient(tradeSignal, -0.2, 0.2, col_sell, col_buy)
plot(tradeSignal, title="Rating", linewidth = 1, style = plot.style_columns, color = colorTransp(col_gradient, 50 - _pc * 10))
_cond1 = crossunder(tradeSignal, -WeakBound)
alertcondition(_cond1, "Sell", "Ratings changed to Sell")
_cond2 = crossover(tradeSignal, WeakBound)
alertcondition(_cond2, "Buy", "Ratings changed to Buy")
_cond3 = crossunder(tradeSignal, -StrongBound)
alertcondition(_cond3, "Strong Sell", "Ratings changed to Strong Sell")
_cond4 = crossover(tradeSignal, StrongBound)
alertcondition(_cond4, "Strong Buy", "Ratings changed to Strong Buy")


////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
/////////////////      RSI      ///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////


len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#8E1599)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")
内置技术评级代码

//@version=4
study(title="Technical Ratings", shorttitle="Technicals", precision=2)
res = input("", title="Indicator Timeframe", type=input.resolution)
ratingSignal = input(defval = "All", title = "Rating is based on", options = ["MAs", "Oscillators", "All"])
// Awesome Oscillator
AO() => 
    sma(hl2, 5) - sma(hl2, 34)
// Stochastic RSI
StochRSI() =>
    rsi1 = rsi(close, 14)
    K = sma(stoch(rsi1, rsi1, rsi1, 14), 3)
    D = sma(K, 3)
    [K, D]
// Ultimate Oscillator
tl() => close[1] < low ? close[1]: low
uo(ShortLen, MiddlLen, LongLen) =>
    Value1 = sum(tr, ShortLen)
    Value2 = sum(tr, MiddlLen)
    Value3 = sum(tr, LongLen)
    Value4 = sum(close - tl(), ShortLen)
    Value5 = sum(close - tl(), MiddlLen)
    Value6 = sum(close - tl(), LongLen)
    float UO = na
    if Value1 != 0 and Value2 != 0 and Value3 != 0
        var0 = LongLen / ShortLen
        var1 = LongLen / MiddlLen
        Value7 = (Value4 / Value1) * (var0)
        Value8 = (Value5 / Value2) * (var1)
        Value9 = (Value6 / Value3)
        UO := (Value7 + Value8 + Value9) / (var0 + var1 + 1)
    UO
// Ichimoku Cloud
donchian(len) => avg(lowest(len), highest(len))
ichimoku_cloud() =>
    conversionLine = donchian(9)
    baseLine = donchian(26)
    leadLine1 = avg(conversionLine, baseLine)
    leadLine2 = donchian(52)
    [conversionLine, baseLine, leadLine1, leadLine2]
    
calcRatingMA(ma, src) => na(ma) or na(src) ? na : (ma == src ? 0 : ( ma < src ? 1 : -1 ))
calcRating(buy, sell) => buy ? 1 : ( sell ? -1 : 0 )
calcRatingAll() =>
    //============== MA =================
    SMA10 = sma(close, 10)
    SMA20 = sma(close, 20)
    SMA30 = sma(close, 30)
    SMA50 = sma(close, 50)
    SMA100 = sma(close, 100)
    SMA200 = sma(close, 200)
    
    EMA10 = ema(close, 10)
    EMA20 = ema(close, 20)
    EMA30 = ema(close, 30)
    EMA50 = ema(close, 50)
    EMA100 = ema(close, 100)
    EMA200 = ema(close, 200)
    
    HullMA9 = hma(close, 9)
    
    // Volume Weighted Moving Average (VWMA)
    VWMA = vwma(close, 20)
    
    [IC_CLine, IC_BLine, IC_Lead1, IC_Lead2] = ichimoku_cloud()
    
    // ======= Other =============
    // Relative Strength Index, RSI
    RSI = rsi(close,14)
    
    // Stochastic
    lengthStoch = 14
    smoothKStoch = 3
    smoothDStoch = 3
    kStoch = sma(stoch(close, high, low, lengthStoch), smoothKStoch)
    dStoch = sma(kStoch, smoothDStoch)
    
    // Commodity Channel Index, CCI
    CCI = cci(close, 20)
    
    // Average Directional Index
    float adxValue = na, float adxPlus = na, float adxMinus = na
    [P, M, V] = dmi(14, 14)
    adxValue := V
    adxPlus := P
    adxMinus := M
    // Awesome Oscillator
    ao = AO()
    
    // Momentum
    Mom = mom(close, 10)
    // Moving Average Convergence/Divergence, MACD
    [macdMACD, signalMACD, _] = macd(close, 12, 26, 9)
    // Stochastic RSI
    [Stoch_RSI_K, Stoch_RSI_D] = StochRSI()
    // Williams Percent Range
    WR = wpr(14)
    
    // Bull / Bear Power
    BullPower = high - ema(close, 13)
    BearPower = low - ema(close, 13)
    // Ultimate Oscillator
    UO = uo(7,14,28)
    if not na(UO)
        UO := UO * 100
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    PriceAvg = ema(close, 50)
    DownTrend = close < PriceAvg
    UpTrend = close > PriceAvg
    // calculate trading recommendation based on SMA/EMA
    float ratingMA = 0
    float ratingMAC = 0
    
    if not na(SMA10)
        ratingMA := ratingMA + calcRatingMA(SMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA20)
        ratingMA := ratingMA + calcRatingMA(SMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA30)
        ratingMA := ratingMA + calcRatingMA(SMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA50)
        ratingMA := ratingMA + calcRatingMA(SMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA100)
        ratingMA := ratingMA + calcRatingMA(SMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA200)
        ratingMA := ratingMA + calcRatingMA(SMA200, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA10)
        ratingMA := ratingMA + calcRatingMA(EMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA20)
        ratingMA := ratingMA + calcRatingMA(EMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA30)
        ratingMA := ratingMA + calcRatingMA(EMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA50)
        ratingMA := ratingMA + calcRatingMA(EMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA100)
        ratingMA := ratingMA + calcRatingMA(EMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA200)
        ratingMA := ratingMA + calcRatingMA(EMA200, close)
        ratingMAC := ratingMAC + 1
    
    if not na(HullMA9)
        ratingHullMA9 = calcRatingMA(HullMA9, close)
        ratingMA := ratingMA + ratingHullMA9
        ratingMAC := ratingMAC + 1
    
    if not na(VWMA)
        ratingVWMA = calcRatingMA(VWMA, close)
        ratingMA := ratingMA + ratingVWMA
        ratingMAC := ratingMAC + 1
    
    float ratingIC = na
    if not (na(IC_Lead1) or na(IC_Lead2) or na(close) or na(close[1]) or na(IC_BLine) or na(IC_CLine))
        ratingIC := calcRating(
         IC_Lead1 > IC_Lead2 and close > IC_Lead1 and close < IC_BLine and close[1] < IC_CLine and close > IC_CLine,
         IC_Lead2 > IC_Lead1 and close < IC_Lead2 and close > IC_BLine and close[1] > IC_CLine and close < IC_CLine)
    if not na(ratingIC)
        ratingMA := ratingMA + ratingIC
        ratingMAC := ratingMAC + 1
    
    ratingMA := ratingMAC > 0 ? ratingMA / ratingMAC : na
    
    float ratingOther = 0
    float ratingOtherC = 0
    
    ratingRSI = RSI
    if not(na(ratingRSI) or na(ratingRSI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingRSI < 30 and ratingRSI[1] < ratingRSI, ratingRSI > 70 and ratingRSI[1] > ratingRSI)
    
    if not(na(kStoch) or na(dStoch) or na(kStoch[1]) or na(dStoch[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(kStoch < 20 and dStoch < 20 and kStoch > dStoch and kStoch[1] < dStoch[1], kStoch > 80 and dStoch > 80 and kStoch < dStoch and kStoch[1] > dStoch[1])
    
    ratingCCI = CCI
    if not(na(ratingCCI) or na(ratingCCI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingCCI < -100 and ratingCCI > ratingCCI[1], ratingCCI > 100 and ratingCCI < ratingCCI[1])
    
    if not(na(adxValue) or na(adxPlus[1]) or na(adxMinus[1]) or na(adxPlus) or na(adxMinus))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(adxValue > 20 and adxPlus[1] < adxMinus[1] and adxPlus > adxMinus, adxValue > 20 and adxPlus[1] > adxMinus[1] and adxPlus < adxMinus)
    
    if not(na(ao) or na(ao[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(crossover(ao,0) or (ao > 0 and ao[1] > 0 and ao > ao[1] and ao[2] > ao[1]), crossunder(ao,0) or (ao < 0 and ao[1] < 0 and ao < ao[1] and ao[2] < ao[1]))
    
    if not(na(Mom) or na(Mom[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(Mom > Mom[1], Mom < Mom[1])
    
    if not(na(macdMACD) or na(signalMACD))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(macdMACD > signalMACD, macdMACD < signalMACD)
    
    float ratingStoch_RSI = na
    if not(na(DownTrend) or na(UpTrend) or na(Stoch_RSI_K) or na(Stoch_RSI_D) or na(Stoch_RSI_K[1]) or na(Stoch_RSI_D[1]))
        ratingStoch_RSI := calcRating(
         DownTrend and Stoch_RSI_K < 20 and Stoch_RSI_D < 20 and Stoch_RSI_K > Stoch_RSI_D and Stoch_RSI_K[1] < Stoch_RSI_D[1],
         UpTrend and Stoch_RSI_K > 80 and Stoch_RSI_D > 80 and Stoch_RSI_K < Stoch_RSI_D and Stoch_RSI_K[1] > Stoch_RSI_D[1])
    if not na(ratingStoch_RSI)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingStoch_RSI
    
    float ratingWR = na
    if not(na(WR) or na(WR[1]))
        ratingWR := calcRating(WR < -80 and WR > WR[1], WR > -20 and WR < WR[1])
    if not na(ratingWR)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingWR
    
    float ratingBBPower = na
    if not(na(UpTrend) or na(DownTrend) or na(BearPower) or na(BearPower[1]) or na(BullPower) or na(BullPower[1]))
        ratingBBPower := calcRating(
         UpTrend and BearPower < 0 and BearPower > BearPower[1],
         DownTrend and BullPower > 0 and BullPower < BullPower[1])
    if not na(ratingBBPower)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingBBPower
    
    float ratingUO = na
    if not(na(UO))
        ratingUO := calcRating(UO > 70, UO < 30)
    if not na(ratingUO)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingUO
    
    ratingOther := ratingOtherC > 0 ? ratingOther / ratingOtherC : na
    
    float ratingTotal = 0
    float ratingTotalC = 0
    if not na(ratingMA)
        ratingTotal := ratingTotal + ratingMA
        ratingTotalC := ratingTotalC + 1
    if not na(ratingOther)
        ratingTotal := ratingTotal + ratingOther
        ratingTotalC := ratingTotalC + 1
    ratingTotal := ratingTotalC > 0 ? ratingTotal / ratingTotalC : na
    
    [ratingTotal, ratingOther, ratingMA, ratingOtherC, ratingMAC]
[ratingTotal, ratingOther, ratingMA, ratingOtherC, ratingMAC]  = security(syminfo.tickerid, res, calcRatingAll())
StrongBound = 0.5
WeakBound = 0.1
getSignal(ratingTotal, ratingOther, ratingMA) =>
    float _res = ratingTotal
    if ratingSignal == "MAs"
        _res := ratingMA
    if ratingSignal == "Oscillators"
        _res := ratingOther
    _res
tradeSignal = getSignal(ratingTotal, ratingOther, ratingMA)


poscol = input(color.blue, "Buy Color")
neutralcolor = input(color.gray, "Neutral Color")
negcol = input(color.red, "Sell Color")
poscond = tradeSignal > WeakBound
negcond = tradeSignal < -WeakBound
posseries = poscond ? tradeSignal : 0
negseries = negcond ? tradeSignal : 0
count_rising(plot) =>
    v_plot = plot > 0 ? plot : -plot
    var count = 0
    if v_plot == 0
        count := 0
    else if v_plot >= v_plot[1]
        count := min(5, count + 1)
    else if v_plot < v_plot[1]
        count := max(1, count - 1)
    count
poscount = count_rising(posseries)
negcount = count_rising(negseries)
_pc = poscond ? poscount : negcond ? negcount : 0
colorTransp(col, transp) =>
    red = color.r(col)
    green = color.g(col)
    blue = color.b(col)
    color.rgb(red, green, blue, transp)
hline(1, color=colorTransp(poscol, 50), linestyle=hline.style_solid)
hline(0.5, color=colorTransp(poscol, 50), linestyle=hline.style_dashed)
hline(-1, color=colorTransp(negcol, 50), linestyle=hline.style_solid)
hline(-0.5, color=colorTransp(negcol, 50), linestyle=hline.style_dashed)
getTimeOfNextBar() =>
    currentTime = time(timeframe.period)
    changeTime = change(currentTime)
    minChange = if (not na(changeTime))
        var float minChange = changeTime
        minChange := min(minChange, changeTime)
    int(currentTime + minChange)
drawInfo(txt, value) =>
    var info = label.new(0, 0, "", yloc = yloc.price, xloc = xloc.bar_time, textalign = text.align_left, textcolor = color.white)
    label.set_x(info, getTimeOfNextBar())
    label.set_text(info, txt)
    label.set_color(info, poscond ? poscol : negcond ? negcol : color.gray)
    label.set_style(info, label.style_label_left)
calcRatingStatus(value) =>
    if -StrongBound > value
        "Strong Sell"
    else if value < -WeakBound
        "Sell"
    else if value > StrongBound
        "Strong Buy"
    else if value > WeakBound
        "Buy"
    else
        "Neutral"
MAText = ratingMAC == 0 ? "" : "MAs:     " + calcRatingStatus(ratingMA) + "\n"
OtherText = ratingOtherC == 0 ? "" : "Oscillators: " + calcRatingStatus(ratingOther) + "\n"
TotaText = "All:  " + calcRatingStatus(ratingTotal)
drawInfo(MAText + OtherText + TotaText, tradeSignal)
col_buy = color.from_gradient(tradeSignal, 0.0, 0.2, neutralcolor, poscol)
col_sell = color.from_gradient(tradeSignal, -0.2, 0.0, negcol, neutralcolor)
col_gradient = color.from_gradient(tradeSignal, -0.2, 0.2, col_sell, col_buy)
plot(tradeSignal, title="Rating", linewidth = 1, style = plot.style_columns, color = colorTransp(col_gradient, 50 - _pc * 10))
_cond1 = crossunder(tradeSignal, -WeakBound)
alertcondition(_cond1, "Sell", "Ratings changed to Sell")
_cond2 = crossover(tradeSignal, WeakBound)
alertcondition(_cond2, "Buy", "Ratings changed to Buy")
_cond3 = crossunder(tradeSignal, -StrongBound)
alertcondition(_cond3, "Strong Sell", "Ratings changed to Strong Sell")
_cond4 = crossover(tradeSignal, StrongBound)
alertcondition(_cond4, "Strong Buy", "Ratings changed to Strong Buy")
/@version=4
研究(title=“技术评级”,shorttitle=“技术”,精度=2)
res=input(“,title=“指标时间范围”,type=input.resolution)
评级信号=输入(deffal=“All”,title=“评级基于”,选项=[“MAs”,“振荡器”,“全部”])
//很棒的振荡器
AO()=>
sma(hl2,5)-sma(hl2,34)
//随机RSI
StochRSI()=>
rsi1=rsi(闭合,14)
K=sma(stoch(rsi1,rsi1,rsi1,14),3)
D=sma(K,3)
[K,D]
//终极振荡器
tl()=>关闭[1]<低?关闭[1]:低
uo(ShortLen、MiddlLen、LongLen)=>
值1=总和(tr,ShortLen)
值2=总和(tr,MiddlLen)
值3=总和(tr,LongLen)
Value4=总和(close-tl(),ShortLen)
Value5=总和(close-tl(),MiddlLen)
值6=总和(闭合-tl(),LongLen)
浮动UO=na
如果值为1!=0和值2!=0和值3!=0
var0=长/短
var1=朗朗/米德伦
Value7=(Value4/Value1)*(var0)
Value8=(Value5/Value2)*(var1)
值9=(值6/3)
UO:=(值7+8+9)/(var0+var1+1)
UO
//一墨云
唐奇安(len)=>平均值(最低(len),最高(len))
ichimoku_cloud()=>
conversionLine=donchian(9)
基线=donchian(26)
leadLine1=平均值(在线、基线)
leadLine2=donchian(52)
[在线、基线、leadLine1、leadLine2]
calcRatingMA(ma,src)=>na(ma)或na(src)?na:(ma==src?0:(ma买?1:(卖出?-1:0)
calcRatingAll()=>
//================MA=================
SMA10=sma(闭合,10)
SMA20=sma(闭合,20)
SMA30=sma(闭合,30)
SMA50=sma(闭合,50)
SMA100=sma(闭合,100)
SMA200=sma(闭合,200)
EMA10=ema(关闭,10)
EMA20=ema(关闭,20)
均线30=均线(闭合,30)
均线50=均线(收盘,50)
EMA100=ema(关闭,100)
EMA200=ema(关闭,200)
HullMA9=hma(关闭,9)
//成交量加权移动平均值(VWMA)
VWMA=VWMA(关闭,20)
[IC_-CLine,IC_-BLine,IC_-Lead1,IC_-Lead2]=ichimoku_-cloud()
//=======其他=============
//相对强度指数
RSI=RSI(收盘,14)
//随机的
长度stoch=14
smoothKStoch=3
smoothDStoch=3
kStoch=sma(stoch(闭合、高、低、长stoch)、平滑kStoch)
dStoch=sma(kStoch,smoothDStoch)
//商品渠道指数
CCI=CCI(闭合,20)
//平均方向指数
浮点adxValue=na,浮点adxPlus=na,浮点adxMinus=na
[P,M,V]=dmi(14,14)
adxValue:=V
adxPlus:=P
adxMinus:=M
//很棒的振荡器
ao=ao()
//动力
Mom=Mom(关闭,10)
//移动平均收敛/发散,MACD
[macdMACD,signalMACD,]=macd(关闭,12,26,9)
//随机RSI
[Stoch_RSI_K,Stoch_RSI_D]=StochRSI()
//威廉姆斯百分比范围
WR=wpr(14)
//牛市/熊市力量
功率=高-均线(关闭,13)
BearPower=低-均线(关闭,13)
//终极振荡器
UO=UO(7,14,28)
如果不是na(UO)
UO:=UO*100
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
平均价格=均线(收盘价,50)
下跌趋势=收盘<平均价格
上升趋势=收盘>平均价格
//基于SMA/EMA计算交易建议
浮动比率MA=0
浮动比率MAC=0
如果不是na(SMA10)
额定值:=额定值+额定值(SMA10,关闭)
ratingMAC:=ratingMAC+1
如果不是na(SMA20)
额定值:=额定值+额定值(SMA20,关闭)
ratingMAC:=ratingMAC+1
如果不是na(SMA30)
额定值:=额定值+额定值(SMA30,关闭)
ratingMAC:=ratingMAC+1
如果不是na(SMA50)
额定值:=额定值+额定值(SMA50,关闭)
ratingMAC:=ratingMAC+1
如果不是na(SMA100)
额定值:=额定值+额定值(SMA100,关闭)
ratingMAC:=ratingMAC+1
如果不是na(SMA200)
额定值:=额定值+额定值(SMA200,关闭)
ratingMAC:=ratingMAC+1
如果不是na(EMA10)
额定值:=额定值+额定值(EMA10,关闭)
ratingMAC:=ratingMAC+1
如果不是na(EMA20)
额定值:=额定值+额定值(EMA20,关闭)
ratingMAC:=ratingMAC+1
如果不是na(EMA30)
额定值:=额定值+额定值(EMA30,关闭)
ratingMAC:=ratingMAC+1
如果不是na(EMA50)
额定值:=额定值+额定值(EMA50,关闭)
ratingMAC:=ratingMAC+1
如果不是na(EMA100)
额定值:=额定值+额定值(EMA100,关闭)
ratingMAC:=ratingMAC+1
如果不是na(EMA200)
额定值:=额定值+额定值(EMA200,关闭)
ratingMAC:=ratingMAC+1
如果不是na(HullMA9)
额定值HullMA9=calcRatingMA(HullMA9,关闭)
额定值MA:=额定值MA+额定值HULLMA9
ratingMAC:=ratingMAC+1
如果不是na(VWMA)
额定VWMA=calcRatingMA(VWMA,关闭)
额定值MA:=额定值MA+额定值VWMA
ratingMAC:=ratingMAC+1
浮动比率=na
如果不是(na(IC_导线1)或na(IC_导线2)或na(闭合)
//@version=4
study(title="Technical Ratings", shorttitle="Technicals", precision=2)
res = input("", title="Indicator Timeframe", type=input.resolution)
ratingSignal = input(defval = "All", title = "Rating is based on", options = ["MAs", "Oscillators", "All"])
// Awesome Oscillator
AO() => 
    sma(hl2, 5) - sma(hl2, 34)
// Stochastic RSI
StochRSI() =>
    rsi1 = rsi(close, 14)
    K = sma(stoch(rsi1, rsi1, rsi1, 14), 3)
    D = sma(K, 3)
    [K, D]
// Ultimate Oscillator
tl() => close[1] < low ? close[1]: low
uo(ShortLen, MiddlLen, LongLen) =>
    Value1 = sum(tr, ShortLen)
    Value2 = sum(tr, MiddlLen)
    Value3 = sum(tr, LongLen)
    Value4 = sum(close - tl(), ShortLen)
    Value5 = sum(close - tl(), MiddlLen)
    Value6 = sum(close - tl(), LongLen)
    float UO = na
    if Value1 != 0 and Value2 != 0 and Value3 != 0
        var0 = LongLen / ShortLen
        var1 = LongLen / MiddlLen
        Value7 = (Value4 / Value1) * (var0)
        Value8 = (Value5 / Value2) * (var1)
        Value9 = (Value6 / Value3)
        UO := (Value7 + Value8 + Value9) / (var0 + var1 + 1)
    UO
// Ichimoku Cloud
donchian(len) => avg(lowest(len), highest(len))
ichimoku_cloud() =>
    conversionLine = donchian(9)
    baseLine = donchian(26)
    leadLine1 = avg(conversionLine, baseLine)
    leadLine2 = donchian(52)
    [conversionLine, baseLine, leadLine1, leadLine2]
    
calcRatingMA(ma, src) => na(ma) or na(src) ? na : (ma == src ? 0 : ( ma < src ? 1 : -1 ))
calcRating(buy, sell) => buy ? 1 : ( sell ? -1 : 0 )
calcRatingAll() =>
    //============== MA =================
    SMA10 = sma(close, 10)
    SMA20 = sma(close, 20)
    SMA30 = sma(close, 30)
    SMA50 = sma(close, 50)
    SMA100 = sma(close, 100)
    SMA200 = sma(close, 200)
    
    EMA10 = ema(close, 10)
    EMA20 = ema(close, 20)
    EMA30 = ema(close, 30)
    EMA50 = ema(close, 50)
    EMA100 = ema(close, 100)
    EMA200 = ema(close, 200)
    
    HullMA9 = hma(close, 9)
    
    // Volume Weighted Moving Average (VWMA)
    VWMA = vwma(close, 20)
    
    [IC_CLine, IC_BLine, IC_Lead1, IC_Lead2] = ichimoku_cloud()
    
    // ======= Other =============
    // Relative Strength Index, RSI
    RSI = rsi(close,14)
    
    // Stochastic
    lengthStoch = 14
    smoothKStoch = 3
    smoothDStoch = 3
    kStoch = sma(stoch(close, high, low, lengthStoch), smoothKStoch)
    dStoch = sma(kStoch, smoothDStoch)
    
    // Commodity Channel Index, CCI
    CCI = cci(close, 20)
    
    // Average Directional Index
    float adxValue = na, float adxPlus = na, float adxMinus = na
    [P, M, V] = dmi(14, 14)
    adxValue := V
    adxPlus := P
    adxMinus := M
    // Awesome Oscillator
    ao = AO()
    
    // Momentum
    Mom = mom(close, 10)
    // Moving Average Convergence/Divergence, MACD
    [macdMACD, signalMACD, _] = macd(close, 12, 26, 9)
    // Stochastic RSI
    [Stoch_RSI_K, Stoch_RSI_D] = StochRSI()
    // Williams Percent Range
    WR = wpr(14)
    
    // Bull / Bear Power
    BullPower = high - ema(close, 13)
    BearPower = low - ema(close, 13)
    // Ultimate Oscillator
    UO = uo(7,14,28)
    if not na(UO)
        UO := UO * 100
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    PriceAvg = ema(close, 50)
    DownTrend = close < PriceAvg
    UpTrend = close > PriceAvg
    // calculate trading recommendation based on SMA/EMA
    float ratingMA = 0
    float ratingMAC = 0
    
    if not na(SMA10)
        ratingMA := ratingMA + calcRatingMA(SMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA20)
        ratingMA := ratingMA + calcRatingMA(SMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA30)
        ratingMA := ratingMA + calcRatingMA(SMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA50)
        ratingMA := ratingMA + calcRatingMA(SMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA100)
        ratingMA := ratingMA + calcRatingMA(SMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA200)
        ratingMA := ratingMA + calcRatingMA(SMA200, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA10)
        ratingMA := ratingMA + calcRatingMA(EMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA20)
        ratingMA := ratingMA + calcRatingMA(EMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA30)
        ratingMA := ratingMA + calcRatingMA(EMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA50)
        ratingMA := ratingMA + calcRatingMA(EMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA100)
        ratingMA := ratingMA + calcRatingMA(EMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA200)
        ratingMA := ratingMA + calcRatingMA(EMA200, close)
        ratingMAC := ratingMAC + 1
    
    if not na(HullMA9)
        ratingHullMA9 = calcRatingMA(HullMA9, close)
        ratingMA := ratingMA + ratingHullMA9
        ratingMAC := ratingMAC + 1
    
    if not na(VWMA)
        ratingVWMA = calcRatingMA(VWMA, close)
        ratingMA := ratingMA + ratingVWMA
        ratingMAC := ratingMAC + 1
    
    float ratingIC = na
    if not (na(IC_Lead1) or na(IC_Lead2) or na(close) or na(close[1]) or na(IC_BLine) or na(IC_CLine))
        ratingIC := calcRating(
         IC_Lead1 > IC_Lead2 and close > IC_Lead1 and close < IC_BLine and close[1] < IC_CLine and close > IC_CLine,
         IC_Lead2 > IC_Lead1 and close < IC_Lead2 and close > IC_BLine and close[1] > IC_CLine and close < IC_CLine)
    if not na(ratingIC)
        ratingMA := ratingMA + ratingIC
        ratingMAC := ratingMAC + 1
    
    ratingMA := ratingMAC > 0 ? ratingMA / ratingMAC : na
    
    float ratingOther = 0
    float ratingOtherC = 0
    
    ratingRSI = RSI
    if not(na(ratingRSI) or na(ratingRSI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingRSI < 30 and ratingRSI[1] < ratingRSI, ratingRSI > 70 and ratingRSI[1] > ratingRSI)
    
    if not(na(kStoch) or na(dStoch) or na(kStoch[1]) or na(dStoch[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(kStoch < 20 and dStoch < 20 and kStoch > dStoch and kStoch[1] < dStoch[1], kStoch > 80 and dStoch > 80 and kStoch < dStoch and kStoch[1] > dStoch[1])
    
    ratingCCI = CCI
    if not(na(ratingCCI) or na(ratingCCI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingCCI < -100 and ratingCCI > ratingCCI[1], ratingCCI > 100 and ratingCCI < ratingCCI[1])
    
    if not(na(adxValue) or na(adxPlus[1]) or na(adxMinus[1]) or na(adxPlus) or na(adxMinus))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(adxValue > 20 and adxPlus[1] < adxMinus[1] and adxPlus > adxMinus, adxValue > 20 and adxPlus[1] > adxMinus[1] and adxPlus < adxMinus)
    
    if not(na(ao) or na(ao[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(crossover(ao,0) or (ao > 0 and ao[1] > 0 and ao > ao[1] and ao[2] > ao[1]), crossunder(ao,0) or (ao < 0 and ao[1] < 0 and ao < ao[1] and ao[2] < ao[1]))
    
    if not(na(Mom) or na(Mom[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(Mom > Mom[1], Mom < Mom[1])
    
    if not(na(macdMACD) or na(signalMACD))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(macdMACD > signalMACD, macdMACD < signalMACD)
    
    float ratingStoch_RSI = na
    if not(na(DownTrend) or na(UpTrend) or na(Stoch_RSI_K) or na(Stoch_RSI_D) or na(Stoch_RSI_K[1]) or na(Stoch_RSI_D[1]))
        ratingStoch_RSI := calcRating(
         DownTrend and Stoch_RSI_K < 20 and Stoch_RSI_D < 20 and Stoch_RSI_K > Stoch_RSI_D and Stoch_RSI_K[1] < Stoch_RSI_D[1],
         UpTrend and Stoch_RSI_K > 80 and Stoch_RSI_D > 80 and Stoch_RSI_K < Stoch_RSI_D and Stoch_RSI_K[1] > Stoch_RSI_D[1])
    if not na(ratingStoch_RSI)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingStoch_RSI
    
    float ratingWR = na
    if not(na(WR) or na(WR[1]))
        ratingWR := calcRating(WR < -80 and WR > WR[1], WR > -20 and WR < WR[1])
    if not na(ratingWR)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingWR
    
    float ratingBBPower = na
    if not(na(UpTrend) or na(DownTrend) or na(BearPower) or na(BearPower[1]) or na(BullPower) or na(BullPower[1]))
        ratingBBPower := calcRating(
         UpTrend and BearPower < 0 and BearPower > BearPower[1],
         DownTrend and BullPower > 0 and BullPower < BullPower[1])
    if not na(ratingBBPower)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingBBPower
    
    float ratingUO = na
    if not(na(UO))
        ratingUO := calcRating(UO > 70, UO < 30)
    if not na(ratingUO)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingUO
    
    ratingOther := ratingOtherC > 0 ? ratingOther / ratingOtherC : na
    
    float ratingTotal = 0
    float ratingTotalC = 0
    if not na(ratingMA)
        ratingTotal := ratingTotal + ratingMA
        ratingTotalC := ratingTotalC + 1
    if not na(ratingOther)
        ratingTotal := ratingTotal + ratingOther
        ratingTotalC := ratingTotalC + 1
    ratingTotal := ratingTotalC > 0 ? ratingTotal / ratingTotalC : na
    
    [ratingTotal, ratingOther, ratingMA, ratingOtherC, ratingMAC]
[ratingTotal, ratingOther, ratingMA, ratingOtherC, ratingMAC]  = security(syminfo.tickerid, res, calcRatingAll())
StrongBound = 0.5
WeakBound = 0.1
getSignal(ratingTotal, ratingOther, ratingMA) =>
    float _res = ratingTotal
    if ratingSignal == "MAs"
        _res := ratingMA
    if ratingSignal == "Oscillators"
        _res := ratingOther
    _res
tradeSignal = getSignal(ratingTotal, ratingOther, ratingMA)


poscol = input(color.blue, "Buy Color")
neutralcolor = input(color.gray, "Neutral Color")
negcol = input(color.red, "Sell Color")
poscond = tradeSignal > WeakBound
negcond = tradeSignal < -WeakBound
posseries = poscond ? tradeSignal : 0
negseries = negcond ? tradeSignal : 0
count_rising(plot) =>
    v_plot = plot > 0 ? plot : -plot
    var count = 0
    if v_plot == 0
        count := 0
    else if v_plot >= v_plot[1]
        count := min(5, count + 1)
    else if v_plot < v_plot[1]
        count := max(1, count - 1)
    count
poscount = count_rising(posseries)
negcount = count_rising(negseries)
_pc = poscond ? poscount : negcond ? negcount : 0
colorTransp(col, transp) =>
    red = color.r(col)
    green = color.g(col)
    blue = color.b(col)
    color.rgb(red, green, blue, transp)
hline(1, color=colorTransp(poscol, 50), linestyle=hline.style_solid)
hline(0.5, color=colorTransp(poscol, 50), linestyle=hline.style_dashed)
hline(-1, color=colorTransp(negcol, 50), linestyle=hline.style_solid)
hline(-0.5, color=colorTransp(negcol, 50), linestyle=hline.style_dashed)
getTimeOfNextBar() =>
    currentTime = time(timeframe.period)
    changeTime = change(currentTime)
    minChange = if (not na(changeTime))
        var float minChange = changeTime
        minChange := min(minChange, changeTime)
    int(currentTime + minChange)
drawInfo(txt, value) =>
    var info = label.new(0, 0, "", yloc = yloc.price, xloc = xloc.bar_time, textalign = text.align_left, textcolor = color.white)
    label.set_x(info, getTimeOfNextBar())
    label.set_text(info, txt)
    label.set_color(info, poscond ? poscol : negcond ? negcol : color.gray)
    label.set_style(info, label.style_label_left)
calcRatingStatus(value) =>
    if -StrongBound > value
        "Strong Sell"
    else if value < -WeakBound
        "Sell"
    else if value > StrongBound
        "Strong Buy"
    else if value > WeakBound
        "Buy"
    else
        "Neutral"
MAText = ratingMAC == 0 ? "" : "MAs:     " + calcRatingStatus(ratingMA) + "\n"
OtherText = ratingOtherC == 0 ? "" : "Oscillators: " + calcRatingStatus(ratingOther) + "\n"
TotaText = "All:  " + calcRatingStatus(ratingTotal)
drawInfo(MAText + OtherText + TotaText, tradeSignal)
col_buy = color.from_gradient(tradeSignal, 0.0, 0.2, neutralcolor, poscol)
col_sell = color.from_gradient(tradeSignal, -0.2, 0.0, negcol, neutralcolor)
col_gradient = color.from_gradient(tradeSignal, -0.2, 0.2, col_sell, col_buy)
plot(tradeSignal, title="Rating", linewidth = 1, style = plot.style_columns, color = colorTransp(col_gradient, 50 - _pc * 10))
_cond1 = crossunder(tradeSignal, -WeakBound)
alertcondition(_cond1, "Sell", "Ratings changed to Sell")
_cond2 = crossover(tradeSignal, WeakBound)
alertcondition(_cond2, "Buy", "Ratings changed to Buy")
_cond3 = crossunder(tradeSignal, -StrongBound)
alertcondition(_cond3, "Strong Sell", "Ratings changed to Strong Sell")
_cond4 = crossover(tradeSignal, StrongBound)
alertcondition(_cond4, "Strong Buy", "Ratings changed to Strong Buy")