Indicador regresión logística múltiple de TradingView a ProRealTime

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #232503 quote
    Fr7
    Participant
    Master

    Solicite, si es posible, convertir el indicador adjunto.

    Indicador de regresión logística múltiple
    El indicador de Aprendizaje automático: regresión logística múltiple para TradingView es una herramienta versátil que emplea regresión logística múltiple basada en varios indicadores técnicos para generar señales potenciales de compra y venta. Al utilizar indicadores clave como RSI, CCI, DMI, Aroon, EMA y SuperTrend, el indicador pretende proporcionar un enfoque sistemático para la toma de decisiones en los mercados financieros.

    https://es.tradingview.com/script/YHuROcQY-Machine-Learning-Multiple-Logistic-Regression/

    A ver si Iván el moderador lo puede traducir.
    Muchas gracias.

    #232629 quote
    Iván González
    Moderator
    Master

    Buenas!
    Aquí tienes el indicador:

    DEFPARAM DRAWONLASTBARONLY =TRUE
    //--------------------------------------------------------------//
    //PRC_Multiple Logistic Regression
    //version = 0
    //14.05.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------------------------------//
    //-----Inputs--------------------------------------------------//
    length=50 //Z score length
    rsilength=35 //rsi
    ccilength=45 //cc1
    dmilength=35 //dmi
    arlength=35 //aroon
    emalength=30 //exponential average
    factor=3.2 //factor for supertrend
    atrperiod=2 //atr period
    b0=1
    b1=1//rsi
    b2=4//cci
    b3=1//dmi
    b4=2//aroon
    b5=5//ema
    b6=4//supertrend
    lr=0.08//step of learning
    //-------------------------------------------------------------//
    //-----INDICATORS----------------------------------------------//
    //-----RSI
    rsivalue=rsi[rsilength](close)
    //-----CCI
    ccivalue=cci[ccilength]((high+low+close)/3)
    //-----DMI and DPI
    plus=DIplus[dmilength](close)
    minus=DIminus[dmilength](close)
    //-----AROON
    upper=AroonUp[arlength]
    lower=AroonDown[arlength]
    //-----EMAs
    ema1=average[emalength,1](close)
    ema2=average[emalength-10,1](close)
    //-----SUPERTREND
    atr = averagetruerange[atrperiod](close)
    src=(high+low)/2
    up = src - factor*atr
    up1 = up[1]
    if close[1] > up1 then
    up = max(up,up1)
    else
    up = up
    endif
    
    dn = src + factor*atr
    dn1 = dn[1]
    if close[1] < dn1 then
    dn = min(dn,dn1)
    else
    dn = dn
    endif
    
    once direction = 1
    
    if direction = -1 and close > dn1 then
    direction = 1
    elsif direction = 1 and close < up1 then
    direction = -1
    else
    direction = direction
    endif
    
    if direction = 1 then
    st = up
    else
    st = dn
    endif
    //-------------------------------------------------------------//
    //-----Normalized indicators-----------------------------------//
    //-----Normalized close
    basis=average[length](close)
    zscore=(close-basis)/std[length](close)
    if zscore > 0 then
    y=1
    else
    y=-1
    endif
    //-----Normalized RSI
    if rsivalue > 50 then
    x1=1
    else
    x1=-1
    endif
    //-----Normalized CCI
    if ccivalue crosses over 100 then
    x2=1
    elsif ccivalue crosses under -100 then
    x2=-1
    endif
    //-----Normalized DMI
    if plus > minus then
    x3=1
    else
    x3=-1
    endif
    //-----Normalized Aroon
    if upper > lower then
    x4=1
    else
    x4=-1
    endif
    //-----Normalized ema
    if ema1 > ema2 then
    x5=-1
    else
    x5=1
    endif
    //-----Normalized Supertrend
    x6=direction*(1)
    //-------------------------------------------------------------//
    //-----MULTIPLE LOGISTIC REGRESSION----------------------------//
    //-----Pre Multiple Logic Regression
    p=1/(1+exp(-(b0+b1*x1+b2*x2+b3*x3+b4*x4+b5*x5+b6*x6)))
    //-----Loss
    myloss=(-y)*log(p)-(1-y)*log(1-p)
    //-----Adjusting model weights using gradient descent
    b11=b1-lr*(p+myloss)*x1
    b22=b2-lr*(p+myloss)*x2
    b33=b3-lr*(p+myloss)*x3
    b44=b4-lr*(p+myloss)*x4
    b55=b5-lr*(p+myloss)*x5
    b66=b6-lr*(p+myloss)*x6
    //-----Multiple Logic Regression With adjusted weights based on loss function
    lreg=1/(1+exp(-(b0+b11*x1+b22*x2+b33*x3+b44*x4+b55*x5+b66*x6)))
    //-------------------------------------------------------------//
    //-----PLOT----------------------------------------------------//
    //-----Color
    if lreg>=0.5 then
    r=0
    g=255
    else
    r=255
    g=0
    endif
    //-----SMA
    sma=average[10](close)
    //-------------------------------------------------------------//
    //-----SIGNALS-------------------------------------------------//
    if lreg crosses over 0.5 then
    $crossupx[z+1]=barindex
    $crossup[z+1]=low
    z=z+1
    elsif lreg crosses under 0.5 then
    $crossdnx[t+1]=barindex
    $crossdn[t+1]=high
    t=t+1
    endif
    for i=0 to z do
    drawtext("▲",$crossupx[i],$crossup[i])coloured("green")
    next
    for j=0 to t do
    drawtext("▼",$crossdnx[j],$crossdn[j])coloured("red")
    next
    //-------------------------------------------------------------//
    //-----TABLE---------------------------------------------------//
    //-----Variable
    drawtext("Variable",-150,-60)anchor(topRIGHT ,XSHIFT ,YSHIFT ) 
    drawtext("RSI",-150,-80)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("CCI",-150,-100)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("DMI",-150,-120)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("AROON",-150,-140)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("EMA",-150,-160)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("SuperT",-150,-180)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    //-----Val
    drawtext("Val",-100,-60)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#x1#",-100,-80)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#x2#",-100,-100)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#x3#",-100,-120)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#x4#",-100,-140)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#x5#",-100,-160)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#x6#",-100,-180)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    //-----Beta
    drawtext("Beta",-50,-60)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#b11#",-50,-80)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#b22#",-50,-100)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#b33#",-50,-120)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#b44#",-50,-140)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#b55#",-50,-160)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    drawtext("#b66#",-50,-180)anchor(topRIGHT ,XSHIFT ,YSHIFT )
    //-----Rectangle
    drawrectangle(-200,-200,-10,-40)anchor(topRIGHT ,XSHIFT ,YSHIFT )fillcolor("blue",50)
    //-------------------------------------------------------------//
    return sma as "SMA"coloured(r,g,0)style(line,3)
    
    Fr7 thanked this post
    #232705 quote
    Fr7
    Participant
    Master

    Muchas gracias Iván!!,eres un crack!!Sólo tengo palabras de agradecimiento por tu trabajo y esfuerzo en este foro. Espero que sea útil para todo el mundo y estoy investigando sobre  indicadores basados en I.A., quizás más adelante te mande otros códigos. Un saludo.

    #258291 quote
    Pedro Herrero
    Participant
    New

    Buenas noches ¿sería posible configurar un screener para tradingview con este indicador en el que te dijera los valores que han dado señal de compra?

    Gracias

    #258299 quote
    Iván González
    Moderator
    Master

    Buenas, quizás en un foro de tradingview sí. aquí no lo es.

    De todas formas creo que con tradingview no puedes hacer screeners de este tipo.

    #258311 quote
    Pedro Herrero
    Participant
    New

    Muchas gracias

    ¿para ProRealTime se podría hacer? 

    Un saludo

    #258315 quote
    Iván González
    Moderator
    Master

    si

    //--------------------------------------------------------------//
    // PRC_Multiple Logistic Regression - SCREENER (Buy Signal)
    //-------------------------------------------------------------//
    
    //-----Inputs--------------------------------------------------//
    length = 50
    rsilength = 35
    ccilength = 45
    dmilength = 35
    arlength = 35
    emalength = 30
    factor = 3.2
    atrperiod = 2
    b0 = 1
    b1 = 1
    b2 = 4
    b3 = 1
    b4 = 2
    b5 = 5
    b6 = 4
    lr = 0.08
    //-------------------------------------------------------------//
    
    //-----INDICATORS----------------------------------------------//
    //-----RSI
    rsivalue = rsi[rsilength](close)
    //-----CCI
    ccivalue = cci[ccilength]((high+low+close)/3)
    //-----DMI and DPI
    plus = DIplus[dmilength](close)
    minus = DIminus[dmilength](close)
    //-----AROON
    upper = AroonUp[arlength]
    lower = AroonDown[arlength]
    //-----EMAs
    ema1 = average[emalength,1](close)
    ema2 = average[emalength-10,1](close)
    
    //-----SUPERTREND
    atr = averagetruerange[atrperiod](close)
    src = (high+low)/2
    up = src - factor*atr
    up1 = up[1]
    
    IF close[1] > up1 THEN
       up = max(up,up1)
    ELSE
       up = up
    ENDIF
    
    dn = src + factor*atr
    dn1 = dn[1]
    
    IF close[1] < dn1 THEN
       dn = min(dn,dn1)
    ELSE
       dn = dn
    ENDIF
    
    ONCE direction = 1
    
    IF direction = -1 AND close > dn1 THEN
       direction = 1
    ELSIF direction = 1 AND close < up1 THEN
       direction = -1
    ELSE
       direction = direction
    ENDIF
    
    //-------------------------------------------------------------//
    //-----Normalized indicators-----------------------------------//
    //-----Normalized close
    basis = average[length](close)
    zscore = (close-basis)/std[length](close)
    
    IF zscore > 0 THEN
       y = 1
    ELSE
       y = -1
    ENDIF
    
    //-----Normalized RSI
    IF rsivalue > 50 THEN
       x1 = 1
    ELSE
       x1 = -1
    ENDIF
    
    //-----Normalized CCI
    IF ccivalue CROSSES OVER 100 THEN
       x2 = 1
    ELSIF ccivalue CROSSES UNDER -100 THEN
       x2 = -1
    ENDIF
    
    //-----Normalized DMI
    IF plus > minus THEN
       x3 = 1
    ELSE
       x3 = -1
    ENDIF
    
    //-----Normalized Aroon
    IF upper > lower THEN
       x4 = 1
    ELSE
       x4 = -1
    ENDIF
    
    //-----Normalized ema
    IF ema1 > ema2 THEN
       x5 = -1
    ELSE
       x5 = 1
    ENDIF
    
    //-----Normalized Supertrend
    x6 = direction * 1
    
    //-------------------------------------------------------------//
    //-----MULTIPLE LOGISTIC REGRESSION----------------------------//
    //-----Pre Multiple Logic Regression
    p = 1 / (1 + exp(-(b0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6)))
    
    //-----Loss
    myloss = (-y)*log(p) - (1-y)*log(1-p)
    
    //-----Adjusting model weights using gradient descent
    b11 = b1 - lr*(p+myloss)*x1
    b22 = b2 - lr*(p+myloss)*x2
    b33 = b3 - lr*(p+myloss)*x3
    b44 = b4 - lr*(p+myloss)*x4
    b55 = b5 - lr*(p+myloss)*x5
    b66 = b6 - lr*(p+myloss)*x6
    
    //-----Multiple Logic Regression With adjusted weights
    lreg = 1 / (1 + exp(-(b0 + b11*x1 + b22*x2 + b33*x3 + b44*x4 + b55*x5 + b66*x6)))
    
    //-------------------------------------------------------------//
    //-----SIGNALS & SCREENER--------------------------------------//
    buySignal = lreg CROSSES OVER 0.5
    
    SCREENER[buySignal] (lreg AS "L-Reg Value")
    


    robertogozzi thanked this post
    #258339 quote
    Pedro Herrero
    Participant
    New

    Muchas gracias

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

Indicador regresión logística múltiple de TradingView a ProRealTime


ProBuilder: Indicadores y Herramientas

New Reply
Author
author-avatar
Fr7 @fr7 Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by Pedro Herrero
1 month, 1 week ago.

Topic Details
Forum: ProBuilder: Indicadores y Herramientas
Language: Spanish
Started: 05/08/2024
Status: Active
Attachments: No files
Logo Logo
Loading...