Reason being, the computer time may be 9:30 AM but the time stamp on the 1 hour candle would be 10:00 AM on the chart.
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
Time [] & ToTime()
Collapse
X
-
Hello jg123,
When using Time[0] this is simply referring to the datetime object stored in the bar it is currently accessing. So to answer your question, Time[] is looking at the bar time and not your computer time.
ToTime and also ToDay convert the datetime object into a integer value to make comparing times or dates easy.
If you are looking to get the system time you do have access to the C# datetime methods.
Here is a MSDN page about Datetime in C#
Please let me know if I may be of additional assisstance.JesseNinjaTrader Customer Service
-
Great thank you
This does lead me to 2 questions.
In my code I use both Time & ToTime.
First:
In my user defined Parameters, I have a start time designed to be the beginning of a range. The Parameters code that I use is here:
Code:[GridCategory("Parameters")] [Gui.Design.DisplayName("1 Start Range")] public DateTime StartRange { get { return startRange; } set { startRange = value; } }
Code:private DateTime startRange = DateTime.Today.AddHours(2); // Hour that the range will start
2nd Question:
This is a debugging question.
I calculate an overnight range and then, at or after 9:00 AM Germany time, if the price breaks out of that range, I enter the market. Today, it did not enter the market at the correct time (It should have been at 9:08 AM). It entered the market on a break of the 10:00 candle when the 15:00 candle broke it.
Here is the code that is used to in order to enter on the breakout.
Code:if (LongEntryOCO == null && ShortEntryOCO == null && ToTime(Time[0]) >= ToTime(endRangeHr, endRangeMin, 00) && ToTime(Time[0]) < ToTime(removeOrderHr, removeOrderMin,00) && High[0] >= LongEntryPrice && restrictTrade == false) { LongEntryOCO = EnterLong(positionSize, "BreakoutLongOCO"); }
Code:private int endRangeHr = 10; // Hour that the range will end private int endRangeMin = 00; // Minute that the range will end private int removeOrderHr = 19; // Hour that unfilled entry orders will be removed private int removeOrderMin = 00; // Minute that that unfilled entry orders will be removed
for endRangeHour, I have it set to 10. The reason is because I am trading this on hourly charts and I want it to trigger at 9:00 AM or later and the time Stamp for a tick at 9:00 AM on an hourly chart is 10:00 AM. So it seems to me that this should have triggered earlier than it did.
I am attaching a screenshot of the chart also.
Comment
-
Hello,
For your first question, I believe that this is caused by the variable being set where you are declaring it; I don't think the script can get a date before the script is initialized, so I just added
Code:protected override void Initialize() { startRange = DateTime.Today.AddHours(2); }
For your second question I would like to get a few more details on how the strategy is run before I try to answer you.
From what you described this is how I interpreted it. -> You are running a strategy that checks if the current bars time is after 9 and before 10, if so and the price breaks, then submit an order, am I correct in thinking this is the logic you are going for?.
I would like to ask, are you running this on CalculateOnBarClose = false ?
If you have calculate on bar close set to true and you are using an hourly chart I would expect it to not place trades in between 9 and 10 because it is only processing as each bar closes so if the condition permitted as the 9 bar closed and moved to the 10 bar, it would place the order.
Another way you could possibly check what is happening is after trading is done today, if you have the market replay data available either by recording or downloading, to playback the day up until the point where it makes the error trade.
This would probably be the best way to check this as you can pause, rewind and retry with Print() statements or whatever else you may need to add in order to debug the logic.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Thanks for your reply Jesse.
will look into the addition that you suggested for the Initialize method.
For further clarification on Question #2.
I am looking for a breakout that happens between 9:00 AM and 18:00. If an order is not triggered and filled within that time, then it will call the CancelOrder() method.
CalculateOnBarclose is set to False.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bmartz, Today, 09:30 AM
|
2 responses
11 views
0 likes
|
Last Post
by bltdavid
Today, 11:24 AM
|
||
Started by f.saeidi, Today, 11:02 AM
|
1 response
3 views
0 likes
|
Last Post Today, 11:08 AM | ||
Started by geotrades1, Today, 10:02 AM
|
4 responses
12 views
0 likes
|
Last Post
by geotrades1
Today, 11:08 AM
|
||
Started by rajendrasubedi2023, Today, 09:50 AM
|
3 responses
16 views
0 likes
|
Last Post Today, 10:57 AM | ||
Started by lorem, Today, 09:18 AM
|
2 responses
11 views
0 likes
|
Last Post Today, 10:55 AM |
Comment