Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple question

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

    Simple question

    I'm doing some tests with a stategy and I'm trying to print a text if my position is flat, using OnBarUpdate:

    Code:
     protected override void Initialize()
            {
                CalculateOnBarClose = false;
            }
    
           
            protected override void OnBarUpdate()
            {
    			if(Position.MarketPosition == MarketPosition.Flat)
    			Print("position flat");
            }
    The position is flat, because still no orders have been submitted, but nothing is printed on bar update
    I've been using Ninja for a long time but this sounds new to me
    Is that something am I missing or am I just tired for an hard day?

    #2
    I can see print only if I attach the strategy to chart, but I need to use the strategy "activating" it from the Control Center.

    Thanks

    Comment


      #3
      Hello MAX,

      Thank you for your post.

      When enabling the strategy on the Strategies tab of the NinjaTrader Control Center does the strategy ever go 'green' or does it stay 'yellow'?

      I look forward to your response.

      Comment


        #4
        Just solved!

        It was because I did not change the Number of Bars required. I now set it up to "0" and everything works.

        Thanks.

        Comment


          #5
          Sorry to bother, but suddenly I'm facing the same trouble.

          Following is my code:

          Code:
           protected override void Initialize()
                  {
                      CalculateOnBarClose = false;
          			BarsRequired = 0;
                  }
          
               
                  protected override void OnBarUpdate()
                  {
          			if(Close[0] != Close[1])
          			Print(Close[0].ToString());
                  }
          In my opinion I should see Close price printed in the Output Window.

          I'm running NT 7.0.1000.11 and, once enabled, the strategy is "green".

          As I told you, I've been using NT for many years so I'm suspecting something is not working in my NT.

          Could you please give me an hint?

          Thanks.

          Comment


            #6
            Hello MAX,

            Thank you for your response.

            Please send me your log and trace files for today so that I may look into what occurred.

            You can do this by going to the Control Center-> Help-> Mail to Support.

            Please put 'ATTN:Patrick' in the subject line and a reference to this thread in the body of the email: http://www.ninjatrader.com/support/f...ad.php?t=55814

            I look forward to your response.

            Comment


              #7
              Originally posted by MAX View Post
              Sorry to bother, but suddenly I'm facing the same trouble.

              Following is my code:

              Code:
               
               protected override void Initialize()
                      {
                          CalculateOnBarClose = false;
                          BarsRequired = 0;
                      }
               
               
                      protected override void OnBarUpdate()
                      {
                          if(Close[0] != Close[1])
                          Print(Close[0].ToString());
                      }
              In my opinion I should see Close price printed in the Output Window.

              I'm running NT 7.0.1000.11 and, once enabled, the strategy is "green".

              As I told you, I've been using NT for many years so I'm suspecting something is not working in my NT.

              Could you please give me an hint?

              Thanks.
              You are trying to access bar[1]. You need to escape it.
              Code:
              if (CurrentBar < 1) return;
              at the start of OnBarUpdate() should take care of it in this particular instance.

              Comment


                #8
                Thanks koganam for your suggestion.

                Patrick, I've sent the log. Thanks.

                Comment


                  #9
                  Hello MAX,

                  Thank you for those files.

                  From your log file I see the following error listed several times and each time right before your strategy is disabled:
                  • Error on loading chart data for 'MYTESTINSTRUMENT 10-12 Default': NinjaTrader data server does not support this instrument, no data available.

                  Please apply your strategy to a valid instrument in NinjaTrader and then advise if the strategy stays enabled and no errors are shown in the Log tab of the NinjaTrader Control Center.
                  Last edited by NinjaTrader_PatrickH; 02-14-2013, 07:51 AM.

                  Comment


                    #10
                    This is a "fake" instrument I created for tests and simulations and it works fine (I've never had any trouble).
                    When runs as "simulated data feeds" I've seen the same behaviour of a real market. The strange thing is that I was seeing the market updating on chart but nothing on print.

                    Anyway I will try with a valid instrument.

                    Thanks.

                    Comment


                      #11
                      I don't know if this is relevant, but I had similar weird issues with strategies when fewer than 20 bars are in the chart.

                      Make sure you have some historical data and at least 20 bars... If you're using the Sim connection... I bet once you get 20 bars updated that it will start to work.

                      Comment


                        #12
                        Hello MAX,

                        Thank you for your response.

                        Along with what koganam and BigWaveDave have mentioned, have you looked into making sure you have enough bars on the chart before accessing the bars?

                        You can do this with the following:
                        Code:
                        if(CurrentBar < BarsRequired)return;
                        For information on ensuring you have enough bars before accessing them please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

                        Please let me know if you have any questions.

                        Comment


                          #13
                          Thanks BigWaveDave. This could be a good reason.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          637 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          366 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          107 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          569 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          571 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X