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

Time issue

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

    Time issue

    if(DateTime.Now.Date == DateTime.Today && ToTime(Time[0]) > 093000 )

    I read this as do something when it's today and after 930 am.
    is this correct?

    if It is then I have an issue lol!

    #2
    Yes lah......

    Tell us the issues, bro,

    Comment


      #3
      I want to draw a ray from an indicator only between those 2 times and only for today.
      Each time it ignores the day - but does follow the time.

      if(DateTime.Now.Date == DateTime.Today && ToTime(Time[0]) > 093000 )
      blueray = Draw.Ray(this,"p"+CurrentBar,Time[0],Close[0] ,midnight,Close[0],IsRayGlobal,"Blue Ray");

      I should add I also get object doesn't exist errors as well!!

      Comment


        #4
        I simply don't understand why it reads yesterday's bars as today?

        Comment


          #5
          Hello Mindset,

          What do you mean it reads yesterdays bars as today? Are you seeing this drawn on the wrong bar or what specifically is the problem that you see?

          Time[0] represents the last closed bar, depending on what series you used that may be yesterday if you are using a Daily series.

          DateTime.Now is your PC clock which holds no relevance toward NinjaScript, Generally you should avoid using this in your code, the Date and Time will always be from Today right now. If you need to reference the PC clock you should do so using the correct property which includes the platforms time offset settings. NinjaTrader.Core.Globals.Now


          I look forward to being of further assistance.


          JesseNinjaTrader Customer Service

          Comment


            #6
            Ok so how do I properly ( Ninjascript wise) check that now is today?
            i tried == DateTime.Today and also ToDay(Time[0]) - both produce errors
            Last edited by Mindset; 01-13-2021, 01:39 AM.

            Comment


              #7
              Hello Mindset,

              You can use NinjaTrader.Core.Globals.Now. That variable represents the equivalent of DateTime.Now, its the PC time including the timezone settings you set in the options menu.

              You could compare the processing bar time against NinjaTrader.Core.Globals.Now to know if that bar was today.

              Code:
              if(NinjaTrader.Core.Globals.Now.Date == Time[0].Date)
              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thanks very much Jesse. Time[0].Date - so simple!!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by RubenCazorla, Today, 09:07 AM
                2 responses
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by i019945nj, 12-14-2023, 06:41 AM
                7 responses
                82 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by timmbbo, 07-05-2023, 10:21 PM
                4 responses
                158 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by tkaboris, Today, 08:01 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by Lumbeezl, 01-11-2022, 06:50 PM
                31 responses
                820 views
                1 like
                Last Post NinjaTrader_Adrian  
                Working...
                X