Thanks a lot!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Instrument.Expiry for added instruments
Collapse
X
-
Hello and welcome to the forums.
It is not supported to dynamically Add() instruments within Initialize(). It is recommended to hard code the expiry dates for these instruments as using dynamic input can lead to unexpected errors since Initialize() can be called other times than when just starting the strategy/indicator.LanceNinjaTrader Customer Service
-
Thanks Lance. I know that, but my plan was to add all the futures in the Initialize section, then I would use the Instrument.expiry,in the OnBarUpdate, function to figure out which futures to trade. Sorry I wasn't clear about that.
Thanks koganam! I'll try that out.
Comment
-
Ah that's unfortunate. I guess I'll manually create an array with the expiry dates in the same order as I add the futures. That way array[3] would be the expiry date for Closes[3], for example. I just didn't wan't to have to do it manually, but that's fine.
I have two completely different questions too. How do I make my strategy work only at 3:45pm? And let's say I want to close a position and open a new one right afterwards, how do I make it wait until the closing order has passed?
Comment
-
You can do this with a time filterOriginally posted by jean9114 View PostI have two completely different questions too. How do I make my strategy work only at 3:45pm? And let's say I want to close a position and open a new one right afterwards, how do I make it wait until the closing order has passed?
Example
Code:if(ToTime(Time[0]) == ToTime(15, 45, 0)) { //do something }
The use of OnOrderUpdate/OnExecution should be helpful for the second part in checking order states
The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
Please let me know if I can be of further assistance.LanceNinjaTrader Customer Service
Comment
-
Thanks a lot! That'll definitely work.
One more question, how would I backtest a futures strategy? In the Initialize section, I added the futures for the next 2 years, but when backtesting, these won't change. Should I do a Monte Carlo simulation instead or add the old futures and run the backtest normally? Can it run the backtest even though the futures have actually expired already? Might be easier to just run the Monte Carlo simulation.
Comment
-
Hello,
You can backtest over previous contracts using the most current contract depending on your merge settings.
For example. If you wanted to backtest the past year of the ES, you could run the backtest on the ES 06-13 contract but make it merge in the previous contracts.
The different merge settings are defined in the last section here: http://www.ninjatrader.com/support/h...rical_data.htm
To change go to tools -> options -> data tab: http://www.ninjatrader.com/support/h...l?data_tab.htm
It's up to you whether or not you use the Monte Carlo Analysis.LanceNinjaTrader Customer Service
Comment
-
You can use DateTime subtractions to find this.
An example can be found here: http://msdn.microsoft.com/en-us/library/8ysw4sby.aspx
For all the DateTime methods: http://msdn.microsoft.com/en-us/libr....datetime.aspx
Let me know if I can be of further assistance.LanceNinjaTrader Customer Service
Comment
-
Lookup DateTime and TimeSpan. You use the TotalDays property of the TimeSpan value that you get from subtracting the DateTime values that represent the dates in which you are interested.Originally posted by jean9114 View PostHow can I find the number of day between lets say, the 1st of May and the 1st of June?
With the ToDay function, I get integers, which gives me a difference of 100 instead of 31.
Comment
-
Ok great! If i'm short 500 futures and want to go long 500 instead, do I have to closeshort 500 and enterlong 500 or can I enterlong 1000 instead?
I know that for equity you need to close first, but I'm quite new to futures. The difference between the two is that you can't sell your futures contracts, that's why I'm wondering if I can simply go long 1000.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by sjsj2732, Yesterday, 04:31 AM
|
0 responses
32 views
0 likes
|
Last Post
by sjsj2732
Yesterday, 04:31 AM
|
||
|
Started by NullPointStrategies, 03-13-2026, 05:17 AM
|
0 responses
286 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
283 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
133 views
1 like
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
91 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
Comment