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 missing bar data

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

    IsFirstTickOfBar missing bar data

    Hello There

    I created a simple script that prints the bar time on every first tick of bar recieved.
    however it seems for some reason this IsFirstTickOfBar does not work for me or it is skipping bars when there is a gap.


    MyScript.
    if (IsFirstTickOfBar)
    {
    Print(Time[bi].TimeOfDay + " Checking");
    }


    My Output.
    15:28:30 Checking
    15:29:00 Checking
    15:30:30 Checking
    15:31:00 Checking
    15:31:30 Checking


    It seems to maybe happen when ever there is a gap on the chart,
    if looking at the chjart for these two missing times.
    15:29:30 and 15:00:00 it seems they are gapping a bit,

    what causes this and how can i handle this ?

    My end goal is to execute some code as close as posible to the open.
    at the moment i am checking for the end time of the previous candle and if it is first tick of bar.

    is there a better way to do this ?

    #2
    Hello donto,

    Thank you for your inquiry.

    In 'Time[bi].TimeOfDay', what is 'bi' defined as?

    What instrument (including expiry contract month), bar type, and interval are you testing?

    Are you testing using the Strategy Analyzer?

    If this isn't in the Analyzer, if you right-click within the chart > Reload Historical Data are these bars still missing?

    Are you seeing any errors in the Log tab of the Control Center?

    We also have a reference sample that may be useful to you that demonstrates using IsFirstTickOfBar to separate logic to either calculate once for each bar, or on every tick:



    I look forward to your response.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hello Gaby

      bi is defined as 1
      so it should print the close time of the previous bar / open time of current bar.


      I am testing in Market Replay in the above example,

      but i just this instance was running it live to test and i get same results.

      15:28:30 Checking
      15:29:00 Checking
      15:30:30 Checking
      15:31:00 Checking

      I can try doing something in strategy analyzer.

      i do not see any errors or anything in the output or the log.

      Comment


        #4
        Hello donto,

        Thank you for your response.

        What instrument (including expiry contract month), bar type, and interval are you testing?​

        I would like to test and review the chart on my end.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Ohh Sorry missed that.
          it is MNQ 03-24
          30 seccond normal standard bars.

          If i open a NQ chart and run through it i get same results there.

          15:25:00 Checking
          15:25:30 Checking
          15:26:00 Checking
          15:26:30 Checking
          15:27:00 Checking
          15:27:30 Checking
          15:28:00 Checking
          15:28:30 Checking
          15:29:00 Checking
          15:30:30 Checking
          15:31:00 Checking
          15:31:30 Checking
          15:32:00 Checking
          15:32:30 Checking
          15:33:00 Checking
          15:33:30 Checking
          15:34:00 Checking
          15:34:30 Checking
          15:35:00 Checking
          15:35:30 Checking
          15:36:00 Checking
          15:36:30 Checking​
          Last edited by donto; 02-08-2024, 08:51 AM.

          Comment


            #6
            After testing back and forth i tested with another Trading Hours template and found that by changing this it does not happen.
            I offcourse have a template making a break excatley at the open.

            will do some more testing an posible some changes to this and return.
            Last edited by donto; 02-08-2024, 09:05 AM.

            Comment


              #7
              Hello donto,

              Thank you for letting me know that info.

              If your trading hours template is set to up break / end at the open, this could be why you are are not seeing those bars on the chart. From the Help Guide:

              "When a template is applied, any data outside of the times in the session definitions will be ignored."

              HTML Code:
              https://ninjatrader.com/support/helpGuides/nt8/index.html?using_the_trading_hours_window.htm#UnderstandingTradingHourTemplates
              Since the data is ignored, OnBarUpdate() does not get an update on those bars, so you wouldn't see any prints and IsFirstTickOfBar cannot be true for bars outside of the session definitions.

              Please let me know if you have any further questions.
              Gaby V.NinjaTrader Customer Service

              Comment


                #8
                try this

                if Calculate = oneachtick
                in OnBarUpdate
                Code:
                if (Time[0].Hour == 9    && Time[0].Minute == 30        && Bars.TickCount < 2 )
                            {
                            }​
                if Calc = on bar close
                Code:
                if (IsFirstTickOfBar    && Time[0].Hour == 9    && Time[0].Minute == 30 )
                            {
                            }​

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by JoMoon2024, Today, 06:56 AM
                0 responses
                6 views
                0 likes
                Last Post JoMoon2024  
                Started by Haiasi, 04-25-2024, 06:53 PM
                2 responses
                17 views
                0 likes
                Last Post Massinisa  
                Started by Creamers, Today, 05:32 AM
                0 responses
                5 views
                0 likes
                Last Post Creamers  
                Started by Segwin, 05-07-2018, 02:15 PM
                12 responses
                1,786 views
                0 likes
                Last Post Leafcutter  
                Started by poplagelu, Today, 05:00 AM
                0 responses
                3 views
                0 likes
                Last Post poplagelu  
                Working...
                X