Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

very simple problem here....

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

    very simple problem here....

    I cannot figure out what the problem is here with the code that I posted below.
    If I have the code shown below, it does nothing. But it should print "testing" why does it not work?

    However, if I uncomment out the add(Period)s and the additional PrintWithTimeStamp()s it prints out the following:

    testing
    8/31/2011 8:05:11 PM 0BarsInProgress 2

    8/31/2011 8:05:11 PM 2BarsInProgress 2


    However, I would think that it should print out


    testing
    8/31/2011 8:05:11 PM 0BarsInProgress 0

    8/31/2011 8:05:11 PM 0BarsInProgress 0
    8/31/2011 8:05:11 PM 1BarsInProgress 1

    8/31/2011 8:05:11 PM 0BarsInProgress 0
    8/31/2011 8:05:11 PM 2BarsInProgress 2

    What it going on here?
    Thanks,
    Matt
    See code below

    Code:
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        
        public class test : Strategy
        {
            #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            #endregion
            //DateTime startTime;
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
    
            //    Add(PeriodType.Minute, 60);
            //    Add(PeriodType.Second, 1);
                Print("end initialize");
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                Print("testing");
                
    //            PrintWithTimeStamp("0BarsInProgress " + BarsInProgress);
    //            if (BarsInProgress==1){ 
    //                PrintWithTimeStamp("1BarsInProgress " + BarsInProgress);
    //            }
    //            if (BarsInProgress==2){ 
    //                PrintWithTimeStamp("2BarsInProgress " + BarsInProgress);
    //            }
                
            }
    
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            #endregion
        }
    }

    #2
    Hi Matt, can you please recheck after ensuring enough days back of data is loaded to satisfy the BarsRequired for all series involved in this script?

    Comment


      #3
      You mean that code even compiles?

      I thought that PrintWithTimeStamp() has been removed in NT7 recently.

      Comment


        #4
        PrintWithTimeStamp seems commented out there koganam...

        Comment


          #5
          Bertrand,

          Thank you! I knew it was something silly.



          PrintWithTimeStamp does work in 7.0.1000.7

          Comment


            #6
            Originally posted by matt3m View Post
            Bertrand,

            Thank you! I knew it was something silly.



            PrintWithTimeStamp does work in 7.0.1000.7
            I guess you must have a different 7.0.1000.7 from the one that I have then.
            Attached Files

            Comment


              #7
              In a strategy > it will work / compile

              In an indicator > it will not work / compile

              That's the difference we would see here, as the snippet from the OP was a strategy.

              Comment


                #8
                just out of curiosity, what happens if I have code that calls for the value of the 200 simple moving average SMA, but I only have 50 bars?

                Thanks,
                Matt

                Comment


                  #9
                  matt3m,

                  The indicator may not plot depending on how you have set to handle this issue and you'd received a log error indicating there are not enough bars on the chart to calculate

                  http://www.ninjatrader.com/support/f...ead.php?t=3170
                  .
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    In a strategy > it will work / compile

                    In an indicator > it will not work / compile

                    That's the difference we would see here, as the snippet from the OP was a strategy.
                    Ah, that would certainly explain why.

                    But if I may ask, this is just an output debugging statement. Why should it be available only to a strategy and not to an indicator?

                    Comment


                      #11
                      Originally posted by matt3m View Post
                      just out of curiosity, what happens if I have code that calls for the value of the 200 simple moving average SMA, but I only have 50 bars?

                      Thanks,
                      Matt
                      In the very particular case of the SMA(), it would probably work OK.

                      Look at the code for the SMA indicator, and you will see that it is coded to use the SMA for available bars until it reaches the requested value, after which it will return the SMA for the exact number of bars requested.

                      For any other indicators, well, it depends on how they handle the situation when the number of bars is less than requested.

                      Comment


                        #12
                        Bertrand, under what circumstances would you see an error message? I ran a strategy with sma(200) and it produced no messages in the logs or the output window.

                        thx

                        Comment


                          #13
                          Originally posted by dojidubbs View Post
                          Bertrand, under what circumstances would you see an error message? I ran a strategy with sma(200) and it produced no messages in the logs or the output window.

                          thx
                          I believe that I explained above why in the particular case of the SMA(), you would probably not see an error?

                          Comment


                            #14
                            Guess I should refresh the thread prior to asking a question to see additional responses!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            649 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            370 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            109 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            574 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            576 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X