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

IsFirstTickOfBar compatible with the simulated data feed?

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

    IsFirstTickOfBar compatible with the simulated data feed?

    I'm trying to work on my indicator this weekend when the markets are closed. It was working yesterday with live markets, but with sim data it doesn't. I have a Print() in OnBarUpdate that was printing about every half second even though the chart bars are only painted about ever 10 seconds. So, I put it inside a if(IsFirstTickOfBar){Print(x++);} and I am still getting text printed to the output window about every half second. I even tried setting my data series to only load 200 bars and deleted everything in the onbarupdate method except for the "if" statement... same result. Bars paint about every 10 seconds, but the output screen prints and incremented number every half second.

    #2
    Hello Chippy,

    May I have you print the value of IsFirstTickOfBar outside of any conditions (at the top of OnBarUpdate()).

    Try printing the following:
    Print(string.Format("{0} | Calculate: {1}, BarsPeriod.BarsPeriodType: {2}, BarsPeriod.Value: {3}, State: {4}, IsFirstTickOfBar: {5}", Time[0], Calculate, BarsArray[BarsInProgress].BarsPeriod.BaseBarsPeriodType, BarsArray[BarsInProgress].BarsPeriod.Value, State, IsFirstTickOfBar ));

    Save the output to a text file and include this as an attachment to your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea... apologies for not getting back to you sooner. Here is the result of the test you asked me to run...

      2/23/2022 11:44:59 AM | Calculate: OnBarClose, BarsPeriod.BarsPeriodType: Minute, BarsPeriod.Value: 1, State: Realtime, IsFirstTickOfBar: True

      Comment


        #4
        Chelsea, it looks like I'm getting the same behavior with my continuum data as well, so it doesn't appear to be just simulated data.

        Comment


          #5
          Hello Chippy,

          This is one line of output.
          Is this the only line that appeared in the output window?
          To save the output to a text file, right-click the output window, select Save As.

          That said, Calculate is OnBarClose. So the prints will only be appearing when the bar closes. IsFirstTickOfBar will always be true as the bar only updates once.

          From the help guide:
          "Indicates if the incoming tick is the first tick of a new bar. This property is only of value in scripts that run tick by tick which is when the Calculate property is set to Calculate.OnEachTick or Calculate.OnPriceChange."
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Chelsea, attached is the file requested, however, I placed the print statement inside the If(isFirstTick) statement to prove that the if(isFirstTick) is not only running on the first tick. There are no loops in my code. In fact, I commented out every line except for your print statement. I've also changed the Calculate property to OnEachTick. I'm using a 1 minute chart, though the problem was first noticed on a range 2 chart. Notice that your print statement is being printed multiple times per minute and should only be printed once.

            For the record, I have used isFirstTick successfully prior to this issue. I don't have a clue what could be causing this. I will put your print statement at the top of the OnBarUpdate method and follow up in about two minutes.
            Attached Files

            Comment


              #7
              Wow... weird. Attached is the output with the print statement as the first line in OnBarUpdate...Seems like it's printing twice and not in chronological order! I forgot to mention that I am completely removing the indicator from the chart, applying, then reloading it after each edit.
              Attached Files

              Comment


                #8
                Hello Chippy,

                Does this script add a series with AddDataSeries()?

                Attached is a test script that is not able to reproduce on my end.
                Attached Files
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Yes! It's in State.Configure

                  Comment


                    #10
                    Hello Chippy,

                    Thats likely the issue. Are you ensuring that these are for specific BarsInProgress or BarsArray series?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Chelsea, honestly, I don't really understand what that method is doing. I don't recall where or how I found it now (probably from reading one of the sample indicators), but without it, I get the following error:

                      'Order Flow Cumulative Delta' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load ES 03-22 Globex: 1 Tick

                      This indicator is where I added another indicator to an existing indicator. Here I instantiated the cumulative delta object.

                      CumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 0);

                      Here is the offending method. Is there another way or a fix, to get the cumulative data object inserted into my indicator without the adddataseries?

                      AddDataSeries(Data.BarsPeriodType.Tick, 1);

                      Comment


                        #12
                        Hello Chippy,

                        You have added a 1 tick series to the script. This means that there are 1 tick bars updating OnBarUpdate(). This is what you printing.

                        IsFirstTickOfBar is true because each bar is 1 tick.

                        Try printing for BarsInProgress 0, the primary series.

                        if (BarsInProgress == 0)
                        {
                        Print(string.Format("{0} | Calculate: {1}, BarsInProgress: {2}, BarsPeriod.BarsPeriodType: {3}, BarsPeriod.Value: {4}, State: {5}, IsFirstTickOfBar: {6}", Time[0], Calculate, BarsInProgress, BarsArray[BarsInProgress].BarsPeriod.BaseBarsPeriodType, BarsArray[BarsInProgress].BarsPeriod.Value, State, IsFirstTickOfBar ));
                        }

                        Below is a link to the help guide on BarsInProgress, BarsArray, CurrentBars, Closes, and Times.




                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Perr0Grande, Today, 08:16 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Perr0Grande  
                        Started by elderan, Today, 08:03 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post elderan
                        by elderan
                         
                        Started by algospoke, Today, 06:40 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post algospoke  
                        Started by maybeimnotrader, Today, 05:46 PM
                        0 responses
                        12 views
                        0 likes
                        Last Post maybeimnotrader  
                        Started by quantismo, Today, 05:13 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post quantismo  
                        Working...
                        X