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

Inputting dates and times

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

    Inputting dates and times

    How do I refer to a specific date and time?

    For example if I want to tell ninjatrader: do X at 103800 on 01/27/2022


    #2
    Hello WalterSkinner,

    Thanks for your post.

    You can get the timestamp of the bar in OnBarUpdate with Time[0] and you can create conditions to check properties of this DateTime object like Time[0].Date and Time[0].TimeOfDay.

    DateTime objects (publicly available resource) - https://docs.microsoft.com/en-us/dot...tframework-4.8

    We also offer some more friendly functions like ToTime() and ToDay() to convert times into integers that may be easier to work with in your script.

    ToTime() - https://ninjatrader.com/support/help...tml?totime.htm

    ToDay() - https://ninjatrader.com/support/help...html?today.htm

    Additionally, you could follow the Condition example in the Help Guide for how to create a time comparison in the Strategy Builder, and use View Code to se the resulting syntax.



    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Sorry if I worded my question wrong let me try another way:

      I would say:
      Today is 01/28/2022 at 12:05 PM

      C#/ninja would say:
      Today is __________ at 120500

      Sorry for having to ask such a basic question this way, I googled and saw so many conflicting answers to this question - which is why I wanted to ask here - I figured it would be infinitely more straight forward if someone could just fill in this one blank.

      Comment


        #4
        Hello WalterSkinner,

        To clarify, are you trying to display a date as "01/28/2022" or are you trying to set up conditions to trigger events based on the time?

        Displaying a date as 01/28/2022, so NinjaTrader would print Today is 01/28/2022 would involve manipulating Time[0]. Time[0] is a DateTime Object, and DateTime.ToShortDateString() could be used.

        For example:

        Print("Today is " + Time[0].ToShortDateString() + " at " + Time[0].TimeOfDay);

        Would give you exactly:

        Today is 1/28/2022 at 20:34:36

        If you instead want to make conditions that trigger when Time[0] is a certain date/time, I think the Help Guide example for creating time comparisons should be the first thing to look into. Linked here. That can show you how to make a condition checking the specific time of a bar. Similarly, you can create a condition that compares Date Series to a specific Date value. All conditions in the Strategy Builder could be tested in the Strategy Builder and then you can use the View Code button to check what the syntax looks like.

        If you need additional help with either, please show me what you are setting up (either screenshots in the Strategy Builder, or example snippets) and let me know what you expect to see and what you see instead.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        4 views
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        6 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        96 views
        1 like
        Last Post caryc123  
        Working...
        X