Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Instrument Manager
Collapse
X
-
Instrument Manager
Hi. I'm developing an indicator that uses the ES to determine overall market sentiment. I want to "ADD" the most current ES contract in my instrument manager list. Is there a way to access the instrument manager list? If so,how would I go about accessing the most recent ES contract? thanksTags: None
-
Hello FCatan,
Thank you for your inquiry.
The easiest way to add the ES contract to your indicator would be the syntax below:
Please take a look at the NinjaTrader help guide at this link for more information on the Add() method call: http://ninjatrader.com/support/helpGuides/nt7/?add3.htmCode:Add("ES (contract month)", PeriodType periodType, int period);
I do not know if a supported way of accessing an instrument list from NinjaScript. However, there is this method that is unsupported:
Below is a sample that will pull only the ES instruments from the instrument list you have specified and sort them in descending order.Code:NinjaTrader.Cbi.InstrumentList list = NinjaTrader.Cbi.InstrumentList.GetObject("instrument list name");
You would be able to pull the first index value of that esInstruments list and use it in your Add() method for the most current contract month:Code:List<string> esInstruments = new List<string>(); foreach (Instrument instrument in list.Instruments) { if (instrument.FullName.Contains("ES")) { esInstruments.Add(instrument.FullName); } } esInstruments.Sort(); esInstruments.Reverse();
Please note that the method I have provided will only work correctly if your ES instruments in the instrument list have the same contract year.Code:Add(esInstruments[0], PeriodType periodType, int period);
Zachary G.NinjaTrader Customer Service
-
below is the code I added to the Initialize section
// this section gets the most recent ES contract from the Instrument List
NinjaTrader.Cbi.InstrumentList list = NinjaTrader.Cbi.InstrumentList.GetObject("Instrume nts");
List<string> esInstruments = new List<string>();
foreach (Instrument instrument in list.Instruments)
{
if (instrument.FullName.Contains("ES ")) esInstruments.Add(instrument.FullName);
}
if (esInstruments != null)
{
esInstruments.Sort();
esInstruments.Reverse();
ES_contract = esInstruments[0];
}
else ES_contract = "";
// ************************************************** ********************
I get an error message "Failed to call method 'Initialize' for indicator 'TestInd': Object reference not set to an instance of an object."
I'm relatively new to C# so I'm sure I missed something.
thanks Vince
Comment
-
Hello FCatan,
That would be the name of your instrument list.
To see the name of the instrument list you want to pull from, you'll want to click on Tools -> Instrument Manager.
At the top left of the window, you'll see a section titled Instrument lists. Below will be the name of your instrument list.
So, if you'd like to use the Default instrument list, you would change "instrument list name" to "Default".Zachary G.NinjaTrader Customer Service
Comment
-
Hello Vince,Originally posted by FCatan View Post
I get an error message "Failed to call method 'Initialize' for indicator 'TestInd': Object reference not set to an instance of an object."
I'm relatively new to C# so I'm sure I missed something.
thanks Vince
This would be due to an improper instrument list name.
Has your issue been rectified by my previous post?Zachary G.NinjaTrader Customer Service
Comment
-
Hi ... Zacahry assisted me awhile back on a section of code that selects the most current instrument form the Dfault instrument list. The code is as follows:
NinjaTrader.Cbi.InstrumentList list = NinjaTrader.Cbi.InstrumentList.GetObject("Default" );
bool contractFound = false;
List<string> selectedInstruments = new List<string>();
foreach (Instrument myInstrument in list.Instruments)
{
if (myInstrument.FullName.Contains(defaultInst)) {selectedInstruments.Add(myInstrument.FullName); contractFound = true;}
}
if (contractFound)
{
selectedInstruments.Sort();
selectedInstruments.Reverse();
selected_contract = selectedInstruments[0];
}
else
{
selected_contract = "";
runProgram = false;
}
This works find except when I have a contract that is for a prior year but a greater month. For example if I have the current ES contract "ES 09-15" as well as an older contract, "ES 12-14", the selectedInstruments.Sort(); selectedInstruments.Reverse(); lines will sort the "ES 12-14" first. But I want "ES 09-15". The issue being how the order of the text puts the month before the year. How do I sort first but year, then by month while keeping the text format in tact?
thanks!
Comment
-
Hello FCatan,
I have mentioned in my initial post that "the method I have provided will only work correctly if your ES instruments in the instrument list have the same contract year." This is due to the fact that "12" is larger than "09" that it is sorting ES 12-14 before ES 09-15.
There is nothing built into NinjaScript that would provide this functionality for you. I would suggest looking into C# custom list sort methods to do this for you.Zachary G.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
599 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
345 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment