thanks for your respond!
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
DateTime vs DateTimeOffset
Collapse
X
-
DateTime vs DateTimeOffset
Hey guys, i´ve recently read that as far as Time Zone is concerned, Microsoft recognized using DateTimeOffset instead of DateTime. How is this at NT8. is it there also better to use DateTimeOffset, or is NT alway calculating on custom Time Zone?
thanks for your respond!Tags: None
-
Hello sane1111,
Thanks for your post.
You could use DateTime in a NInjaScript strategy or indicator if you would like to get your machine's time. For example, see the sample code below.
Code:Print("Current machine time: " + DateTime.Now);
Code:Print("Bar time stamp: " + Time[0]);
See this publicly available link for more information about DateTime: https://docs.microsoft.com/en-us/dot...e?view=net-6.0
And, see the attached example script. The example script demonstrates using the above prints.
Let me know if I may assist further.Attached FilesBrandon H.NinjaTrader Customer Service
- Likes 1
-
Thanks Brandon for your reply,
I´m asking because of the following example.
Code:DateTime dt = DateTime.UtcNow; Print(dt.ToString("HH:mm")); string apiReturn = dt.ToString("o"); DateTime apiValue = DateTime.ParseExact(apiReturn, "o", null); Print(apiValue.ToString("HH:mm")); //
Last edited by sane1111; 08-10-2022, 09:03 AM.
Comment
-
Hello sane1111,
Thanks for your note.
This would fall under C# education and would go beyond the support we could provide. It would be up to you to decide whether to use DateTime or DateTimeOffset in your script.
Ultimately, DateTime is used when referencing the machine's time and Time[0] would be used to reference a bar's timestamp.
See this help guide page for information about creating time comparisons: https://ninjatrader.com/support/help...imeComparisons
You could create a time comparison condition in the Strategy Builder and click the 'View code' button to see the generated syntax. Note that DateTime is used for time comparisons.
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by RookieTrader, Today, 09:37 AM
|
3 responses
15 views
0 likes
|
Last Post Today, 10:32 AM | ||
Started by kulwinder73, Today, 10:31 AM
|
0 responses
5 views
0 likes
|
Last Post
by kulwinder73
Today, 10:31 AM
|
||
Started by terofs, Yesterday, 04:18 PM
|
1 response
23 views
0 likes
|
Last Post
by terofs
Today, 10:14 AM
|
||
Started by CommonWhale, Today, 09:55 AM
|
1 response
4 views
0 likes
|
Last Post Today, 10:11 AM | ||
Started by Gerik, Today, 09:40 AM
|
2 responses
7 views
0 likes
|
Last Post
by Gerik
Today, 10:04 AM
|
Comment