I have a question regarding Instrument Lists in Code. My goal is to catch a pre-configured instrument list in Ninjatrader 8, get each instrument from this list, add it as a DataSeries Object in State.Configure and treat exactly this instrument with buy/sell orders in OnBarUpdate().
The problem is that during back testing, only the instrument selected under Instrument in the strategy analyzer is treated with buy/sell orders. My custom instrument coming in as secondary DataSeries Object is always ignored. I'm expecting that i have to fire the order with the symbol coming from the instrument list but how can i configure a custom symbol for an order entry?
... if (State == State.Configure) { Collection<NinjaTrader.Cbi.InstrumentList> instrumentListAll = NinjaTrader.Cbi.InstrumentList.All; foreach (InstrumentList instrumentList in instrumentListAll) { if (instrumentList.Name == "My List") // List contains AMZN MSFT GOOG NFLX { foreach (Instrument instrument in instrumentList.Instruments) { AddDataSeries(instrument.FullName, Data.BarsPeriodType.Day, 1); } } } } } protected override void OnBarUpdate() { // Primary instrument is AAPL if (CurrentBar < BarsRequiredToTrade) return; if (CrossAbove(SMA(BarsArray[1], 20), SMA(BarsArray[1], 50), 1)) EnterLong(); // Trades are only executed for AAPL else if (CrossBelow(SMA(BarsArray[1], 20), SMA(BarsArray[1], 50), 1)) EnterShort(); // Trades are only executed for AAPL }
Comment