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

Convert current date to Julian Date

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

    Convert current date to Julian Date

    Can you give me an example to how to convert the current date to JulianDate please

    #2
    Hello jkt1120,

    While this would not be specific to NinjaScript and is a general C# inquiry, I have done a quick google search for you.

    I need to convert from a standard Gregorian date to a Julian day number. I've seen nothing documented in C# to do this directly, but I have found many posts (while Googling) suggesting the use of
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea, Sorry but I'm not a C# programmer so I'm not sure how to implement your solution, What I'm basically trying to do is figure out if a Date timestamp is 3 days earlier than the current Date. Is there an easier way to do that in NinjaScript?

      Comment


        #4
        Hello jkt1120,

        You should be able to copy the method suggested on stack overflow within the class of your script, and then supply the date to that.

        Finding if a time stamp is 3 days earlier than the current date would not involve converting the time to Julian in any way.

        Code:
        if (Time[0] <= Core.Globals.Now.AddDays(-3))
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea, thanks for the help but I think I need a little more, I'm now getting this when I compile the strategy:

          'NinjaTrader.Cbi.Core' does not contain a definition for 'Globals'



          if (Time[0] <= Core.Globals.Now.AddDays(-3))


          Comment


            #6
            Hello jkt1120,

            Apologies, I overlooked this was for NinjaTrader 7 and not for NinjaTrader 8.

            For NinjaTrader 7 you could use the general c# DateTime.Now.
            Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.


            Please note, NinjaTrader 7 is no longer in active development and we are no longer considering new feature requests or changes for NinjaTrader 7. Main development has shifted to our flagship platform NinjaTrader 8. This does mean updates from brokerages, data feeds, or operating systems that require an update in NinjaTrader will not be implemented in NinjaTrader 7 and may cause an interruption in service.

            While there is not a set ETA for the complete discontinuation of NinjaTrader 7, we highly recommend transitioning to NinjaTrader 8 as soon as possible before NinjaTrader 7 reaches its end of life to prevent interruption of service.

            Click below to download NinjaTrader 8.
            NinjaTrader is a futures trading platform that delivers integrated multi-device trading. Discover our best platform to trade futures for active futures traders.
            Last edited by NinjaTrader_ChelseaB; 06-13-2022, 03:32 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Good morning Chelsea, I hate being such an idiot, sorry but its still not working (Remember it Ninjatrader 7 if that matters)
              Strategy\JKTZones.cs The type or namespace name 'Core' does not exist in the namespace 'NinjaTrader' (are you missing an assembly reference?)

              Comment


                #8
                Hello jkt1120,

                DateTime.Now is in the System namespace from C#. See the documentation linked in post #6.

                if (Time[0] <= DateTime.Now.AddDays(-3))
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello again Chelsea, I got the statement " Time[0].Date > DateTime.Now.AddDays(-daysLookBack) " working in realtime, thank you, however I had to do some back testing with Replay and I guess the attribute .Now is picking up today's current date. Can this be programmed differently for Replay testing? Again thank you very much for your help :-)

                  Comment


                    #10
                    Hello jkt1120,

                    For NinjaTrader 8 this would be Core.Globals.Now.

                    There is no documented equivalent for NinjaTrader 7, but you could try Bars.MarketData.Connection.Now.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Chelsea, one more question, could you please give me an example in NinjaScript on how to write a statement using it:

                      Bars.MarketData.Connection.Now

                      Comment


                        #12
                        Hello jkt1120,

                        This would not be documented so I would not have a script example.

                        This would be a date time object.

                        Print(Bars.MarketData.Connection.Now);

                        or

                        if (Time[0] > Bars.MarketData.Connection.Now.AddDays(-1))
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Chelsea, I need to remove the time portion of date time to only have the Date. (Ninjatrader 7 Strategy)

                          When I Googled it "Stackoverflow" gave me this suggestion:

                          zoneDate = DateOnly.FromDateTime(DateTime.Now);

                          but I getting a compile error "the name "DateOnly" does not exist in the current context"

                          Can you advise please .... Jack





                          Comment


                            #14
                            Hello jkt1120,

                            The code you posted is for a later version of C# which NinjaTrader does not use. To clarify are you still asking about getting a julian date or are you trying to use the PC clock and store that to a variable?

                            The DateTime objects in C# have a Date property:

                            Code:
                            DateTime.Now.Date
                            Time[0].Date
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              These may also be useful, particularly for the question as originally asked:Using the JulianCalendar Class may provide an easy and reliable way to achieve the desired outcome.

                              Thanks.
                              Multi-Dimensional Managed Trading
                              jeronymite
                              NinjaTrader Ecosystem Vendor - Mizpah Software

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X