Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

End of historic data call

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

    End of historic data call

    Hello

    I would like to do some time consuming computations after last historic bar is received. I need to have access to performance, price and indicators.

    Could you please let me know how should I call such function so it is executed only one time at the end. I theoretically can look for previous and next bars and when there is a swith from historic to realtime bar call this function fron onbarsupdate but I am wondering if you know a better way.

    Best ergards,
    Sergey.

    #2
    sergeysamsonov,

    I am happy to assist you.

    You could use a time filter, i.e.
    Code:
    private Datetime CurrentTime;
    
    protected override void Initialize()
    {
      // code here
    
      CurrentTime = Datetime.Now.TimeOfDay;
    }
    
    protected override void OnBarUpdate()
    {
         if( Time[0].Day < CurrentTime.Day || Time[0].Hour < CurrentTime.Hour || Time[0].Minute < CurrentTime.Minute )
         {  
                 return;
         }
        else
        {
                //do intense computation
        }
    }
    For more information on Datetime objects, please see the following link.

    Represents an instant in time, typically expressed as a date and time of day.


    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you AdamP, this is exactly what I need. Is there a way to stop OnBarUpdate calls untill this time consuming routine finishes? My concern is that this routine will be called many times on each bar update.

      Best ergards,
      Sergey.

      Comment


        #4
        sergeysamsonov,

        Sure. You could make a flag that is default to true, then after the code is run it sets the flag to false.

        Code:
        private Datetime CurrentTime;
        private bool RunFlag = true;
        
        protected override void Initialize()
        {
          // code here
        
          CurrentTime = Datetime.Now.TimeOfDay;
        }
        
        protected override void OnBarUpdate()
        {
             if( Time[0].Day < CurrentTime.Day || Time[0].Hour < CurrentTime.Hour || Time[0].Minute < CurrentTime.Minute )
             {  
                     return;
             }
            else if(RunFlag)
            {
                    //do intense computation
                    RunFlag = false;
            }
        }
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thank you. This is good.

          And I have one more questions.

          Is there a way to find out after all historical bars were processed at what historical bar any particular trade entry was taken so I can calculate values of indicators for that bar at later time.

          I assume if I start with Performance object I can trace to entry bar. Or may be the only way is to check entry time and then convert it to entry bar (fast changing range bars)?

          Thank you very much and best regards,
          Sergey.

          Comment


            #6
            entry bar

            Hello

            Is there a way to find out after all historical bars were processed at what historical bar any particular trade entry was taken so I can calculate values of indicators for that bar at later time.

            I assume if I start with Performance object I can trace to entry bar. Or may be the only way is to check entry time and then convert it to entry bar (fast changing range bars)?

            Thank you very much and best regards,
            Sergey.

            Comment


              #7
              sergey,

              When a trade occurs, you could use http://www.ninjatrader.com/support/h...nexecution.htm to catch the execution times of trades, then store this in some kind of datetime dataseries. Then, you can go through bars and compare times.

              If you use iOrder objects, the time gets updated whenever the order does so its not guaranteed to be the opening time of the order.

              Another way would be to store some kind of count of how many bars in the past each order was.

              I.e. Have a dataseries of integers, add a new element every time an order takes place with value 0. Every OnBarUpdate() increment every element of the dataseries.

              Either way it may be computationally complex if a lot of orders are generated.

              Please let me know if I may assist further.
              Adam P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              648 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              369 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              572 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              573 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X