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

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!

              Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


              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 bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,605 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  13 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X