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

BarsRequired and min bars required

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

    BarsRequired and min bars required

    I'm looking to clear up some issues using BarsRequired and to understand when to use min bars required.

    1) In the attached .jpg file is the Initialize() method for a strategy. Will the BarsRequired = 30; statement require 30 bars for each of the 3 preceding Add() statements or only the last Add() statement?

    Background:
    2) In this particular strategy I use or reference functions that use BarsRequired in a few places and I want to make sure I understand what's happening:

    a.] The strategy calls an indicator and this indicator, let's call it Indicator1, has BarsRequired = 16 in its Initialize method.

    b.] In the strategy, there is a function which uses Indicator1. This function uses BarsArray[2] which are 1 day bars. The function requires 30 bars. Thats's why I've included BarsRequired = 30 in the strategy Initialize() method.

    3) So, according to the simple math I should set DaysToLoad = 16 + 30 = 46 and I set min bars required = 0 since all of the bars required by the strategy are already addressed in the BarsRequired statements

    4) However, I'm not able to get the variables to populate with sufficient data unless I set DaysToLoad >= 66.

    Questions:
    1) Why do I need need to add the 20 extra bars (66 - 46 = 20) to get sufficient data into the function included in my strategy code?

    2) If I use BarsRequired throughout my indicator and strategy code will that supersede min bars required? If so, then why would I ever use min bars required? I'd really like to avoid using min bars required b/c it's caused a lot of problems for my strategy.

    3) Why does min bars required work differently in Backtest mode vs. Real-time trading? In backtest mode I didn't need BarsRequired statements at all. I just set min bars required = 66 and the code ran properly. But, in strategy mode, if I exclude BarsRequired statements and set DaysToLoad = 66 and min bars required = 66 the code doesn't run. I can't even force an exception or an error message to occur. BTW, I wasted 2 weeks trying to get my code to run before I figured out this difference b/t backtest mode and real-time mode and how to correct for it.

    Lastly, while I'm glad I figured this out on my own, I can't believe that in my many requests for help from NT support on this issue that no one mentioned this difference b/t min bars required in backtest vs. real-time mode.
    Attached Files

    #2
    bluelou, we will get back to you tomorrow.
    AustinNinjaTrader Customer Service

    Comment


      #3
      okay, thx for the reply.

      BTW, I can send you the code if you'd like to see how min bars required works differently in backtest mode vs. real-time mode.
      Last edited by bluelou; 08-19-2010, 08:04 AM.

      Comment


        #4
        bluelou, here's how it works - DaysToLoad determines how much historical data is loaded on your chart, if you set the min bars to this setting as well, there's no data point to work with as you're adding a daily series to your strategy.

        The MinBarsRequired has to be fulfilled for all series in the strategy, then the OnBarUpdate() would be called and the strategy could start calculating.

        The BarsRequired in an indicator is for visualization purposes only, you can setup how many bars it should wait from the start of the chart before it would display a value, so you can give it some room to stabilize for example.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand,
          That doesn't fully answer my question and I don't agree with you entirely. However, it's not worth debating since it appears that my code is working properly at the moment. Really, my post was for the hapless NT user trying to wrestle with min bars required and to let them know that there's hope.

          I have a separate question regarding a problem w/an output log but I'll put that in a separate thread.

          Thx,
          Lou
          Last edited by bluelou; 08-19-2010, 08:58 AM.

          Comment


            #6
            Behaviour I don't understand with BarsRequired

            Hi there...I have a strategy where I have set the BarsRequired to 5. when I run this strategy it doesn't load,. When I set the BarsRequired to 20 it does.

            It uses 144 volume bars and the EMA indicator.

            My thinking was that if the strategy can load fine with BarsRequired=20, then surely it would load with BarsRequired=5, because if ther are 20 bars on the chart, then of course there are 5!

            What am I missing? Many thanks, Adam

            Comment


              #7
              Hi Adam, do you mean the strategy is then disabled by NT, or would not produce the trades you seeked?
              BertrandNinjaTrader Customer Service

              Comment


                #8
                I mean the strategy is disabled by NT - it appears in the list of strategies on the strategies tab, but the 'white' and not 'green', with the check box on the right unticked (even when I tick it, it unticks itself).

                In order to work around this I either change the BarsRequired field, or change the number of day's data the chart loads. I can't seem to work out the logic.

                Comment


                  #9
                  How many bars do you load have you chart when the strategy fails to activate for you?
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Normally I load 3 days worth of data on opening the chart, and the BarsRequired is 5. The number of bars is a lot, as the chart is 6E, with candles of 144 volume. At least 50 if not 100 bars are on the chart when it loads.

                    I then try to load 10 days, and the strategy still does not activate. I then change the Bars Required from 5 to 20, and it activates. I have tried combinations of 3, 5, 10, 15, 20, 25 days, and Bars Required from 2 to 20.

                    I normally just keep on changing either the days loaded, or the BarsRequired until it activates...but I always start with 3 days and 5 BarsRequired, and it almost never activates on this.

                    Comment


                      #11
                      Thanks - I would expect this only if you were adding a higher timeframe internally. Are you adding any frame here internally via the Add() in your Strategy Initialize()?
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Nope. Here is my strategy initialize:


                        protected override void Initialize()
                        {

                        CalculateOnBarClose = false;
                        TraceOrders = true;
                        BarsRequired = 2;
                        ClearOutputWindow();

                        // Allow three simultaneous entries
                        EntriesPerDirection = 3;

                        // Add a Renko Bar object for the 6E 06-12 contract - BarsInProgress index = 1
                        AddRenko("6E 09-12", 3, MarketDataType.Last);

                        // Plot indicators on chart
                        Add(HeikenAshi());
                        Add(EMA(ema1));
                        Add(HMA(hma1));
                        Add(VolumeCounter(true, false));

                        EMA(ema1).Plots[0].Pen.Color = Color.Blue;
                        HMA(hma1).Plots[0].Pen.Color = Color.DeepPink;

                        }

                        Hope this helps...

                        Comment


                          #13
                          Thanks Adam, well you add a Renko series here programmatically - so you need to have the Bars required passed for all series.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            I have the following code in the OnBarUpdate event:

                            protected override void OnBarUpdate()
                            {
                            // Checks to ensure all Bars objects contain enough bars before beginning
                            if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
                            return;

                            Comment


                              #15
                              Right Adam, but that's not connected to the issue you're having, you're strategy is not giving you any runtime / indexing errors but not starting up due to BarsRequired not being passed for all series involved.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by smartromain, 03-13-2024, 01:42 AM
                              5 responses
                              92 views
                              0 likes
                              Last Post AndreiBig  
                              Started by Noerclou, Today, 04:55 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Noerclou  
                              Started by llanqui, Yesterday, 09:59 AM
                              2 responses
                              17 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by ThoriSten, Today, 03:56 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post ThoriSten  
                              Started by PhillT, 04-19-2024, 02:16 PM
                              3 responses
                              25 views
                              0 likes
                              Last Post mangel2000  
                              Working...
                              X