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 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:
Code: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:
Code:NinjaTrader.Cbi.InstrumentList list = NinjaTrader.Cbi.InstrumentList.GetObject("instrument list name");
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();
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
-
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 Padan, Today, 02:02 AM
|
3 responses
11 views
0 likes
|
Last Post Today, 08:54 AM | ||
Started by Tim-c, Today, 08:36 AM
|
1 response
3 views
0 likes
|
Last Post Today, 08:45 AM | ||
Started by goodknight777, Today, 08:43 AM
|
0 responses
2 views
0 likes
|
Last Post Today, 08:43 AM | ||
Started by martini, Yesterday, 04:45 PM
|
3 responses
28 views
0 likes
|
Last Post Today, 08:38 AM | ||
Started by Mestor, Today, 03:15 AM
|
2 responses
10 views
0 likes
|
Last Post
by Mestor
Today, 08:36 AM
|
Comment