Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

N Bars Down Producing No Trades

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

    N Bars Down Producing No Trades

    Hi,

    I am trying to use the condition "if the market has gone down for "N bars" and this condition was met at the close of last bar then ... do something.

    I have attached a screenshot of what i have it setup as, but it is producing no trades in my backtest.

    I also tried setting the right hand side of the wizard to "= True" but said it wouldnt allow a Boolean value.

    Im sure its a simple thing but please could you tell me where I have gone wrong.

    Thank you
    Attached Files

    #2
    Hello Tomhgriff1, and thank you for your question.

    Your condition does look correct, you should be comparing NBarsDown to an integer value. It looks like we are going to need a bigger picture than what we have so far to work with before we can track this down.

    I would like to ask, are you getting any messages in the log tab of the control center? If so, please send a screen shot of these messages.

    To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.
    Click here for instructions
    Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.
    Click here for detailed instruction
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi there was a message in the log tab saying
      "NBarsDown" couldnt be serialized"

      Not sure what that means
      Attached Files

      Comment


        #4
        Hello Tomhgriff1,

        It looks first like I was mistaken earlier. After reviewing the documentation for NBarsDown, we find

        Originally posted by https://ninjatrader.com/support/helpGuides/nt7/n_bars_down.htm
        Checks for n number of consecutive lower closes. Returns a value of 1 when the condition is true or 0 when false.
        Therefore you will actually want to compare this to Misc -> Numeric Value. You will want to make sure this is equal to 1 before trading.

        That said if you are getting a message like this, I believe we need to investigate whether BarsDown is an integer. I would like to ask you to press the View Code button. You should get output something like this :

        Code:
        [FONT=Courier New]        #region Variables
                // Wizard generated variables
                private int barsDown = 1; // Default setting for BarsDown
                // User defined variables (add any user defined variables below)
                #endregion
        
                /// <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 = true;
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                    // Condition set 1
                    if (NBarsDown(BarsDown, true, true, true)[1] == 1)
                    {
                        EnterLong();
                    }
                }[/FONT]
        If your code looks significantly different from that, please let us know so we can assist further.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Hi Jessica,

          I have this as one of my lines of code relating to N Bars down.

          // Condition set 1
          if (NBarsDown(BarsDown, true, true, true)[0] >= BarsDown)
          {
          EnterLong(DefaultQuantity, "");
          }

          So it is missing two number "1's" i wanted to make the number of down bars a variable so be optimized. Are you saying it cant be a variable but has to be an integer you set in the Wizard?

          Thanks

          Comment


            #6
            This can be a variable. In fact you are already using this as a variable. I am going to emphasize some parts of your code to clarify what is happening.

            Code:
            [FONT=Courier New] if (NBarsDown([B][SIZE=2][I]BarsDown[/I][/SIZE][/B], true, true, true)[0] >= [B][SIZE=2][I]BarsDown[/I][/SIZE][/B])[/FONT]
            As we can see, your custom variable shows up twice - once as the first argument to NBarsDown, and once as the value you are comparing to.

            I am going to provide a more complete excerpt from the documentation.

            Originally posted by https://ninjatrader.com/support/helpGuides/nt7/n_bars_down.htm
            Checks for n number of consecutive lower closes. Returns a value of 1 when the condition is true or 0 when false.


            Syntax
            NBarsDown(int barCount, bool BarDown, bool lowerHigh, bool lowerLow)
            ...

            • barCount: The number of required consecutive lower closes
            • BarDown: Each bar's open must be less than the close; true or false
            • input: Indicator source data (?)
            • lowestHigh: Consecutive lower highs required; true or false
            • lowestLow: Consecutive lower lows required; true or false
            "Returns a value of 1" means we should be comparing to a numeric value of 1 if we want to mean "we have been trending downward far enough" and 0 to mean "we have not been trending downward far enough"

            As far as what "far enough" means, this is where "barCount" comes in to play. In your case, this is BarsDown already.

            Putting this all together, if your code looks like this :

            Code:
            [FONT=Courier New] if (NBarsDown([B][SIZE=2][I]BarsDown[/I][/SIZE][/B], true, true, true)[0] >= [SIZE=2][I][B]1[/B][/I][/SIZE])
            {
                EnterLong(DefaultQuantity, "");
            }
            [/FONT]
            This means "if we have been trending downward BarsDown bars, enter a trade on the long side of the market", which is our goal.

            You can compare to numeric values on the right-hand-side with Misc -> Numeric Value.

            Please let us know if there are any other ways we can help.
            Last edited by NinjaTrader_JessicaP; 09-19-2016, 10:25 AM.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Hi again,

              Sorry but i dont understand really when you speak in NinjaScript terms. Is it possible to show me what to do in the wizard. As from what im reading I have it setup as this in the wizard already. (as shown in first screen shot).

              Thanks

              Comment


                #8
                We're always happy to assist further. If you examine your first screen shot, on the left hand side, you see a parameter you have already managed to set called "BarCount". This corresponds to the first part of

                NBarsDown(BarsDown, true, true, true)

                BarsCount, which you set to BarsDown, is the number of bars we must trend downward for NBarsDown to be triggered.

                The second, third, and fourth parts - "true, true, true" in the code - you can read in the picture you sent below BarCount. These are Bar Down, Lower High, and Lower Low. The Help Guide excerpt I posted explains what all of these are.

                The next parameter in the picture, BarsAgo, is the one that goes inside [1] . This is why my code sample had a 1 in it; originally you had this set to 1 in the picture you sent us, and must have changed it to 0 at a later point before sending us that code sample.

                When you see something in the help guide talk about "return values", they are talking about values that show up on the right-hand side of an equals sign (or other comparator, by comparator I mean something like an equals sign or a greater than sign). So this would be whatever goes on the right side of the picture you sent.

                Please let me know if that helps, or if there are any other questions we may answer.
                Last edited by NinjaTrader_JessicaP; 09-19-2016, 11:09 AM.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Please see the attached image. Im still not getting any results and dont know what to change in the strategy wizard.
                  Attached Files

                  Comment


                    #10
                    Hello again Tomhgriff1,

                    I noticed that we still have not been able to set Misc -> Numeric Value to 1 on the right hand side, instead of using a redundant BarsDown, which as we pointed out is showing up on your left hand side in the lower left hand corner.

                    Could you try this setting and let us know what your results are?
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Yes that solved it. Thank you very much for the help

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      633 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      364 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      105 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      567 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      568 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X