Conversión indicador Gaussian Channel with the Best Setting tradingview

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #231650 quote
    jesus1975jesus1975
    Participant
    Veteran

    Solicito, si es posible, convertir el indicador adjunto. Tiene buena pinta, se adapta muy bien tanto a tendencias cortas como más largas.

    https://www.tradingview.com/script/WC5Ekkc9-Gaussian-Channel-with-the-Best-Setting/

    Muchas gracias.

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © Kebeng
    
    //@version=4
    study(title="Gaussian Channel with the Best Setting", shorttitle="GC Best Setting", overlay=true)
    
    //Filter function 
    f_filt9x (_a, _s, _i) => 
        int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0, 
        int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = .0, _x = (1 - _a)
        // Weights. 
        // Initial weight _m1 is a pole number and equal to _i
        _m2 := _i == 9 ? 36  : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ? 10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
        _m3 := _i == 9 ? 84  : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ? 10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
        _m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5  : _i == 4 ? 1 : 0
        _m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6  : _i == 5 ? 1  : 0 
        _m6 := _i == 9 ? 84  : _i == 8 ? 28 : _i == 7 ? 7  : _i == 6 ? 1  : 0 
        _m7 := _i == 9 ? 36  : _i == 8 ? 8  : _i == 7 ? 1  : 0 
        _m8 := _i == 9 ? 9   : _i == 8 ? 1  : 0 
        _m9 := _i == 9 ? 1   : 0
        // filter
        _f :=   pow(_a, _i) * nz(_s) + 
          _i  *     _x      * nz(_f[1])      - (_i >= 2 ? 
          _m2 * pow(_x, 2)  * nz(_f[2]) : 0) + (_i >= 3 ? 
          _m3 * pow(_x, 3)  * nz(_f[3]) : 0) - (_i >= 4 ? 
          _m4 * pow(_x, 4)  * nz(_f[4]) : 0) + (_i >= 5 ? 
          _m5 * pow(_x, 5)  * nz(_f[5]) : 0) - (_i >= 6 ? 
          _m6 * pow(_x, 6)  * nz(_f[6]) : 0) + (_i >= 7 ? 
          _m7 * pow(_x, 7)  * nz(_f[7]) : 0) - (_i >= 8 ? 
          _m8 * pow(_x, 8)  * nz(_f[8]) : 0) + (_i == 9 ? 
          _m9 * pow(_x, 9)  * nz(_f[9]) : 0)
    
    //9 var declaration fun
    f_pole (_a, _s, _i) =>
        _f1 =            f_filt9x(_a, _s, 1),      _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2) : 0), _f3 = (_i >= 3 ? f_filt9x(_a, _s, 3) : 0)
        _f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5) : 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0)
        _f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8) : 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0)
        _fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 :
          _i == 4     ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 :
          _i == 7     ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
        [_fn, _f1]
    
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
    //Inputs
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    //Source
    src = input(defval=hlc3, title="Source")
    
    //Poles
    int N = input(defval=3, title="Poles", minval=1, maxval=9)
    
    //Period
    int per = input(defval=100, title="Sampling Period", minval=2)
    
    //True Range Multiplier
    float mult = input(defval=2.414, title="Filtered True Range Multiplier", minval=0)
    
    //Lag Reduction
    bool modeLag  = input(defval=false, title="Reduced Lag Mode")
    bool modeFast = input(defval=false, title="Fast Response Mode")
    
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
    //Definitions
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    //Beta and Alpha Components
    beta  = (1 - cos(4*asin(1)/per)) / (pow(1.414, 2/N) - 1)
    alpha = - beta + sqrt(pow(beta, 2) + 2*beta)
    
    //Lag
    lag = (per - 1)/(2*N)
    
    //Data
    srcdata = modeLag ? src + (src - src[lag]) : src
    trdata  = modeLag ? tr(true) + (tr(true) - tr(true)[lag]) : tr(true)
    
    //Filtered Values
    [filtn, filt1]     = f_pole(alpha, srcdata, N)
    [filtntr, filt1tr] = f_pole(alpha, trdata,  N)
    
    //Lag Reduction
    filt   = modeFast ? (filtn + filt1)/2 : filtn
    filttr = modeFast ? (filtntr + filt1tr)/2 : filtntr
    
    //Bands
    hband = filt + filttr*mult
    lband = filt - filttr*mult
    
    // Colors
    color1   = #0aff68
    color2   = #00752d
    color3   = #ff0a5a
    color4   = #990032
    fcolor   = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
    barcolor = (src > src[1]) and (src > filt) and (src < hband) ? #0aff68 : (src > src[1]) and (src >= hband) ? #0aff1b : (src <= src[1]) and (src > filt) ? #00752d : 
               (src < src[1]) and (src < filt) and (src > lband) ? #ff0a5a : (src < src[1]) and (src <= lband) ? #ff0a11 : (src >= src[1]) and (src < filt) ? #990032 : #cccccc
    
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
    //Outputs
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    //Filter Plot
    filtplot = plot(filt, title="Filter", color=fcolor, linewidth=3)
    
    //Band Plots
    hbandplot = plot(hband, title="Filtered True Range High Band", color=fcolor)
    lbandplot = plot(lband, title="Filtered True Range Low Band", color=fcolor)
    
    //Channel Fill
    fill(hbandplot, lbandplot, title="Channel Fill", color=fcolor, transp=80)
    
    //Bar Color
    barcolor(barcolor)
    
    #231705 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Hola
    Aquí tienes el código traducido:
    https://www.prorealcode.com/prorealtime-indicators/gaussian-channel-indicator-key-to-identifying-trends-and-volatility/

    //-----------------------------------------------------------//
    //PRC_Gaussian Channel
    //version = 0
    //19.04.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-----------------------------------------------------------//
    //-----Inputs------------------------------------------------//
    source=(high+low+close)/3
    N=4//Poles
    per=144//Sampling period
    mult=1.414//True Range multiplier
    modelag=0//Boolean//Reduced Lag Mode
    colorcandle=0//Boolean//Color Candles
    colorchannel=1//Boolean//Color Channel
    //-----------------------------------------------------------//
    //-----Beta and Alpha components-----------------------------//
    beta = (1-cos(4*asin(1)/per))/(pow(1.414,2/N)-1)
    alpha = - beta + SQRT(pow(beta,2) + 2*beta)
    lag = round((per-1)/(2*N))
    //-----------------------------------------------------------//
    //-----Data--------------------------------------------------//
    if modelag then
    if barindex <= lag then
    src=source
    trdate=tr
    else
    src=source+(source-source[lag])
    trdata=tr+(tr-tr[lag])
    endif
    else
    src=source
    trdata=tr
    endif
    //-----------------------------------------------------------//
    //-----Filtered Values---------------------------------------//
    //[filtn, filt1] = f_pole(alpha, srcdata, N)
    //f_filt9x (alpha, srcdata, N)
    x=1-alpha
    if N=9 then
    m2=36
    m3=84
    m4=126
    m5=126
    m6=84
    m7=36
    m8=9
    m9=1
    elsif N=8 then
    m2=28
    m3=56
    m4=70
    m5=56
    m6=28
    m7=8
    m8=1
    m9=0
    elsif N=7 then
    m2=21
    m3=35
    m4=35
    m5=21
    m6=7
    m7=1
    m8=0
    m9=0
    elsif N=6 then
    m2=15
    m3=20
    m4=15
    m5=6
    m6=1
    m7=0
    m8=0
    m9=0
    elsif N=5 then
    m2=10
    m3=10
    m4=5
    m5=1
    m6=0
    m7=0
    m8=0
    m9=0
    elsif N=4 then
    m2=6
    m3=4
    m4=1
    m5=0
    m6=0
    m7=0
    m8=0
    m9=0
    elsif N=3 then
    m2=3
    m3=1
    m4=0
    m5=0
    m6=0
    m7=0
    m8=0
    m9=0
    elsif N=2 then
    m2=1
    m3=0
    m4=0
    m5=0
    m6=0
    m7=0
    m8=0
    m9=0
    endif
    if barindex <=N then
    f1=0
    f2=0
    f3=0
    f4=0
    f5=0
    f6=0
    f7=0
    f8=0
    f9=0
    filtN=0
    filttrN=0
    else
    if N=9 then
    
    f9= pow(alpha,N) * src+N*x*f9[1] - m2*pow(x,2)*f9[2] + m3*pow(x,3)*f9[3] - m4*pow(x,4)*f9[4] + m5*pow(x,5)*f9[5] - m6*pow(x,6)*f9[6] + m7*pow(x,7)*f9[7] - m8*pow(x,8)*f9[8] + m9*pow(x,9)*f9[9]
    filtN=f9
    
    ftr9= pow(alpha,N) * trdata+N*x*ftr9[1] - m2*pow(x,2)*ftr9[2] + m3*pow(x,3)*ftr9[3] - m4*pow(x,4)*ftr9[4] + m5*pow(x,5)*ftr9[5] - m6*pow(x,6)*ftr9[6] + m7*pow(x,7)*ftr9[7] - m8*pow(x,8)*ftr9[8] + m9*pow(x,9)*ftr9[9]
    filttrN=ftr9
    
    elsif N=8 then
    
    f8= pow(alpha,N) * src+N*x*f8[1] - m2*pow(x,2)*f8[2] + m3*pow(x,3)*f8[3] - m4*pow(x,4)*f8[4] + m5*pow(x,5)*f8[5] - m6*pow(x,6)*f8[6] + m7*pow(x,7)*f8[7] - m8*pow(x,8)*f8[8]
    filtN=f8
    
    ftr8= pow(alpha,N) * trdata+N*x*ftr8[1] - m2*pow(x,2)*ftr8[2] + m3*pow(x,3)*ftr8[3] - m4*pow(x,4)*ftr8[4] + m5*pow(x,5)*ftr8[5] - m6*pow(x,6)*ftr8[6] + m7*pow(x,7)*ftr8[7] - m8*pow(x,8)*ftr8[8]
    filttrN=ftr8
    
    elsif N=7 then
    
    f7= pow(alpha,N) * src+N*x*f7[1] - m2*pow(x,2)*f7[2] + m3*pow(x,3)*f7[3] - m4*pow(x,4)*f7[4] + m5*pow(x,5)*f7[5] - m6*pow(x,6)*f7[6] + m7*pow(x,7)*f7[7]
    filtN=f7
    
    ftr7= pow(alpha,N) * trdata+N*x*ftr7[1] - m2*pow(x,2)*ftr7[2] + m3*pow(x,3)*ftr7[3] - m4*pow(x,4)*ftr7[4] + m5*pow(x,5)*ftr7[5] - m6*pow(x,6)*ftr7[6] + m7*pow(x,7)*ftr7[7]
    filttrN=ftr7
    
    elsif N=6 then
    
    f6= pow(alpha,N) * src+N*x*f6[1] - m2*pow(x,2)*f6[2] + m3*pow(x,3)*f6[3] - m4*pow(x,4)*f6[4] + m5*pow(x,5)*f6[5] - m6*pow(x,6)*f6[6]
    filtN=f6
    
    ftr6= pow(alpha,N) * trdata+N*x*ftr6[1] - m2*pow(x,2)*ftr6[2] + m3*pow(x,3)*ftr6[3] - m4*pow(x,4)*ftr6[4] + m5*pow(x,5)*ftr6[5] - m6*pow(x,6)*ftr6[6]
    filttrN=ftr6
    
    elsif N=5 then
    
    f5= pow(alpha,N) * src+N*x*f5[1] - m2*pow(x,2)*f5[2] + m3*pow(x,3)*f5[3] - m4*pow(x,4)*f5[4] + m5*pow(x,5)*f5[5]
    filtN=f5
    
    ftr5= pow(alpha,N) * trdata+N*x*ftr5[1] - m2*pow(x,2)*ftr5[2] + m3*pow(x,3)*ftr5[3] - m4*pow(x,4)*ftr5[4] + m5*pow(x,5)*ftr5[5]
    filttrN=ftr5
    
    elsif N=4 then
    
    f4= pow(alpha,N) * src+N*x*f4[1] - m2*pow(x,2)*f4[2] + m3*pow(x,3)*f4[3] - m4*pow(x,4)*f4[4]
    filtN=f4
    
    ftr4= pow(alpha,N) * trdata+N*x*ftr4[1] - m2*pow(x,2)*ftr4[2] + m3*pow(x,3)*ftr4[3] - m4*pow(x,4)*ftr4[4]
    filttrN=ftr4
    
    elsif N=3 then
    
    f3= pow(alpha,N) * src+N*x*f3[1] - m2*pow(x,2)*f3[2] + m3*pow(x,3)*f3[3]
    filtN=f3
    
    ftr3= pow(alpha,N) * trdata+N*x*ftr3[1] - m2*pow(x,2)*ftr3[2] + m3*pow(x,3)*ftr3[3]
    filttrN=ftr3
    
    elsif N=2 then
    
    f2= pow(alpha,N) * src+N*x*f2[1] - m2*pow(x,2)*f2[2]
    filtN=f2
    
    ftr2= pow(alpha,N) * trdata+N*x*ftr2[1] - m2*pow(x,2)*ftr2[2]
    filttrN=ftr2
    
    elsif N=1 then
    
    f1= pow(alpha,N) * src+N*x*f1[1]
    filtN=f1
    
    ftr1= pow(alpha,N) * trdata+N*x*ftr1[1]
    filttrN=ftr1
     
    endif
    endif
    
    filt=filtN
    filtTR=filttrN
    //-----------------------------------------------------------//
    //-----Bands-------------------------------------------------//
    hband=filt+filtTR*mult
    lband=filt-filtTR*mult
    //-----------------------------------------------------------//
    //-----Bands Colors------------------------------------------//
    if filt > filt[1] then
    r=10
    g=255
    b=104
    elsif filt<filt[1] then
    r=255
    g=10
    b=90
    else
    r=204
    g=204
    b=204
    endif
    //-----------------------------------------------------------//
    //-----Candle Colors-----------------------------------------//
    if colorcandle then
    if source > source[1] and source>filt and source < hband then
    rb=10
    gb=255
    bb=104
    elsif source > source[1] and source >= hband then
    rb=10
    gb=255
    bb=27
    elsif source <= source[1] and source > filt then
    rb=0
    gb=117
    bb=45
    elsif source < source[1] and source < filt and source > lband then
    rb=255
    gb=10
    bb=90
    elsif source < source[1] and source <= lband then
    rb=255
    gb=10
    bb=17
    elsif source >= source[1] and source < filt then
    rb=153
    gb=0
    bb=50
    else
    rb=204
    gb=204
    bb=204
    endif
    DRAWCANDLE(open, high, low, close) coloured(rb,gb,bb)
    endif
    //-----------------------------------------------------------//
    //-----Channel fill color------------------------------------//
    if colorchannel then
    colorbetween(hband,lband,r,g,b,80)
    endif
    //-----------------------------------------------------------//
    return  hband as "Filtered TR High Band"coloured(r,g,b), lband as "Filtered TR Low Band"coloured(r,g,b),filt as "Filter"coloured(r,g,b)style(line,3)
    
    jesus1975 thanked this post
    #231706 quote
    jesus1975jesus1975
    Participant
    Veteran

    Muchas gracias, Iván. Impresionante tu aportación al foro. Saludos

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Conversión indicador Gaussian Channel with the Best Setting tradingview


ProBuilder: Indicadores y Herramientas

New Reply
Author
author-avatar
jesus1975 @jesus1975 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by jesus1975jesus1975
2 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicadores y Herramientas
Language: Spanish
Started: 04/18/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...