Thanks a lot!
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
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
-
Originally 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
-
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 MSerag, Yesterday, 11:52 PM
|
3 responses
22 views
0 likes
|
Last Post Today, 08:52 AM | ||
Started by dcriador, Yesterday, 01:43 AM
|
6 responses
27 views
0 likes
|
Last Post Today, 08:51 AM | ||
Started by James650, Today, 08:25 AM
|
1 response
2 views
0 likes
|
Last Post Today, 08:35 AM | ||
Started by Rogers101, 05-05-2024, 11:30 AM
|
14 responses
40 views
0 likes
|
Last Post Today, 08:32 AM | ||
Started by ETFVoyageur, 04-30-2024, 06:05 PM
|
11 responses
80 views
0 likes
|
Last Post Today, 08:21 AM |
Comment