리소스 로딩... 로딩...

다중 이동평균 등급 트렌드 전략

저자:차오장, 날짜: 2023-10-17 13:11:25
태그:

img

전반적인 설명

이 전략은 다양한 유형의 이동 평균을 채택하여 여러 각도에서 가격 추세를 분석하여 개막 방향을 결정하기 위해 포괄적인 등급 신호를 형성합니다. 전략은 다음과 같은 장점을 가지고 있습니다. 1) 여러 이동 평균이 판단 정확도를 향상시키기 위해 등급 시스템을 형성합니다. 2) 다양한 품종에 적응하기 위해 등급 시스템 매개 변수 유연성 조정; 3) 위험을 제어하기 위해 구성 가능한 입시 등급 조건.

전략 논리

  1. 이 전략은 SMA, EMA, ALMA, SMMA, LSMA, VWMA, DEMA, HMA, KAMA, TEMA, ZLEMA, TRIMA, T3 등을 포함한 총 17 가지 다른 유형의 이동 평균을 사용합니다.

  2. 각 이동 평균에 대해 종료 가격과의 관계를 판단하십시오. 이동 평균이 종료 가격보다 낮다면 1 등급점을 부여하십시오. 더 높으면 -1 등급점을 부여하십시오. 결정할 수없는 경우 등급을 부여하지 마십시오.

  3. 이동 평균의 모든 등급을 합쳐서, 전체적인 등급을 얻기 위해 가등급 가능한 이동 평균의 수로 나눕니다.

  4. 전체 등급을 입력 등급의 임계값과 비교하여 개막 방향을 결정합니다. 전체 등급이 긴 임계값에 도달하면 길게 가십시오. 짧은 임계값에 도달하면 짧게 가십시오.

  5. 서로 다른 기간의 이동 평균을 채택하면 단기 및 장기 트렌드를 판단 할 수 있습니다. 다른 유형을 사용하여 다각 판단에 더 풍부한 기술적 지표를 제공합니다.

장점

  1. 여러 이동 평균 등급은 정확도를 향상시킵니다.

    단일 또는 몇 가지 이동 평균과 비교하면 전략은 17 가지 다른 이동 평균을 신용등급에 사용하며, 이는 더 많은 각도에서 시장 트렌드 방향을 더 잘 판단하여 단일 지표의 오차를 줄일 수 있습니다. 신용등급에 참여하는 여러 지표는 최종 결과의 신뢰성을 향상시킬 수 있습니다.

  2. 등급 시스템의 구성 가능한 매개 변수는 다양한 품종에 적응합니다.

    신용등급 시스템의 이동평균 기간과 신용등급 문턱은 매개 변수를 통해 구성될 수 있어 전략은 거래 품종의 다른 특성에 적응할 수 있어 최적화를 위해 유리하다.

  3. 설정 가능한 입시 등급 조건 제어 위험

    이 전략은 긴 및 짧은 엔트리 등급 문턱을 구성 할 수 있습니다. 포괄적 인 등급이 문턱에 도달 할 때만 신호가 생성되며 불분명한 시장 조건에서 잘못된 오픈을 피합니다. 합리적인 엔트리 문턱 설정은 불필요한 거래를 줄이고 위험을 제어하는 데 도움이됩니다.

위험 과 해결책

  1. 개별 품종에 대한 효과는 낮을 수 있습니다.

    이 전략의 매개 변수 설정은 전체 시장을 위해 설계되어 있으며 특정 품종에 잘 작동하지 않을 수 있습니다. 해결책은 다른 품종에 대해 매개 변수를 별도로 최적화하는 것입니다.

  2. 혼합 트렌딩 시장에서 더 높은 오류율

    이 전략은 시장이 혼합되었을 때 잘못된 신호를 생성하는 경향이 있습니다. 해결책은 그러한 시장 조건에서 거래를 줄이기 위해 입시 등급 문턱을 높이는 것입니다.

  3. 장기적인 동작을 위해 주기적인 매개 변수 최적화가 필요할 수 있습니다.

    시장 조건이 계속 변함에 따라 고정 매개 변수는 전략의 효율성을 감소시킬 수 있습니다. 전략 성과를 보장하기 위해 매시적으로 매개 변수를 다시 테스트하고 최적화하는 것이 좋습니다.

최적화 방향

  1. 등급을 위한 다른 지표, 즉 변동성 지표, 부피 지표 등을 추가하여 판단의 더 많은 차원을 제공합니다.

  2. 적응력을 향상시키기 위해 다양한 품종에 대해 매개 변수를 개별적으로 테스트하고 최적화합니다.

  3. 더 긴 백테스트 기간을 설정합니다. 반 년, 1 년, 매개 변수 효과의 기간을 관찰하기 위해.

  4. 더 나은 조합을 선택하기 위해 다른 기간에 다른 이동 평균의 실제 효과를 연구합니다.

  5. 자동으로 매개 변수를 최적화하는 기계 학습 방법을 시도해보세요.

결론

이 전략은 시장 트렌드에 대한 다각적 판단을 달성하기 위해 여러 이동 평균의 등급 시스템을 구축합니다. 다양한 품종에 유연하게 적응하고 매개 변수 조정을 통해 전략 위험을 제어 할 수있는 구성 가능한 매개 변수의 장점을 가지고 있습니다. 또한, 전략 성능을 더욱 향상시키기 위해 등급 시스템을 지속적으로 최적화하고 개선 할 수 있습니다. 일반적으로 전략은 강력한 트렌드 추적 능력을 형성하기 위해 여러 기술적 지표의 효과를 활용합니다.


/*backtest
start: 2023-10-09 00:00:00
end: 2023-10-12 02:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © exlux99

//@version=5

strategy(title='Ultra Moving Average Rating Trend Strategy', overlay=true)  //,  pyramiding=1,initial_capital = 1000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)
// //


//==========DEMA
getDEMA(src, len) =>
    dema = 2 * ta.ema(src, len) - ta.ema(ta.ema(src, len), len)
    dema
//==========HMA
getHULLMA(src, len) =>
    hullma = ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))
    hullma
//==========KAMA
getKAMA(src, len, k1, k2) =>
    change = math.abs(ta.change(src, len))
    volatility = math.sum(math.abs(ta.change(src)), len)
    efficiency_ratio = volatility != 0 ? change / volatility : 0
    kama = 0.0
    fast = 2 / (k1 + 1)
    slow = 2 / (k2 + 1)
    smooth_const = math.pow(efficiency_ratio * (fast - slow) + slow, 2)
    kama := nz(kama[1]) + smooth_const * (src - nz(kama[1]))
    kama
//==========TEMA
getTEMA(src, len) =>
    e = ta.ema(src, len)
    tema = 3 * (e - ta.ema(e, len)) + ta.ema(ta.ema(e, len), len)
    tema
//==========ZLEMA
getZLEMA(src, len) =>
    zlemalag_1 = (len - 1) / 2
    zlemadata_1 = src + src - src[zlemalag_1]
    zlema = ta.ema(zlemadata_1, len)
    zlema
//==========FRAMA
getFRAMA(src, len) =>
    Price = src
    N = len
    if N % 2 != 0
        N += 1
        N
    N1 = 0.0
    N2 = 0.0
    N3 = 0.0
    HH = 0.0
    LL = 0.0
    Dimen = 0.0
    alpha = 0.0
    Filt = 0.0
    N3 := (ta.highest(N) - ta.lowest(N)) / N
    HH := ta.highest(N / 2 - 1)
    LL := ta.lowest(N / 2 - 1)
    N1 := (HH - LL) / (N / 2)
    HH := high[N / 2]
    LL := low[N / 2]
    for i = N / 2 to N - 1 by 1
        if high[i] > HH
            HH := high[i]
            HH
        if low[i] < LL
            LL := low[i]
            LL
    N2 := (HH - LL) / (N / 2)
    if N1 > 0 and N2 > 0 and N3 > 0
        Dimen := (math.log(N1 + N2) - math.log(N3)) / math.log(2)
        Dimen
    alpha := math.exp(-4.6 * (Dimen - 1))
    if alpha < .01
        alpha := .01
        alpha
    if alpha > 1
        alpha := 1
        alpha
    Filt := alpha * Price + (1 - alpha) * nz(Filt[1], 1)
    if bar_index < N + 1
        Filt := Price
        Filt
    Filt
//==========VIDYA
getVIDYA(src, len) =>
    mom = ta.change(src)
    upSum = math.sum(math.max(mom, 0), len)
    downSum = math.sum(-math.min(mom, 0), len)
    out = (upSum - downSum) / (upSum + downSum)
    cmo = math.abs(out)
    alpha = 2 / (len + 1)
    vidya = 0.0
    vidya := src * alpha * cmo + nz(vidya[1]) * (1 - alpha * cmo)
    vidya
//==========JMA
getJMA(src, len, power, phase) =>
    phase_ratio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
    beta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)
    alpha = math.pow(beta, power)
    MA1 = 0.0
    Det0 = 0.0
    MA2 = 0.0
    Det1 = 0.0
    JMA = 0.0
    MA1 := (1 - alpha) * src + alpha * nz(MA1[1])
    Det0 := (src - MA1) * (1 - beta) + beta * nz(Det0[1])
    MA2 := MA1 + phase_ratio * Det0
    Det1 := (MA2 - nz(JMA[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(Det1[1])
    JMA := nz(JMA[1]) + Det1
    JMA
//==========T3
getT3(src, len, vFactor) =>
    ema1 = ta.ema(src, len)
    ema2 = ta.ema(ema1, len)
    ema3 = ta.ema(ema2, len)
    ema4 = ta.ema(ema3, len)
    ema5 = ta.ema(ema4, len)
    ema6 = ta.ema(ema5, len)
    c1 = -1 * math.pow(vFactor, 3)
    c2 = 3 * math.pow(vFactor, 2) + 3 * math.pow(vFactor, 3)
    c3 = -6 * math.pow(vFactor, 2) - 3 * vFactor - 3 * math.pow(vFactor, 3)
    c4 = 1 + 3 * vFactor + math.pow(vFactor, 3) + 3 * math.pow(vFactor, 2)
    T3 = c1 * ema6 + c2 * ema5 + c3 * ema4 + c4 * ema3
    T3
//==========TRIMA
getTRIMA(src, len) =>
    N = len + 1
    Nm = math.round(N / 2)
    TRIMA = ta.sma(ta.sma(src, Nm), Nm)
    TRIMA




//-------------- FUNCTIONS 
dirmov(len) =>
    up = ta.change(high)
    down = -ta.change(low)
    plusDM = na(up) ? na : up > down and up > 0 ? up : 0
    minusDM = na(down) ? na : down > up and down > 0 ? down : 0
    truerange = ta.rma(ta.tr, len)
    plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
    minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
    [plus, minus]

adx(dilen, adxlen) =>
    [plus, minus] = dirmov(dilen)
    sum = plus + minus
    adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
    adx

src = close

res = input.timeframe("", title="Indicator Timeframe")

// Ichimoku Cloud
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
ichimoku_cloud() =>
    conversionLine = donchian(9)
    baseLine = donchian(26)
    leadLine1 = math.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 = ta.sma(close, 10)
    SMA20 = ta.sma(close, 20)
    SMA30 = ta.sma(close, 30)
    SMA50 = ta.sma(close, 50)
    SMA100 = ta.sma(close, 100)
    SMA200 = ta.sma(close, 200)

    EMA10 = ta.ema(close, 10)
    EMA20 = ta.ema(close, 20)
    EMA30 = ta.ema(close, 30)
    EMA50 = ta.ema(close, 50)
    EMA100 = ta.ema(close, 100)
    EMA200 = ta.ema(close, 200)
    
    ALMA10 = ta.alma(close, 10, 0.85, 6)
    ALMA20 = ta.alma(close, 20, 0.85, 6)
    ALMA50 = ta.alma(close, 50, 0.85, 6)
    ALMA100 = ta.alma(close, 100, 0.85, 6)
    ALMA200 = ta.alma(close, 200, 0.85, 6)
    
    SMMA10 = ta.rma(close, 10)
    SMMA20 = ta.rma(close, 20)
    SMMA50 = ta.rma(close, 50)
    SMMA100 = ta.rma(close, 100)
    SMMA200 = ta.rma(close, 200)

    LSMA10 = ta.linreg(close, 10, 0)
    LSMA20 = ta.linreg(close, 20, 0)
    LSMA50 = ta.linreg(close, 50, 0)
    LSMA100 = ta.linreg(close, 100, 0)
    LSMA200 = ta.linreg(close, 200, 0)

    VWMA10 = ta.vwma(close, 10)
    VWMA20 = ta.vwma(close, 20)
    VWMA50 = ta.vwma(close, 50)
    VWMA100 = ta.vwma(close, 100)
    VWMA200 = ta.vwma(close, 200)

    DEMA10 = getDEMA(close, 10)
    DEMA20 = getDEMA(close, 20)
    DEMA50 = getDEMA(close, 50)
    DEMA100 =getDEMA(close, 100)
    DEMA200 = getDEMA(close, 200)
    
    HMA10 =  ta.hma(close, 10)
    HMA20 =  ta.hma(close, 20)
    HMA50 =  ta.hma(close, 50)
    HMA100 = ta.hma(close, 100)
    HMA200 = ta.hma(close, 200)
    
    KAMA10 =   getKAMA(close, 10, 2, 30)
    KAMA20 =   getKAMA(close, 20, 2, 30)
    KAMA50 =   getKAMA(close, 50, 2, 30)
    KAMA100 =  getKAMA(close, 100, 2, 30)
    KAMA200 =  getKAMA(close, 200 , 2, 30)
    
    FRAMA10 = getFRAMA(close, 10)
    FRAMA20 = getFRAMA(close, 20)
    FRAMA50 = getFRAMA(close, 50)
    FRAMA100 =getFRAMA(close, 100)
    FRAMA200 = getFRAMA(close, 200)

    VIDMA10 = getVIDYA(close, 10)
    VIDMA20 = getVIDYA(close, 20)
    VIDMA50 = getVIDYA(close, 50)
    VIDMA100 =getVIDYA(close, 100)
    VIDMA200 = getVIDYA(close, 200)
    
    JMA10 = getJMA(close, 10, 2, 50)
    JMA20 = getJMA(close, 20, 2, 50)
    JMA50 = getJMA(close, 50, 2, 50)
    JMA100 =getJMA(close, 100, 2, 50)
    JMA200 = getJMA(close, 200, 2, 50)
    
    TEMA10 = getTEMA(close, 10)
    TEMA20 = getTEMA(close, 20)
    TEMA50 = getTEMA(close, 50)
    TEMA100 =getTEMA(close, 100)
    TEMA200 = getTEMA(close, 200)
    
    ZLEMA10 = getZLEMA(close, 10)
    ZLEMA20 = getZLEMA(close, 20)
    ZLEMA50 = getZLEMA(close, 50)
    ZLEMA100 =getZLEMA(close, 100)
    ZLEMA200 = getZLEMA(close, 200)
    
    TRIMA10 = getTRIMA(close, 10)
    TRIMA20 = getTRIMA(close, 20)
    TRIMA50 = getTRIMA(close, 50)
    TRIMA100 =getTRIMA(close, 100)
    TRIMA200 = getTRIMA(close, 200)
    
    T3MA10 = getT3(close, 10, 0.7)
    T3MA20 = getT3(close, 20, 0.7)
    T3MA50 = getT3(close, 50, 0.7)
    T3MA100 =getT3(close, 100, 0.7)
    T3MA200 = getT3(close, 200, 0.7)
    
    [IC_CLine, IC_BLine, IC_Lead1, IC_Lead2] = ichimoku_cloud()

 
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    PriceAvg = ta.ema(close, 50)
    DownTrend = close < PriceAvg
    UpTrend = close > PriceAvg
    // calculate trading recommendation based on SMA/EMA
    float ratingMA = 0
    float ratingMAC = 0

    float ratingSMA10 = na
    if not na(SMA10)
        ratingSMA10 := calcRatingMA(SMA10, close)
        ratingMA := ratingMA + ratingSMA10
        ratingMAC := ratingMAC + 1
    float ratingSMA20 = na
    if not na(SMA20)
        ratingSMA20 := calcRatingMA(SMA20, close)
        ratingMA := ratingMA + ratingSMA20
        ratingMAC := ratingMAC + 1
    float ratingSMA30 = na
    if not na(SMA30)
        ratingSMA30 := calcRatingMA(SMA30, close)
        ratingMA := ratingMA + ratingSMA30
        ratingMAC := ratingMAC + 1
    float ratingSMA50 = na
    if not na(SMA50)
        ratingSMA50 := calcRatingMA(SMA50, close)
        ratingMA := ratingMA + ratingSMA50
        ratingMAC := ratingMAC + 1
    float ratingSMA100 = na
    if not na(SMA100)
        ratingSMA100 := calcRatingMA(SMA100, close)
        ratingMA := ratingMA + ratingSMA100
        ratingMAC := ratingMAC + 1
    float ratingSMA200 = na
    if not na(SMA200)
        ratingSMA200 := calcRatingMA(SMA200, close)
        ratingMA := ratingMA + ratingSMA200
        ratingMAC := ratingMAC + 1

    float ratingEMA10 = na
    if not na(EMA10)
        ratingEMA10 := calcRatingMA(EMA10, close)
        ratingMA := ratingMA + ratingEMA10
        ratingMAC := ratingMAC + 1
    float ratingEMA20 = na
    if not na(EMA20)
        ratingEMA20 := calcRatingMA(EMA20, close)
        ratingMA := ratingMA + ratingEMA20
        ratingMAC := ratingMAC + 1
    float ratingEMA30 = na
    if not na(EMA30)
        ratingEMA30 := calcRatingMA(EMA30, close)
        ratingMA := ratingMA + ratingEMA30
        ratingMAC := ratingMAC + 1
    float ratingEMA50 = na
    if not na(EMA50)
        ratingEMA50 := calcRatingMA(EMA50, close)
        ratingMA := ratingMA + ratingEMA50
        ratingMAC := ratingMAC + 1
    float ratingEMA100 = na
    if not na(EMA100)
        ratingEMA100 := calcRatingMA(EMA100, close)
        ratingMA := ratingMA + ratingEMA100
        ratingMAC := ratingMAC + 1
    float ratingEMA200 = na
    if not na(EMA200)
        ratingEMA200 := calcRatingMA(EMA200, close)
        ratingMA := ratingMA + ratingEMA200
        ratingMAC := ratingMAC + 1

///////////////////////////
    float ratingALMA10 = na
    if not na(ALMA10)
        ratingALMA10 := calcRatingMA(ALMA10, close)
        ratingMA := ratingMA + ratingALMA10
        ratingMAC := ratingMAC + 1
        
    float ratingALMA20 = na
    if not na(ALMA20)
        ratingALMA20 := calcRatingMA(ALMA20, close)
        ratingMA := ratingMA + ratingALMA20
        ratingMAC := ratingMAC + 1
        
    float ratingALMA50 = na
    if not na(ALMA50)
        ratingALMA50 := calcRatingMA(ALMA50, close)
        ratingMA := ratingMA + ratingALMA50
        ratingMAC := ratingMAC + 1
        
    float ratingALMA100 = na
    if not na(ALMA100)
        ratingALMA100 := calcRatingMA(ALMA100, close)
        ratingMA := ratingMA + ratingALMA100
        ratingMAC := ratingMAC + 1

    float ratingALMA200 = na
    if not na(ALMA200)
        ratingALMA200 := calcRatingMA(ALMA200, close)
        ratingMA := ratingMA + ratingALMA200
        ratingMAC := ratingMAC + 1


/////////////////////////

///////////////////////////
///////////////////////////
    float ratingSMMA10 = na
    if not na(SMMA10)
        ratingSMMA10 := calcRatingMA(SMMA10, close)
        ratingMA := ratingMA + ratingSMMA10
        ratingMAC := ratingMAC + 1
        
    float ratingSMMA20 = na
    if not na(SMMA20)
        ratingSMMA20 := calcRatingMA(SMMA20, close)
        ratingMA := ratingMA + ratingSMMA20
        ratingMAC := ratingMAC + 1
        
    float ratingSMMA50 = na
    if not na(SMMA50)
        ratingSMMA50 := calcRatingMA(SMMA50, close)
        ratingMA := ratingMA + ratingSMMA50
        ratingMAC := ratingMAC + 1
        
    float ratingSMMA100 = na
    if not na(SMMA100)
        ratingSMMA100 := calcRatingMA(SMMA100, close)
        ratingMA := ratingMA + ratingSMMA100
        ratingMAC := ratingMAC + 1

    float ratingSMMA200 = na
    if not na(SMMA200)
        ratingSMMA200 := calcRatingMA(SMMA200, close)
        ratingMA := ratingMA + ratingSMMA200
        ratingMAC := ratingMAC + 1


/////////////////////////

///////////////////////////
///////////////////////////
    float ratingLSMA10 = na
    if not na(LSMA10)
        ratingLSMA10 := calcRatingMA(LSMA10, close)
        ratingMA := ratingMA + ratingLSMA10
        ratingMAC := ratingMAC + 1
        
    float ratingLSMA20 = na
    if not na(LSMA20)
        ratingLSMA20 := calcRatingMA(LSMA20, close)
        ratingMA := ratingMA + ratingLSMA20
        ratingMAC := ratingMAC + 1
        
    float ratingLSMA50 = na
    if not na(LSMA50)
        ratingLSMA50 := calcRatingMA(LSMA50, close)
        ratingMA := ratingMA + ratingLSMA50
        ratingMAC := ratingMAC + 1
        
    float ratingLSMA100 = na
    if not na(LSMA100)
        ratingLSMA100 := calcRatingMA(LSMA100, close)
        ratingMA := ratingMA + ratingLSMA100
        ratingMAC := ratingMAC + 1

    float ratingLSMA200 = na
    if not na(LSMA200)
        ratingLSMA200 := calcRatingMA(LSMA200, close)
        ratingMA := ratingMA + ratingLSMA200
        ratingMAC := ratingMAC + 1


/////////////////////////

///////////////////////////
///////////////////////////
    float ratingVWMA10 = na
    if not na(VWMA10)
        ratingVWMA10 := calcRatingMA(VWMA10, close)
        ratingMA := ratingMA + ratingVWMA10
        ratingMAC := ratingMAC + 1
        
    float ratingVWMA20 = na
    if not na(VWMA20)
        ratingVWMA20 := calcRatingMA(VWMA20, close)
        ratingMA := ratingMA + ratingVWMA20
        ratingMAC := ratingMAC + 1
        
    float ratingVWMA50 = na
    if not na(VWMA50)
        ratingVWMA50 := calcRatingMA(VWMA50, close)
        ratingMA := ratingMA + ratingVWMA50
        ratingMAC := ratingMAC + 1
        
    float ratingVWMA100 = na
    if not na(VWMA100)
        ratingVWMA100 := calcRatingMA(VWMA100, close)
        ratingMA := ratingMA + ratingVWMA100
        ratingMAC := ratingMAC + 1

    float ratingVWMA200 = na
    if not na(VWMA200)
        ratingVWMA200 := calcRatingMA(VWMA200, close)
        ratingMA := ratingMA + ratingVWMA200
        ratingMAC := ratingMAC + 1


/////////////////////////

///////////////////////////
///////////////////////////
    float ratingDEMA10 = na
    if not na(DEMA10)
        ratingDEMA10 := calcRatingMA(DEMA10, close)
        ratingMA := ratingMA + ratingDEMA10
        ratingMAC := ratingMAC + 1
        
    float ratingDEMA20 = na
    if not na(DEMA20)
        ratingDEMA20 := calcRatingMA(DEMA20, close)
        ratingMA := ratingMA + ratingDEMA20
        ratingMAC := ratingMAC + 1
        
    float ratingDEMA50 = na
    if not na(DEMA50)
        ratingDEMA50 := calcRatingMA(DEMA50, close)
        ratingMA := ratingMA + ratingDEMA50
        ratingMAC := ratingMAC + 1
        
    float ratingDEMA100 = na
    if not na(DEMA100)
        ratingDEMA100 := calcRatingMA(DEMA100, close)
        ratingMA := ratingMA + ratingDEMA100
        ratingMAC := ratingMAC + 1

    float ratingDEMA200 = na
    if not na(DEMA200)
        ratingDEMA200 := calcRatingMA(DEMA200, close)
        ratingMA := ratingMA + ratingDEMA200
        ratingMAC := ratingMAC + 1

/////////////////////////
///////////////////////////
    float ratingHMA10 = na
    if not na(HMA10)
        ratingHMA10 := calcRatingMA(HMA10, close)
        ratingMA := ratingMA + ratingHMA10
        ratingMAC := ratingMAC + 1
        
    float ratingHMA20 = na
    if not na(HMA20)
        ratingHMA20 := calcRatingMA(HMA20, close)
        ratingMA := ratingMA + ratingHMA20
        ratingMAC := ratingMAC + 1
        
    float ratingHMA50 = na
    if not na(HMA50)
        ratingHMA50 := calcRatingMA(HMA50, close)
        ratingMA := ratingMA + ratingHMA50
        ratingMAC := ratingMAC + 1
        
    float ratingHMA100 = na
    if not na(HMA100)
        ratingHMA100 := calcRatingMA(HMA100, close)
        ratingMA := ratingMA + ratingHMA100
        ratingMAC := ratingMAC + 1

    float ratingHMA200 = na
    if not na(HMA200)
        ratingHMA200 := calcRatingMA(HMA200, close)
        ratingMA := ratingMA + ratingHMA200
        ratingMAC := ratingMAC + 1
/////////////////////////
///////////////////////////
///////////////////////////
    float ratingKAMA10 = na
    if not na(KAMA10)
        ratingKAMA10 := calcRatingMA(KAMA10, close)
        ratingMA := ratingMA + ratingKAMA10
        ratingMAC := ratingMAC + 1
        
    float ratingKAMA20 = na
    if not na(KAMA20)
        ratingKAMA20 := calcRatingMA(KAMA20, close)
        ratingMA := ratingMA + ratingKAMA20
        ratingMAC := ratingMAC + 1
        
    float ratingKAMA50 = na
    if not na(KAMA50)
        ratingKAMA50 := calcRatingMA(KAMA50, close)
        ratingMA := ratingMA + ratingKAMA50
        ratingMAC := ratingMAC + 1
        
    float ratingKAMA100 = na
    if not na(KAMA100)
        ratingKAMA100 := calcRatingMA(KAMA100, close)
        ratingMA := ratingMA + ratingKAMA100
        ratingMAC := ratingMAC + 1

    float ratingKAMA200 = na
    if not na(KAMA200)
        ratingKAMA200 := calcRatingMA(KAMA200, close)
        ratingMA := ratingMA + ratingKAMA200
        ratingMAC := ratingMAC + 1
/////////////////////////
///////////////////////////
///////////////////////////
    float ratingFRAMA10 = na
    if not na(FRAMA10)
        ratingFRAMA10 := calcRatingMA(FRAMA10, close)
        ratingMA := ratingMA + ratingFRAMA10
        ratingMAC := ratingMAC + 1
        
    float ratingFRAMA20 = na
    if not na(FRAMA20)
        ratingFRAMA20 := calcRatingMA(FRAMA20, close)
        ratingMA := ratingMA + ratingFRAMA20
        ratingMAC := ratingMAC + 1
        
    float ratingFRAMA50 = na
    if not na(FRAMA50)
        ratingFRAMA50 := calcRatingMA(FRAMA50, close)
        ratingMA := ratingMA + ratingFRAMA50
        ratingMAC := ratingMAC + 1
        
    float ratingFRAMA100 = na
    if not na(FRAMA100)
        ratingFRAMA100 := calcRatingMA(FRAMA100, close)
        ratingMA := ratingMA + ratingFRAMA100
        ratingMAC := ratingMAC + 1

    float ratingFRAMA200 = na
    if not na(FRAMA200)
        ratingFRAMA200 := calcRatingMA(FRAMA200, close)
        ratingMA := ratingMA + ratingFRAMA200
        ratingMAC := ratingMAC + 1
/////////////////////////
///////////////////////////
///////////////////////////
    float ratingVIDMA10 = na
    if not na(VIDMA10)
        ratingVIDMA10 := calcRatingMA(VIDMA10, close)
        ratingMA := ratingMA + ratingVIDMA10
        ratingMAC := ratingMAC + 1
        
    float ratingVIDMA20 = na
    if not na(VIDMA20)
        ratingVIDMA20 := calcRatingMA(VIDMA20, close)
        ratingMA := ratingMA + ratingVIDMA20
        ratingMAC := ratingMAC + 1
        
    float ratingVIDMA50 = na
    if not na(VIDMA50)
        ratingVIDMA50 := calcRatingMA(VIDMA50, close)
        ratingMA := ratingMA + ratingVIDMA50
        ratingMAC := ratingMAC + 1
        
    float ratingVIDMA100 = na
    if not na(VIDMA100)
        ratingVIDMA100 := calcRatingMA(VIDMA100, close)
        ratingMA := ratingMA + ratingVIDMA100
        ratingMAC := ratingMAC + 1

    float ratingVIDMA200 = na   
    if not na(VIDMA200)
        ratingVIDMA200 := calcRatingMA(VIDMA200, close)
        ratingMA := ratingMA + ratingVIDMA200
        ratingMAC := ratingMAC + 1
/////////////////////////
///////////////////////////
    float ratingJMA10 = na
    if not na(JMA10)
        ratingJMA10 := calcRatingMA(JMA10, close)
        ratingMA := ratingMA + ratingJMA10
        ratingMAC := ratingMAC + 1
        
    float ratingJMA20 = na
    if not na(JMA20)
        ratingJMA20 := calcRatingMA(JMA20, close)
        ratingMA := ratingMA + ratingJMA20
        ratingMAC := ratingMAC + 1
        
    float ratingJMA50 = na
    if not na(JMA50)
        ratingJMA50 := calcRatingMA(JMA50, close)
        ratingMA := ratingMA + ratingJMA50
        ratingMAC := ratingMAC + 1
        
    float ratingJMA100 = na
    if not na(JMA100)
        ratingJMA100 := calcRatingMA(JMA100, close)
        ratingMA := ratingMA + ratingJMA100
        ratingMAC := ratingMAC + 1

    float ratingJMA200 = na
    if not na(JMA200)
        ratingJMA200 := calcRatingMA(JMA200, close)
        ratingMA := ratingMA + ratingJMA200
        ratingMAC := ratingMAC + 1
/////////////////////////
///////////////////////////
///////////////////////////
    float ratingTEMA10 = na
    if not na(TEMA10)
        ratingTEMA10 := calcRatingMA(TEMA10, close)
        ratingMA := ratingMA + ratingTEMA10
        ratingMAC := ratingMAC + 1
        
    float ratingTEMA20 = na
    if not na(TEMA20)
        ratingTEMA20 := calcRatingMA(TEMA20, close)
        ratingMA := ratingMA + ratingTEMA20
        ratingMAC := ratingMAC + 1
        
    float ratingTEMA50 = na
    if not na(TEMA50)
        ratingTEMA50 := calcRatingMA(TEMA50, close)
        ratingMA := ratingMA + ratingTEMA50
        ratingMAC := ratingMAC + 1
        
    float ratingTEMA100 = na
    if not na(TEMA100)
        ratingTEMA100 := calcRatingMA(TEMA100, close)
        ratingMA := ratingMA + ratingTEMA100
        ratingMAC := ratingMAC + 1

    float ratingTEMA200 = na
    if not na(TEMA200)
        ratingTEMA200 := calcRatingMA(TEMA200, close)
        ratingMA := ratingMA + ratingTEMA200
        ratingMAC := ratingMAC + 1
/////////////////////////
///////////////////////////
    float ratingZLEMA10 = na
    if not na(ZLEMA10)
        ratingZLEMA10 := calcRatingMA(ZLEMA10, close)
        ratingMA := ratingMA + ratingZLEMA10
        ratingMAC := ratingMAC + 1
        
    float ratingZLEMA20 = na
    if not na(ZLEMA20)
        ratingZLEMA20 := calcRatingMA(ZLEMA20, close)
        ratingMA := ratingMA + ratingZLEMA20
        ratingMAC := ratingMAC + 1
        
    float ratingZLEMA50 = na
    if not na(ZLEMA50)
        ratingZLEMA50 := calcRatingMA(ZLEMA50, close)
        ratingMA := ratingMA + ratingZLEMA50
        ratingMAC := ratingMAC + 1
        
    float ratingZLEMA100 = na
    if not na(ZLEMA100)
        ratingZLEMA100 := calcRatingMA(ZLEMA100, close)
        ratingMA := ratingMA + ratingZLEMA100
        ratingMAC := ratingMAC + 1

    float ratingZLEMA200 = na
    if not na(ZLEMA200)
        ratingZLEMA200 := calcRatingMA(ZLEMA200, close)
        ratingMA := ratingMA + ratingZLEMA200
        ratingMAC := ratingMAC + 1
/////////////////////////

///////////////////////////
///////////////////////////
    float ratingTRIMA10 = na
    if not na(TRIMA10)
        ratingTRIMA10 := calcRatingMA(TRIMA10, close)
        ratingMA := ratingMA + ratingTRIMA10
        ratingMAC := ratingMAC + 1
        
    float ratingTRIMA20 = na
    if not na(TRIMA20)
        ratingTRIMA20 := calcRatingMA(TRIMA20, close)
        ratingMA := ratingMA + ratingTRIMA20
        ratingMAC := ratingMAC + 1
        
    float ratingTRIMA50 = na
    if not na(TRIMA50)
        ratingTRIMA50 := calcRatingMA(TRIMA50, close)
        ratingMA := ratingMA + ratingTRIMA50
        ratingMAC := ratingMAC + 1
        
    float ratingTRIMA100 = na
    if not na(TRIMA100)
        ratingTRIMA100 := calcRatingMA(TRIMA100, close)
        ratingMA := ratingMA + ratingTRIMA100
        ratingMAC := ratingMAC + 1

    float ratingTRIMA200 = na
    if not na(TRIMA200)
        ratingTRIMA200 := calcRatingMA(TRIMA200, close)
        ratingMA := ratingMA + ratingTRIMA200
        ratingMAC := ratingMAC + 1
/////////////////////////
///////////////////////////
    float ratingT3MA10 = na
    if not na(T3MA10)
        ratingT3MA10 := calcRatingMA(T3MA10, close)
        ratingMA := ratingMA + ratingT3MA10
        ratingMAC := ratingMAC + 1
        
    float ratingT3MA20 = na
    if not na(T3MA20)
        ratingT3MA20 := calcRatingMA(T3MA20, close)
        ratingMA := ratingMA + ratingT3MA20
        ratingMAC := ratingMAC + 1
        
    float ratingT3MA50 = na
    if not na(T3MA50)
        ratingT3MA50 := calcRatingMA(T3MA50, close)
        ratingMA := ratingMA + ratingT3MA50
        ratingMAC := ratingMAC + 1
        
    float ratingT3MA100 = na
    if not na(T3MA100)
        ratingT3MA100 := calcRatingMA(T3MA100, close)
        ratingMA := ratingMA + ratingT3MA100
        ratingMAC := ratingMAC + 1

    float ratingT3MA200 = na
    if not na(T3MA200)
        ratingT3MA200 := calcRatingMA(T3MA200, close)
        ratingMA := ratingMA + ratingT3MA200
        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 ratingTotal = 0
    float ratingTotalC = 0
    if not na(ratingMA)
        ratingTotal := ratingTotal + ratingMA
        ratingTotalC := ratingTotalC + 1
    ratingTotal := ratingTotalC > 0 ? ratingTotal / ratingTotalC : na

    [ratingTotal,  ratingMA]



getSignal2(ratingTotal,  ratingMA) =>
    float _res = ratingTotal
    _res := ratingMA

    
[ratingTotal, ratingMA]  = request.security(syminfo.tickerid, res, calcRatingAll())
tradeSignal = getSignal2(ratingTotal,  ratingMA)


rating_entry = input.float(0.95, title='Rating for long', group="Entry Rating %", step=0.05)
rating_exit = input.float(0.75, title='Rating for short', group="Entry Rating %", step=0.05) * -1

long = tradeSignal >= rating_entry  
short = tradeSignal <= rating_exit


strategy.entry("long",strategy.long,when=long)
strategy.entry('short',strategy.short,when=short)

더 많은