es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Solo traza los datos históricos de Trading View

Mi mayor problema es que SOLO quiero los datos históricos en mi indicador porque los datos en tiempo real son demasiado variables e imprime una serie de señales de compra/venta que no quiero. A continuación se muestra el código que tengo hasta ahora.

Esencialmente, quiero las alertas históricas y solo quiero que se muestren los datos históricos cuando tengo TV cargado.

Descargo de responsabilidad: Utilicé este código de código abierto de Mehdi y lo he estado editando para arreglarlo/obtener lo que necesito de él.

Gracias a todos por su tiempo en ayudar aquí.

// © SRJRainey
//@version=2
strategy(“TDI – Traders Dynamic Index”, shorttitle=”TDIMH”)

rsiPeriod = input(13, minval = 1, title = “Periodo RSI”)
bandLength = input(34, minval = 1, title = “Longitud de las Bandas”)
lengthrsipl = input(1, minval = 0, title = “MA Rápida en RSI”)
lengthtradesl = input(9, minval = 1, title = “MA Lenta en RSI”)
p1 = input(“15”, title = “Marco de tiempo de la señal”, type = string)

src = close // Fuente de los cálculos (Cierre de la barra)

r = rsi(src, rsiPeriod) // RSI del Cierre
ma = sma(r, bandLength) // Media Móvil del RSI
offs = (1.6185 * stdev(r, bandLength)) // Desplazamiento
up = ma + offs // Bandas Superiores
dn = ma – offs // Bandas Inferiores
mid = (up + dn) / 2 // Media de las Bandas Superiores e Inferiores
fastMA = sma(r, lengthrsipl) // Media Móvil del RSI 2 barras atrás
slowMA = sma(r, lengthtradesl) // Media Móvil del RSI 7 barras atrás

hline(50)
indexHighTf = barstate.isrealtime ? 1 : 0
indexCurrTf = barstate.isrealtime ? 0 : 1
slowMA1 = security(tickerid, p1, slowMA)
fastMA1 = security(tickerid, p1, fastMA)
up1 = security(tickerid, p1, up)
dn1 = security(tickerid, p1, dn)
mid1 = security(tickerid, p1, mid)

plot(up1, “Banda Superior”, color = #3286c3, linewidth = 2) // Banda Superior
plot(dn1, “Banda Inferior”, color = #3286c3, linewidth = 2) // Banda Inferior
plot(mid1, “Media de las Bandas”, color = yellow, linewidth = 2) // Media de las Bandas
plot(slowMA1, “MA Lenta”, color=green, linewidth=2) // Graficar MA Lenta
plot(fastMA1, “MA Rápida”, color=red, linewidth=1) // Graficar MA Rápida

if (crossover(fastMA1, slowMA1)) strategy.entry(“vender”, strategy.long, comment=”Comprar”)

if (crossunder(fastMA1, slowMA1)) strategy.entry(“Vender”, strategy.short, comment=”Vender”)

Tags:  ,

Answer

  1. Avatar for davy.ai

    Para mostrar solo datos históricos y no señales en tiempo real en el indicador, debes modificar las llamadas a la función security() verificando si la barra es en tiempo real o no. Ya has hecho esto utilizando la función barstate.isrealtime, que devuelve true si la barra se está formando actualmente (tiempo real) y false en caso contrario (datos históricos).

    Para aplicar esto a las llamadas a la función security(), debes agregar un operador ternario (?) para elegir entre los datos en tiempo real o los históricos. Por ejemplo, en lugar de:

    slowMA1 = security(tickerid, p1, slowMA)
    

    puedes usar:

    slowMA1 = barstate.isrealtime ? slowMA : security(tickerid, p1, slowMA)
    

    Esto significa que si la barra actual es en tiempo real, el valor de slowMA1 será igual a slowMA (que es el valor en tiempo real), de lo contrario, se obtendrá el valor histórico de slowMA utilizando la función security(). Puedes aplicar lo mismo a las otras llamadas a la función security(), como fastMA, up, dn y mid, para mostrar solo datos históricos.

    Después de hacer estas modificaciones, tu código debería verse así:

    // © SRJRainey
    //@version=2
    strategy("TDI - Traders Dynamic Index ", shorttitle="TDIMH")
    
    rsiPeriod = input(13, minval = 1, title = "RSI Period")
    bandLength = input(34, minval = 1, title = "Band Length")
    lengthrsipl = input(1, minval = 0, title = "Fast MA on RSI")
    lengthtradesl = input(9, minval = 1, title = "Slow MA on RSI")
    p1 = input("15", title = "Signal Timeframe", type = string)
    
    src = close // Fuente de cálculos (Cierre de la barra)
    
    r = rsi(src, rsiPeriod) // RSI del cierre
    ma = sma(r, bandLength) // Media móvil del RSI
    offs = (1.6185 * stdev(r, bandLength)) // Desplazamiento
    up = ma + offs // Bandas superiores
    dn = ma - offs // Bandas inferiores
    mid = (up + dn) / 2 // Promedio de Bandas superiores e inferiores
    fastMA = sma(r, lengthrsipl) // Media móvil de RSI de hace 2 barras
    slowMA = sma(r, lengthtradesl) // Media móvil de RSI de hace 7 barras
    
    hline(50)
    
    slowMA1 = barstate.isrealtime ? slowMA : security(tickerid, p1, slowMA)
    fastMA1 = barstate.isrealtime ? fastMA : security(tickerid, p1, fastMA)
    up1 = barstate.isrealtime ? up : security(tickerid, p1, up)
    dn1 = barstate.isrealtime ? dn : security(tickerid, p1, dn)
    mid1 = barstate.isrealtime ? mid : security(tickerid, p1, mid)
    
    plot(up1, "Upper Band", color = #3286c3, linewidth = 2) // Banda superior
    plot(dn1, "Lower Band", color = #3286c3, linewidth = 2) // Banda inferior
    plot(mid1, "Middle of Bands", color = yellow, linewidth = 2) // Mitad de las Bandas
    plot(slowMA1, "Slow MA", color=green, linewidth=2) // Plot Slow MA
    plot(fastMA1, "Fast MA", color=red, linewidth=1) // Plot Fast MA
    
    if (crossover(fastMA1, slowMA1)) strategy.entry("sell", strategy.long, comment="Buy")
    
    if (crossunder(fastMA1, slowMA1)) strategy.entry("Sell", strategy.short, comment="Sell")
    

    Esto debería mostrar solo los valores históricos del indicador y no las señales de compra/venta en tiempo real que no deseas.

Comments are closed.