Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy not working

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

    Strategy not working

    I am attempint to write my first strategy in Ninjatrader 7 and nothing happens. I used a bunch of print statements to see if i could pin point the problem but what i found out was that none of my codes are working, I even wrote the simpliest one line code with a print statement and nothing gets printed to the output window, This is my first strategy in N7 but i have wrote a couple custom indicator in N7 without problem. Whats going on ?

    #2
    trader413, can you please post the strategy here so we can take a look?
    AustinNinjaTrader Customer Service

    Comment


      #3
      I had just started writing a couple lines when I notice this problem so I strip it down to a simple one line (below) and still nothing happens. This should be printing to the output window right ?



      protected override void Initialize()
      {

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (Close[1] > High[2] )
      {
      got = 1;
      PrintWithTimeStamp(" nmnm");
      }
      }


      }

      Comment


        #4
        trader413, you are running into the issue where you're trying to check the price of a bar that doesn't exist.

        Please try this instead:
        Code:
        protected override void OnBarUpdate()
                {
        if (CurrentBar < 3)
            return;
        
                       if (Close[1] > High[2] )
                       {
                             PrintWithTimeStamp(" nmnm");
                       }
                }
        AustinNinjaTrader Customer Service

        Comment


          #5
          Still nothing prints

          Comment


            #6
            Did you re-compile the script after you made the edits?

            I just tested it here and everything works as expected:
            Attached Files
            AustinNinjaTrader Customer Service

            Comment


              #7
              yes i did and still nothing prints in the output window

              Comment


                #8
                How are you backtesting the strategy? Are there any errors in the logs (right-most tab of Control Center)?
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  I do not see any errors, the only thing that i see that maybe related is a message saying automated trading disabled. Could this be the cause ? and if so how can a fix this?

                  Comment


                    #10
                    trader413, how exactly are you testing this strategy? Are you running it on a chart? From the strategy tab? In the Strategy Analyzer? Market Replay? What instrument are you using and what timeframe/session template? What data provider are you using?

                    If you could list out exactly what you're doing, I will try it out and see what is going wrong.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      I am testing this on a ES 1 min chart with 24/7 session time. My data provider is CGQ. All i'm doing is loading this strategy on the ES chart and looking in the output window to check if the code is working.

                      Comment


                        #12
                        One last question in that case: have you enabled the strategy?

                        The easiest way to test strategies is to use the Strategy Analyzer (File -> New -> Strategy Analyzer), so you can run tests over and over and over again without resetting all the parameters every time.
                        Attached Files
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          Ok Its now fixed, the yellow highlighted box was set to disable. Thanks

                          Another problem

                          protected override void Initialize()
                          {
                          SetStopLoss("NSE1", CalculationMode.Ticks, 12, false);
                          SetProfitTarget("NSE1", CalculationMode.Price, TP);

                          CalculateOnBarClose = false;
                          TraceOrders = true ;
                          }

                          protected override void OnBarUpdate()
                          {

                          TP = targetprice - targetprice % TickSize + ((targetprice % TickSize < TickSize/ 2) ? 0.0 : TickSize);
                          Print(TP);

                          Why isn't my target getting hit ? "targetprice" is a variable being output by an indicator

                          Comment


                            #14
                            trader413,

                            No worries. This should be a straightforward problem to address. You will not be able to dynamically change your profit target price by only changing the TP variable. If you want to change your profit target price you would need to call SetProfitTarget() again. This reference sample should be of value on doing just that: http://www.ninjatrader.com/support/f...ead.php?t=3222
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Are you sure ? I have a couple old strategy in version 6 in which I used this method to change my profit target. Did something changed in version 7 ?

                              And another thing, this profit target will be changing throughout the trading day. So I am looking to have a dynamic Target and stop.

                              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