For example if I want to tell ninjatrader: do X at 103800 on 01/27/2022
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!
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
NinjaTrader
Inputting dates and times
Collapse
X
-
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
Tags: None
-
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
-
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
-
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 Lele2k24, Yesterday, 11:24 AM
|
8 responses
27 views
0 likes
|
Last Post
by Lele2k24
Today, 11:00 AM
|
||
Started by Padan, Today, 02:02 AM
|
4 responses
15 views
0 likes
|
Last Post
by Padan
Today, 10:46 AM
|
||
Started by kramnor2001, Yesterday, 02:30 PM
|
4 responses
24 views
0 likes
|
Last Post
by bltdavid
Today, 10:44 AM
|
||
Started by eduardodipp7, Today, 10:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by eduardodipp7
Today, 10:29 AM
|
||
Started by AgriTrdr, 07-16-2023, 12:54 PM
|
39 responses
272 views
0 likes
|
Last Post
by f.saeidi
Today, 10:23 AM
|
Comment