Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnStartupMehod() called 6 times!

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

    OnStartupMehod() called 6 times!

    Hello Im was reading the information OnStartUp() here: http://www.ninjatrader.com/support/h...?onstartup.htm

    It says it is only called one before OnBarUpdate() and after Initialize(), but I have programed this code:

    protected override void OnStartUp()
    {


    ClearOutputWindow();
    Print("holaaaaaaaaaa");
    }

    And in the Output appears:

    holaaaaaaaaaa
    holaaaaaaaaaa
    holaaaaaaaaaa
    holaaaaaaaaaa
    holaaaaaaaaaa
    holaaaaaaaaaa


    Why???? Why is the line Print("holaaaaaaaaaa"); procesed 6 times??


    Im using NinjaTrader 64bits on Windows vista 64.

    Thank you

    Luis

    #2
    Luis, your understanding is correct here - would this be done from an indicator or strategy? Do you just apply this one test script to one chart or would you for example use in in backtesting with the Strategy Analyzer or call it from other scripts?

    Comment


      #3
      Hello Bertrand

      Im just getting in touch with NinjaScript

      This is the code for a strategy:

      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Strategy;
      #endregion

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Enter the description of your strategy here
      /// </summary>
      [Description("Enter the description of your strategy here")]
      public class Dias5 : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      int[] numeros={0,1};
      int[,] matriz= new int[4,2];
      Random rnd = new Random();
      #endregion





      protected override void OnStartUp()
      {

      int indice = rnd.Next(numeros.Length);
      ClearOutputWindow();



      for (int x=0; x<4; x++)
      {
      for (int y=0;y<2;y++)
      {
      matriz[x,y]=numeros[rnd.Next(numeros.Length)];
      }
      }


      Print("-------------------------RESULTADOS----------------------");
      for (int x=0; x<4; x++)
      {
      Print("La fila numero " + (x+1) + "es=" + matriz[x,0] + " " + matriz[x,1] + " hola");

      }
      }


      protected override void Initialize()
      {
      CalculateOnBarClose = true;

      }


      protected override void OnBarUpdate()
      {

      }

      #region Properties
      #endregion
      }
      }

      The Bold part appears 6 times in the Output window, for me this is very strange.. Because we have the ClearOutputWindow(); line upside.

      I dont understand...... It seems like this section of the code entered a 6 time loop...

      Thank you

      Luis

      Comment


        #4
        Sorry, I don't follow - your loops used in OnStartUp() triggers 6 times in total, so would expect that outcome? The method itself is called only once before the first OnBarUpdate(). So just remove the custom logic for now and just trigger one print for OnStartUp() without any loop logic and you see only one print taking place.

        Comment


          #5
          That is what I did in the first example is very weird:

          protected override void OnStartUp()
          {


          ClearOutputWindow();
          Print("holaaaaaaaaaa");
          }

          It prints holaaaaaaaaaa 6 times, no other Code in the strategy...

          Comment


            #6
            Is perhaps another instance of your other script run as well in the back? The one with the loop logic included?

            Comment


              #7
              Noo!!

              See I have done a quick video with this issue:

              All strategy Closed // New .. Strategy // Put the code // Compile // Backtest

              You are going to see what Im telling you:

              It is very weird indeed!

              World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


              Im going to install the 32bit version meanwhile.

              Luis

              Comment


                #8
                Please try running on one instrument only? From the video, you're running a basket test here which would include multiple instruments and thus multiple instances of your test script, one for each instrument...which will be meaning you see multiple calls to OnStartUp(), one for each instance used.

                Comment


                  #9
                  Thank you!



                  Oh I can see that now!

                  Now I also can see the basket backtesting is proceed in a paralel mode.

                  Thank you!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  563 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  329 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  547 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  548 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X