資源の読み込みに... 荷物...

マルチ・ムービング・平均格付けトレンド戦略

作者: リン・ハーンチャオチャン,日付: 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. パラメータの有効性の持続期間を観察するために半年,一年といった長いバックテスト期間を設定します

  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)

もっと