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”)
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ónbarstate.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:puedes usar:
Esto significa que si la barra actual es en tiempo real, el valor de
slowMA1
será igual aslowMA
(que es el valor en tiempo real), de lo contrario, se obtendrá el valor histórico deslowMA
utilizando la funciónsecurity()
. Puedes aplicar lo mismo a las otras llamadas a la funciónsecurity()
, comofastMA
,up
,dn
ymid
, para mostrar solo datos históricos.Después de hacer estas modificaciones, tu código debería verse así:
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.