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

Minimum Bars Required questions...

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

    Minimum Bars Required questions...

    Hello All!!

    I hope you're having a great day!

    I've been working on this new strategy, which is taking me ever deeper into NinjaScript land...

    I've been looking at the "Minimum Bars Required" parameter in the Strategy Edit window accessed by selecting the "Strategies" tab on the control center, and right clicking.

    I've scoured through a ton of other posts regarding this parameter, but I still have a few unanswered questions regarding it. I'm hoping to benefit again from your wonderful informational generosity.

    Here are my specific questions regarding this parameter. I would love it if someone would tackle each question for me so I get a better understanding of it. This is one of those things regarding which a simple "nudge" just will not do.

    Okay... here we go...

    1.) Does "Minimum Bars Required" look at the number of bars "since the strategy was loaded on the chart," or... does it look at the number of bars, "since the beginning of the trading session?"

    2.) If the answer is "trading session," does it base that calculation on the particular "session template" being used on the chosen chart? Does this calculation change based on the trading session template, or is it calculated from an internally coded market schedule?

    3.) If I have an indicator which has "300" as its period, do I have to set the "Minimum Bars Required" parameter to "300?" If so, why? (I bet you can tell by now I'm a big "why" person. Drives people mad!)

    4.) If the strategy contains indicators which have "300" as their period amount, and I set the "Minimum Bars Required" parameter to "300," will the Strategy not place an order until it has waited 300 bars?

    5.) In the above scenario, where I have an indicator with "300" as its period amount, if I set "Minimum Bars Required" to less then "300" (for example... I set it to just 2 bars), how will that affect live trading specifically?

    6.) If I have one indicator, which has as its parameter "300," and another one, which has as its parameter "250," does that mean I need to wait "550" bars?

    7.) This is a BIG one... Does "Bars Required" reset every time I make an update to the code and reload NinjaScript via F5? In other words, let's say I've had the strategy running, and I've waited 299 bars, and I notice something which needs to be altered, and I alter it, then reload the NinjaScript to update the chart... does that reset the counter... and now I have to wait another 300 bars before I can trade?

    8.) Since I use 6 range bars in this new strategy, and since it can take forever for just one bar to form, should I just give up now and go jump under a fast-moving bus?
    I know I've asked for a lot here... but a "crystal clear" understanding of this parameter will be of inestimable value to me.

    I am grateful for your assistance in this great learning journey to better understand and implement NinjaScript.

    -V

    #2
    Hello Aurum,

    Thank you for your post.

    1) The BarsRequired will be part of all the bars on the chart. This count starts at the far left in the chart. The strategy will wait til this number of bars have been loaded before processing the OnBarUpdate().

    3) As long as there is a current bar check inside the indicator script you would not have to worry about setting the BarsRequired in the startegy.

    4)No, the strategy will wait til the BarsRequired is met then start processing OnBarUpdate(). So long, as the conditions are true in OnBarUpdate then it will place orders.

    5)Again, this will only affect your strategy by waiting for the BarsRequired to be met and then start processing OnBarUpdate()

    6)No, for indicators, it will need to wait for the largest number for this lookback(300).

    7)Yes, BarsRequired will be reset to the default 20 value when you make changes. You can however, hardcode the BarsRequired in the strategy in the Initialize() Section

    8)That will be a personal preference. I cannot make that decision for you. You can base your strategy logic off of performance versus need if you like.

    http://www.ninjatrader.com/support/h...srequired2.htm
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi Cal!

      thank you for your reply and the detailed answers to my questions. The information is extremely helpful to me.

      I just have a couple of points I'm hoping you can clarify further.

      You stated:

      The BarsRequired will be part of all the bars on the chart. This count starts at the far left in the chart. The strategy will wait til this number of bars have been loaded before processing the OnBarUpdate().
      When you say it "will be part of all the bars on the chart," what does this mean exactly? I've got 30 days loaded on the chart of historical data, plus what's coming in live at the moment... which of these sets of bars is being taken into account by BarsRequired? In other words, if I have 30 days of bars on the chart, doesn't this mean I always have enough to cover a 300 period moving average, etc. as soon as I enable the strategy? Or... is the strategy waiting until 300 "new" historical bars form before it can start calculating the moving average and placing trades? See how this is a bit confusing for me? Here's what the help guide states regarding what BarsRequired means (as you'll notice, there's really no information which would help a new NinjaTrader client gain any understanding of this whatsoever.):

      The number of historical bars required before the strategy starts processing calls to the OnBarUpdate() method. This property is generally set via the UI when starting a strategy.
      So... it mentions "historical bars," but it's not specific as to "which" historical bars. Is it referring to historical bars already on the chart when the strategy is loaded (in my case 30 days worth of historical bars), or... is it waiting for "new" historical bars to form? (I'm assuming that as soon as they form they become "historical")? If it's using all the bars on the chart (30 days worth), then I don't even have to worry about it. There are always enough bars on the chart for it to do its calculations right away in that case. However, if it is referring to "new" historical bars, then the situation changes dramatically, because it means I now have to wait for 300, 6-range bars to form, before the strategy will place a trade (which could take a couple of days in some cases). There's a HUGE difference between 300 bars back... and 300 new bars. Both cases are "historical" bars, but one requires that a trader miss potentially profitable market moves because the strategy is waiting for 300 new bars to form before it will take advantage of them (by which point, the market opportunities will be long gone).

      You also state:

      As long as there is a current bar check inside the indicator script you would not have to worry about setting the BarsRequired in the startegy.
      Again, I'm a bit confused here. Take for example a moving average. By default, many of them have a "default" periodicity of 14. Let's say, in my strategy, I have changed that and I've entered "300" as the period for the moving average when I added it to the condition set in the strategy, and now... it is a 300 period moving average (instead of a 14 period moving average). Is this why I need to set the BarsRequired to "300" in the "Edit Strategy" window? In other words, you mention a "current bar check inside the indicator script..." What does this mean?

      Finally, back to that big question, number 7, where I ask:

      Does "Bars Required" reset every time I make an update to the code and reload NinjaScript via F5? In other words, let's say I've had the strategy running, and I've waited 299 bars, and I notice something which needs to be altered, and I alter it, then reload the NinjaScript to update the chart... does that reset the counter... and now I have to wait another 300 bars before I can trade?
      What I meant by the term "reset" is... does the strategy have to now wait for another 300 bars to form, before it will process my condition sets, and place trades? In other words, when I first load the strategy, it needs 300 bars (in the example of the 300 MA), so if I then disable it, make some modifications to it in the Strategy Wizard, and then re-enable it and reload it into the chart by pressing F5, does it now have to start all over from the beginning waiting for 300 new bars? (With 6 range bars, this could be an entire day or two of waiting). If that's the case, that would mean that every time I make an upgrade to the code, and reload it into the chart, I have to potentially wait days to be able to test the new changes (because of using the range bars).

      I'm asking all of these questions because I, and probably others reading this, are a bit baffled by the BarsRequired parameter.

      Thank you again for taking the time and effort. I know it's your job... but the pride you take in your work shows through. And I thoroughly appreciate that. You and your colleagues are truly helping me get my head around NinjaTrader in a way I never could have by just reading the manual.

      -V

      Comment


        #4
        Originally posted by Aurum View Post
        When you say it "will be part of all the bars on the chart," what does this mean exactly? I've got 30 days loaded on the chart of historical data, plus what's coming in live at the moment... which of these sets of bars is being taken into account by BarsRequired? In other words, if I have 30 days of bars on the chart, doesn't this mean I always have enough to cover a 300 period moving average, etc. as soon as I enable the strategy? Or... is the strategy waiting until 300 "new" historical bars form before it can start calculating the moving average and placing trades? See how this is a bit confusing for me? Here's what the help guide states regarding what BarsRequired means (as you'll notice, there's really no information which would help a new NinjaTrader client gain any understanding of this whatsoever.

        So... it mentions "historical bars," but it's not specific as to "which" historical bars. Is it referring to historical bars already on the chart when the strategy is loaded (in my case 30 days worth of historical bars), or... is it waiting for "new" historical bars to form? (I'm assuming that as soon as they form they become "historical")? If it's using all the bars on the chart (30 days worth), then I don't even have to worry about it. There are always enough bars on the chart for it to do its calculations right away in that case. However, if it is referring to "new" historical bars, then the situation changes dramatically, because it means I now have to wait for 300, 6-range bars to form, before the strategy will place a trade (which could take a couple of days in some cases). There's a HUGE difference between 300 bars back... and 300 new bars. Both cases are "historical" bars, but one requires that a trader miss potentially profitable market moves because the strategy is waiting for 300 new bars to form before it will take advantage of them (by which point, the market opportunities will be long gone).
        Scripts will load from left to right when added to a chart. Thus we can take that count of the BarsRequired from the very start of the chart. When BarsRequired is set to 20, it will wait till the 20 count is met when moving to the right historically. You would not need to worry about the SMA with loading 300 bars, what you will need to do is have the script wait 300 bars before you start calculating, this is because the SMA will start plotting the second the BarsRequired is met on the script. You can do this with either BarsRequried or a CurrentBar check in the OnBarUpdate() -
        if(CurrentBar < 300) return;


        Originally posted by Aurum View Post
        Again, I'm a bit confused here. Take for example a moving average. By default, many of them have a "default" periodicity of 14. Let's say, in my strategy, I have changed that and I've entered "300" as the period for the moving average when I added it to the condition set in the strategy, and now... it is a 300 period moving average (instead of a 14 period moving average). Is this why I need to set the BarsRequired to "300" in the "Edit Strategy" window? In other words, you mention a "current bar check inside the indicator script..." What does this mean?
        I will retract my previous statement and re-iterate what I said above here. This will be done in the Strategy script.
        You would not need to worry about the SMA with loading 300 bars, what you will need to do is have the script wait 300 bars before you start calculating, this is because the SMA will start plotting the second the BarsRequired is met on the script. You can do this with either BarsRequried or a CurrentBar check in the OnBarUpdate() -
        if(CurrentBar < 300) return;
        The reason for this, is because the first bar and the SMA value will be the Close price of the bar and then it will start building the 300 period look back moving forward to each new bar.


        Originally posted by Aurum View Post
        Finally, back to that big question, number 7, where I ask:

        What I meant by the term "reset" is... does the strategy have to now wait for another 300 bars to form, before it will process my condition sets, and place trades? In other words, when I first load the strategy, it needs 300 bars (in the example of the 300 MA), so if I then disable it, make some modifications to it in the Strategy Wizard, and then re-enable it and reload it into the chart by pressing F5, does it now have to start all over from the beginning waiting for 300 new bars? (With 6 range bars, this could be an entire day or two of waiting). If that's the case, that would mean that every time I make an upgrade to the code, and reload it into the chart, I have to potentially wait days to be able to test the new changes (because of using the range bars).

        I'm asking all of these questions because I, and probably others reading this, are a bit baffled by the BarsRequired parameter.

        Thank you again for taking the time and effort. I know it's your job... but the pride you take in your work shows through. And I thoroughly appreciate that. You and your colleagues are truly helping me get my head around NinjaTrader in a way I never could have by just reading the manual.
        -V
        Each time you reset the strategy in the chart it will reload the script completely. Meaning that it will start its calculations all over again from far left to the right. Remember, BarsRequired is working for the historical bars not real time bars.

        I have attached a script that will outline some points in the OnBarUpdate() that you may want to take note in. Additionally, add it to a chart see how the BarsRequired affects the plotting and calculations.
        Attached Files
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hello Cal

          I appreciate your reply!

          You made a statement in your reply that still has me a bit confused. You stated:

          we can take that count of the BarsRequired from the very start of the chart

          What does "start of the chart" mean? Does it mean the first bar if I scroll all the way to the left back across 30 days of bars (which loaded when I opened the workspace)? Does it mean the start of the day's trading session? Does it mean from when the strategy is enabled? It's not clear. If I'm looking at a chart in front of me, that is loaded with 30 days of bars... where is the "start of the chart?"

          The help guide states:

          "CurrentBar: A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. For example, if a chart has 100 bars of data, the very first bar of the chart (left most bar) will be number 0 (zero) and each subsequent bar from left to right is incremented by 1"
          Does this mean that if I load the strategy into a chart which has 1000 bars already formed on it, I can be assured that there are sufficient bars to begin processing OnBarUpdate commands immediately? The reason I ask is because your explanation seems to indicate that only "newly formed" bars are taken into account from the instant the strategy is enabled. But the help guide seems to indicate that if the chart has 1000 bars on it already (starting from the far left of the chart), then there are enough bars to calculate a 300 moving average with 700 bars to spare.

          Going further into your reply (thank you again for it), if I understand your explanation (and I'm not sure I do), if my strategy has a 300 period MA in it, and I disable it and make some changes to the code, and the re-enable it. It now must wait for 300 new bars to form, before it will place orders? Or, as the help guide seems to indicate, if I have 1000 bars on the chart already, there are already enough bars on the chart to handle a 300 period MA, and the strategy can use those bars already on the chart for its calculations, without having to wait for another 300 new bars to form.

          Is the strategy looking back at earlier bars which formed on the chart before I clicked "enable," or is it looking at bars which start to form AFTER I click enable?

          What I'm trying to figure out is, If I set the minimum bars required to 300, does this mean that from the time I click the "Enable" checkbox to enable the strategy, it begins recording each new bar that forms from that moment, until 300 bars have gone by? That essentially means, if it takes two days for 300 six-range bars to form, I must leave the strategy running for two days and wait that entire two days before the strategy will take a trade. This makes no sense to me, and would be a HUGE negative for the software.

          Thank you again for your help here.

          -V

          Comment


            #6
            With all due respect, I think you are trying to read meanings where none are intended.

            The statements are clear. The beginning of the chart is where the first printed bar is placed, on the far left, no matter how many bars are there.

            NinjaTrader is, inter alia, a stream editor, so it reads data in a stream, ALWAYS. That means that whenever you do something that causes a chart to have to reload or repaint, NT starts from the leftmost bar and processes everything from scratch, starting from the first bar on the chart. That means that BarsRequired, and everything else, is evaluated again, starting with bar0. 300 bars means 300 bars starting with the leftmost bar, the very first bar on the chart at ALL times, and counting.

            The first bar on the chart is the first bar on the chart, nothing else. Not the first bar since the session started; not the first bar since you reloaded the indicator or strategy; the first bar on the chart, period. It is the leftmost bar.
            Last edited by koganam; 07-25-2014, 11:41 AM.

            Comment


              #7
              Hi koganam,

              Please don't scold me. If I... a paying customer of NinjaTrader, who uses NinjaTrader to trade real money... have a question about this highly technical new piece of software, to which I am completely new, and need clarification on that question, it is my right, as a paying customer, to ask, on the support forum provided by that software company, until I am clear on the issue.

              You have been a member of this forum since 2008. I've been using NinjaTrader for less than six months. You are a wizard at NinjaScript, so to you, it may seem like trivia, and you must be shaking your head in disgust at my ignorance. But, for me, and many like me, this is a totally new experience, which comes with certain very real risks to our financial security, which must be mitigated through a clear understanding of the software. The only way to gain that understanding is to ask, and ask, until we are clear on a particular issue.

              If Cal's words had been "clear," I would not have spent the time to type the amount of text I typed. I would have been trading or doing something else.

              Terms like "first bar on the chart" and "stream editor" and "reads data in a stream" and "far left" are all completely new terms which I am encountering for the very first time in my life regarding trading software. So, in order for me to gain a benefit from the software I am paying for (and trading real money with), I need to get my head around it, otherwise, the money spent on it (and potentially lost using it without understanding it), is a waste. I don't know about you, but I don't like to waste money, and I would like to get the most complete use out of NinjaTrader that I can (since I am paying for it).

              Please understand, I totally appreciate your expertise and experience, but please, please, remember and be sensitive to the fact that there are those of us who are completely new to this, and who need to gain a HUGE amount of understanding in a very short time in order to gain the fullest benefit, and we're using an internet message forum, where it can be difficult at times to understand what people mean in the words they are typing. Also keep in mind, that the NinjaScript section of the NinjaTrader user guide seems to be geared toward people who already have a thorough understanding of C# language and a thorough understanding of NinjaTrader, which I don't have. So it is necessary for me to supplement that user guide with questions on this forum.

              So, from today forward, if you see me typing huge blocks of text claiming to be completely confused about something, please give me, and others on this forum, the benefit of your patience and understanding. And give me the grace to gain just a fraction of your genius.

              As always... I appreciate your genius, your assistance, and your generosity, and I wish you pleasant days and all good things.

              -V

              Comment


                #8
                Originally posted by Aurum View Post
                Hi koganam,

                Please don't scold me. If I... a paying customer of NinjaTrader, who uses NinjaTrader to trade real money... have a question about this highly technical new piece of software, to which I am completely new, and need clarification on that question, it is my right, as a paying customer, to ask, on the support forum provided by that software company, until I am clear on the issue.

                You have been a member of this forum since 2008. I've been using NinjaTrader for less than six months. You are a wizard at NinjaScript, so to you, it may seem like trivia, and you must be shaking your head in disgust at my ignorance. But, for me, and many like me, this is a totally new experience, which comes with certain very real risks to our financial security, which must be mitigated through a clear understanding of the software. The only way to gain that understanding is to ask, and ask, until we are clear on a particular issue.

                If Cal's words had been "clear," I would not have spent the time to type the amount of text I typed. I would have been trading or doing something else.

                Terms like "first bar on the chart" and "stream editor" and "reads data in a stream" and "far left" are all completely new terms which I am encountering for the very first time in my life regarding trading software. So, in order for me to gain a benefit from the software I am paying for (and trading real money with), I need to get my head around it, otherwise, the money spent on it (and potentially lost using it without understanding it), is a waste. I don't know about you, but I don't like to waste money, and I would like to get the most complete use out of NinjaTrader that I can (since I am paying for it).

                Please understand, I totally appreciate your expertise and experience, but please, please, remember and be sensitive to the fact that there are those of us who are completely new to this, and who need to gain a HUGE amount of understanding in a very short time in order to gain the fullest benefit, and we're using an internet message forum, where it can be difficult at times to understand what people mean in the words they are typing. Also keep in mind, that the NinjaScript section of the NinjaTrader user guide seems to be geared toward people who already have a thorough understanding of C# language and a thorough understanding of NinjaTrader, which I don't have. So it is necessary for me to supplement that user guide with questions on this forum.

                So, from today forward, if you see me typing huge blocks of text claiming to be completely confused about something, please give me, and others on this forum, the benefit of your patience and understanding. And give me the grace to gain just a fraction of your genius.

                As always... I appreciate your genius, your assistance, and your generosity, and I wish you pleasant days and all good things.

                -V
                Very well put. I apologize if I came across as scolding you. That was not my intent. Apparently the smileys did not manage to convey that I meant no rudeness. Just keep at it; we all started somewhere. All the best.

                Comment


                  #9
                  Hi Koganam!!! I do appreciate you and your great knowledge... and your smileys!

                  I also appreciate your understanding. Everyone on these forums is so great, and you really are helping me immensely in my quest to get the most out of NinjaTrader.

                  No harm done... I look forward to reading more of your posts!

                  I'll certainly take closer note of the smileys next time. :-)

                  -V

                  Comment


                    #10
                    Hello Cal,

                    I forgot to to thank you for the script you created for me. That was great, and it helps me see what you were explaining.

                    I now see that once I load the strategy, and set the minimum bars to 300... if I scroll back to the left of the chart... at the very beginning, even though my strategy tells dots to be drawn, there are no dots for the first 300 bars, and after that, dots appear... I get it now!

                    My only concern, and the reason for my original post, was the fear that I was going to have to always wait for 300 new bars to form before I could place a trade or see the results of my edits to the code. I thought to myself: "this is kind of a low point in my NinjaTrader euphoria!" I'm glad to learn (with your help, and with the help of Koganam), that I don't have to grow old waiting to be able to place a trade.

                    Thank you again Cal for your efforts in helping me get my head around the "min bars required" concept.

                    -V
                    Last edited by Aurum; 07-27-2014, 02:43 AM. Reason: Typo

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by inanazsocial, Today, 01:15 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post inanazsocial  
                    Started by trilliantrader, 04-18-2024, 08:16 AM
                    5 responses
                    22 views
                    0 likes
                    Last Post trilliantrader  
                    Started by Davidtowleii, Today, 12:15 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post Davidtowleii  
                    Started by guillembm, Yesterday, 11:25 AM
                    2 responses
                    9 views
                    0 likes
                    Last Post guillembm  
                    Started by junkone, 04-21-2024, 07:17 AM
                    9 responses
                    70 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X