thanks for your respond!
Announcement
Collapse
No announcement yet.
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.
You could use Time[0] to get the current bar time stamp value. For example, see the sample code below.Code:Print("Current machine time: " + DateTime.Now);
See this help guide page for more information about Time[ ]: https://ninjatrader.com/support/help...eries_time.htmCode: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 Files<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
- 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.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
650 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
577 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment