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

DateTime in OnBarUpdate

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

    DateTime in OnBarUpdate

    If I put something like

    Print(DateTime.Now);

    in OnBarUpdate, the time is only updated with each incoming tick. If I wanted to update DateTime.Now in real time (aka the time is updated every second, like a clock would display), how would I do this?

    Edit: I know there is OnMarketData which might update faster than OnBarUpdate, but I guess what I'm looking for would be something like "OnSecondUpdate," if that makes sense.
    Last edited by Radical; 12-14-2011, 05:35 PM.

    #2
    Hello Radical,

    You would have to create a timer object and then this could control when you raise the Print statement. This sample can help work with timer objects:


    This works well for things like Print statements which send to the output window.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Edit: Never mind.
      Last edited by Radical; 12-14-2011, 06:31 PM.

      Comment


        #4
        I got the Timer working, but my problem now is that I have an 'if' statement in which one of the conditions needs to be updated on each incoming tick, and one condition needs to be updated according to the Timer object:

        if (DateTime.Now == Time[0] && High[0] > 1)

        'DateTime.Now == Time[0]' would need to be updated by the Timer, and 'High[0] > 1' would need to be checked on each incoming tick. Is there a solution to this?

        Comment


          #5
          I'm not sure exactly what you're trying to do, but judging from your first post you want to process something with a timed interval. When your timer event is raised, just do your check at that point for both conditions. If both conditions are met, have it do whatever you want from within the eventhandler. It won't "update" the High[0], it will just check the current state at that point in time.

          Hope this helps.

          VT

          Comment


            #6
            Thanks for the response VTtrader, that was what I had originally thought of doing once I figured out how to get the Timer working, but then I realized this problem:

            If I have my entry conditions within the event handler and the event handler updates every 1 millisecond (this is the lowest interval allowed by Timer.Interval), will this be slower than having my entry condition contained within OnBarUpdate instead? The way I understand it, the event handler will check to see if my entry conditions are met every 1 millisecond, but OnBarUpdate will check to see if my entry conditions are met as soon as a new tick is received, which could occur in between the 1ms checks that would be done by the event handler.

            Am I being ridiculous about this? I know 1ms is really fast, but I don't know if that would make a difference or not in terms of fills. Sorry if it's hard to understand what I'm trying to say...I'm not a programmer, and I don't really know the best way to express what I mean when it comes to programming. So if anything needs clarification let me know.

            Edit: I think I answered my own question....if my entry logic includes a condition that relies on the Timer, the Timer.Interval is going to be a limiting factor whether my entry logic is within either the event handler or OnBarUpdate, so I guess it doesn't really matter.
            Last edited by Radical; 12-15-2011, 01:57 AM.

            Comment


              #7
              Is the timer's purpose solely to raise an event for placing a trade? If that is the case than I would say just use OnBarUpdate(). If you're checking for a DateTime condition, then you will still be limited by the minimum allowed interval, but you will be able to check your DataTime condition, so it could make sense in that case.

              IMO though, I wouldn't be that concerned with 1ms as not being "fast enough". Unless you're developing a HFT system that is physically located at the exchange, there are FAR greater bottlenecks in a normal setup. I would further add, if <1ms (actually quite a bit more) is going to make or break a system, then it probably isn't stable enough to use over an internet connection.

              VT

              Comment


                #8
                Thanks VT, after thinking about it more in the context of my strategy, I agree with your post below, and I've actually decided to abandon the whole Timer thing altogether.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Brevo, Today, 01:45 AM
                0 responses
                3 views
                0 likes
                Last Post Brevo
                by Brevo
                 
                Started by aussugardefender, Today, 01:07 AM
                0 responses
                3 views
                0 likes
                Last Post aussugardefender  
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                239 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                384 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Started by oviejo, Today, 12:28 AM
                0 responses
                6 views
                0 likes
                Last Post oviejo
                by oviejo
                 
                Working...
                X