Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Cómo inicializar una Series<T> correctamente?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Cómo inicializar una Series<T> correctamente?

    Hola

    Estoy tratando de realizar esta pequeña prueba para implementar el uso de Series<T> en mi estrategia pero estoy recibiendo valores 0 en test[1] y test[2], sin embargo test[0] si me está devolviendo el valor correcto. ¿Qué podré estar haciendo mal?


    private Series<double> test; // Declaré esto a nivel de clase


    Cree el objeto serie y ya le asigné la variable
    protected override void OnStateChange()
    {
    if (State == State.DataLoaded)
    {

    test = new Series<double>(this, MaximumBarsLookBack.Infinite);
    }
    }

    protected override void OnBarUpdate()
    {
    test[0] = Close[0];

    Print (Time[0] + " " + test[0] + " " + test[1] + " " + test[2]);
    }


    Salida en pantalla: 01/02/2019 11:18:00 a. m. 6421.25 0 0
    Last edited by jleira; 07-14-2020, 11:39 PM. Reason: He realizado otras pruebas y me he dado cuenta de que me está trayendo valores cero.

    #2
    Hello jleira,

    Gracias por escribirnos hoy.

    Tenemos capacidad limitada para proporcionar soporte de plataforma en español, sin embargo, hemos encontrado que este sitio https://www.deepl.com/es/translator puede traducir el inglés al español con buena calidad. Por favor copie nuestra respuesta y luego navegue al sitio que le colocamos para pegar la respuesta en el cuadro hacia la izquierda.

    Thanks for your post and welcome to the NinjaTrader forums!

    Do you see any errors in the "Log" tab of the NinjaTrader control center when you run your script?

    I suspect you will get a bar indexing error because when you load that script when it tries to access test[1] there will be an error because on the first bar of the data series there would be no previous bar [1] (or [2]).

    You can check for the current bar like this:

    protected override void OnBarUpdate()
    {

    if (currentBar < 2) // if less that 2 bars processed, do not proceed below the return line
    return;

    test[0] = Close[0];

    Print (Time[0] + " " + test[0] + " " + test[1] + " " + test[2]);
    }

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul

      Thanks for your answer. I have tested the example above and it is working. Let me explain me better. I need save a variable named ResistenciaAlcista in" ResAlcista[0]" because I need check it later.
      First, I am asigning the value of HighSwing[0] in ResistenciaAlcista, after that I am writting the follow: ResAlcista[0] = ResistenciaAlcista;

      Print (Time[0] + " " + ResAlcista[0] + " " + ResAlcista[1] + " " + ResAlcista[2]); But when I test to see if it works I am getting this: 01/02/2019 10:00:00 a. m. 6344 0 0. The first value is correct but the second and third are wrong.

      This is part of the code. Please could you help me.

      if ( Swing1.SwingHigh[0] > ResistenciaAlcista)
      {

      ResistenciaAlcista = Swing1.SwingHigh[0];
      VelaPosicionAlcista = CurrentBar - (Math.Max(0, Swing(SwingStrengh).SwingHighBar(0, 1, CurrentBar)));
      RetrocesoAlcista = 1;
      zonaAlcCounter++;
      ResAlcista[0] = ResistenciaAlcista; <<<-------Here
      Print (Time[0] + " " + ResAlcista[0] + " " + ResAlcista[1] + " " + ResAlcista[2]); <<------ This is to test if the value is being saved


      } Click image for larger version

Name:	Captura.PNG
Views:	100
Size:	99.0 KB
ID:	1109731

      Comment


        #4
        Hello jleira,

        Thanks for your reply.

        When you create a custom series, it will create an array that matches the number of bars in the charts' data series. This means that the Index of [0] will always point to the current bar of the price series as well as your custom series ResAlcista So I suspect the issue for you is that you are storing ResistenciaAlcista in a "slot" of the ResAlcista and expecting the previous slots to have the previously stored values and that is not the case.

        For example if your previous swing point was saved 20 bars ago then, you would need to use ResAlcista[20]. In your Test example, you were storing the close value on every bar update so the previous bars of the series did have a value. In your #3 post you are only saving a value once in a while.

        I am not sure what you are trying to accomplish but the swing method does allow you to search for previous swings through the instance parameter that would look for the instance within the specified look-back period.



        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        68 views
        0 likes
        Last Post jeronymite  
        Started by mgco4you, Yesterday, 09:46 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X