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

Align time of events with bars

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

    Align time of events with bars

    Hello,

    I am trying to align Market Data events with the bar where they occur, and, if it is the first event in the bar, then do some initializations. I could do that in OnBarUpdate, but only if I could be sure that OnBarUpdate event always comes first that the asociated Market Data event for the same tick. It is possible to assume any fixed secuence in the occurence of these events? If yes, which comes first?

    Thank you for any help.

    #2
    OnMarketData() comes first. Ultimately its the same event though so not sure why you really need to make a distinction?

    In OnBarUpdate() you could just go if (FirstTickOfBar) and then do whatever it is that you need to do on the first tick.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your quick reply,

      I´m calculating cumulative volumes for each bar, thats why I need to initialaize all variables at the beginning of each bar, if I do it using FirstTickofBar, I will lose the volume info related with the MarketData event which produce that first tick for the bar. Am I right?

      I need to do it on OnBarUpdate because from OnMarketData I don´t have access to Bars object or Time object.

      Comment


        #4
        telbentel,

        You could grab the volume info directly off the OnBarUpdate() method. When FirstTickOfBar == true, checking Volume[0] on that event = the volume of that tick. You can then keep a variable that keeps track of the prior event's volume and then on each subsequent event check Volume[0] and subtract prior volume from it to get the current tick's volume.

        currVol = Volume[0] - prevVol;
        prevVol = Volume[0];
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        23 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        21 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X