Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar

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

    CurrentBar

    I am using Strategy analyzer and I am running my multi-Instrument strategy. I am printing this value out the value is over 800. I am expecting a number between 15 and 20 since it just past 9:00 am central and I am using a 2 minute time frame. Is there something I should be dong to reset this value to be correct for each day? I am only running the strategy for one day.

    #2
    Hello [email protected],

    This depends on the variable and the behavior you want.

    In the strategy analyzer, selecting a single day will typically include the previous day as well due to the way sessions overlap overnight.

    Are you asking why the CurrentBar value is printing as 800?
    (Are there not 800 bars in either series?)

    Are you asking about the value of a custom variable?

    If you want your variable reset each day, then you can reset this when Bars.FirstBarOfSession is true.


    A common mistake is adding multiple series and then not adding logic to have code execute when a specific series is processing by using a condition that checks for BarsInProgress.


    I recommend you add more prints. Print the time and the bars in progress and the values of all variables in conditions as well as the value of the variable in question that is being set on every bar.
    Are the conditions true when you expect?
    Is the calculation done what you expect for each bar?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. The CurrentBars[BarsInProgress] for a Multi-Instrument, should this property be reset to starting with an int of zero. This is a system propery I can not update. My understanding of this property is that it should be the number of bars since the start of market. I trade equities. So in a 2 minute Bar at 9:00 AM there should be 15 bars. Market start at 8:30 . 30 minutes. Half of 30 is 15. Is this correct?

      Comment


        #4
        Hello [email protected],

        CurrentBar(s) is not a settable property.

        CurrentBar will represent the bar that is being processed. This starts with bar 0 on the left side of the chart.


        CurrentBars is a collection of CurrentBar for each series in a multi-series script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your reply. At 8:30 AM Central the start of the equities market I am getting a value of 796 for the CurrentBars[BarsInProgress] in the strategy analyzer. Why is that. Is there a way of getting 0 at 8:30 for the equities market. Do I need to just subtract a 796 every time? Would it work the same when I am running my strategy live?

          Comment


            #6
            Hello [email protected],

            The only way to have a bar be CurrentBar 0 would be if it were the first bar on the chart.

            Why do you need CurrentBar to be 0?

            I'm not understanding your goal or what you are trying to do.

            CurrentBar is generally used to ensure you have enough bars before you start processing, and can also be used if you are trying to calculate a barsAgo value from a bars.GetBar() call. Other than that, I am unsure of what you would be trying to use CurrentBars for.

            If you want to know if a bar is the first bar of a new session use Bars.IsFirstBarOfSession.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              In my strategy I want to know when I have the highest volume of the day. So I need to loop back in the volume[] array to compare to the current bar. I need know how far back I need to loop thru . I actually want to loop back 15 minutes after the start of the session.

              Comment


                #8
                Someone generously gave me this following code but it needs to now how far back to look for the highest volume.

                privateintReturnHighestVolumeBar(intLookback)
                {
                for (int indx = 0; indx < Lookback; ++indx)
                { Print("CurrBAr= " + CurrentBars[BarsInProgress] + "Lookbak= " + Lookback);
                if (indx < CurrentBars[BarsInProgress]-804)
                if (Volume[indx] > Volume[0])
                return indx;
                }
                return 0;
                }

                Comment


                  #9
                  Hello [email protected],

                  I'm not certain that I am understanding. If CurrentBar were set to 0, how would this allow you to loop back through previous bars?

                  Are you wanting to loop from the CurrentBar to the first bar to make comparisons?
                  Code:
                  for (int i = 0; i < CurrentBar - 1; ++i)
                  {
                  // i represents the bars ago value
                  Print(Time[i]);
                  }
                  This would print the time of every bar starting with the most recent bar going backward.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Yes that is exactly what I am doing I am looping back to the beginning. But the CurrentBars[BarsInProgress] for Miulti Instrument, would have me go back to many bars. I want to start at the beginning of the equity session 8:30 AM central. When I run the Strategy analyzer 8:30 the value for CurrentBars[BarsInProgress] is 796. Should I just subtract 796 from the CurrentBars[BarsInProgress]. Would that work when I go live?

                    Comment


                      #11
                      Hello [email protected],

                      What value are you referring to?

                      Are you talking about your loop?

                      Your loop is printing the same value over and over and over?

                      Are you talking this Print?
                      Print("CurrBAr= " + CurrentBars[BarsInProgress] + "Lookbak= " + Lookback);

                      This is printing CurrBAr=796 over and over and over and over?

                      This is expected. You are printing the current bars value over and over.

                      BarsInProgress is the index of the series that is processing. You are printing the current bar of the series that is processing over and over.

                      Notice how I use a variable that is incremented on each pass of the loop. ++i increments i so it grows by 1 each time. I'm also not printing the currentbar, i'm starting my loop at 0 and on each pass printing the time with that bars ago value and then increasing by 1 until i is as large a the current bar and then it stops.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi I understand all that. the routine that I sent you is called for each bar and for each instrument. The method receives a integer that tells it how far back to check for the Highest volume. At 8:32 that number should be 0. At 8:34(its at 796) it should be 1(its at 797). At 8:36 it should be 2(its at 798). The method will go on until it has found a higher volume or until it goes back the number of times the parameter is pass in. Please dismiss the print I put it in there for debug purposes.

                        My strategy starts up at 9:00 and tries to find if the current bar is the highest volume. It passes in the value from CurrentBars[BarsInProgress] which is at like 810. What I a m asking is why is it 810 should it not be something like 15((30 minutes/2 minute bar )? Should I subtract the 796 that we start with to get to the 15. Will this work in production when I am not running the strategy analyzer .

                        Comment


                          #13
                          Hi [email protected],

                          No, I do not suggest you subtract any hard coded numbers..

                          CurrentBar represents the current bar of which ever bars in progress is processing.

                          CurrentBars[BarsInProgress] will provide the exact same value and is also the current bar of which ever bars in progress is processing.

                          I am suggesting you use a variable and increment it in a loop. This would start at 0 and would stop at the number of bars on the chart.

                          As far the logic goes, you may want to contact the original author for further assistance.

                          The condition in the code you added simply stops evaluating if the barsAgo value being checked is more than 804 bars ago. I have no idea why this would be there and I wouldn't recommend it.

                          You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            A Ninja Professional I can not afford unless I get one of these strategies well. This is the link to the thread that I got the code. I understand it well. I trying to get someone else to understand it is something else.


                            I believe that the problem is with Strategy analyzer . Tommorrow I will run by code in simulation and see what the values are for the CurrentBars[BarsInProgress]. Thanks for you help

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by algospoke, 04-17-2024, 06:40 PM
                            6 responses
                            48 views
                            0 likes
                            Last Post algospoke  
                            Started by arvidvanstaey, Today, 02:19 PM
                            4 responses
                            11 views
                            0 likes
                            Last Post arvidvanstaey  
                            Started by samish18, 04-17-2024, 08:57 AM
                            16 responses
                            61 views
                            0 likes
                            Last Post samish18  
                            Started by jordanq2, Today, 03:10 PM
                            2 responses
                            9 views
                            0 likes
                            Last Post jordanq2  
                            Started by traderqz, Today, 12:06 AM
                            10 responses
                            20 views
                            0 likes
                            Last Post traderqz  
                            Working...
                            X