• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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?
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        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?
            BertrandNinjaTrader Customer Service

            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!

              http://screencast.com/t/p7xr99U42L

              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.
                BertrandNinjaTrader Customer Service

                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 Darringona, Today, 07:43 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Darringona  
                  Started by simonkloot, Today, 07:28 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post simonkloot  
                  Started by marcus2300, Today, 06:24 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post marcus2300  
                  Started by Dhjesus, Today, 06:23 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post Dhjesus
                  by Dhjesus
                   
                  Started by embreyw, Today, 05:56 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post embreyw
                  by embreyw
                   
                  Working...
                  X