Currently I'm facing with the following issue:
I have created an indicator that has a couple of buttons that can open market orders and attach stoploss orders to them as well.
For that I had to subscribe to the OnOrderUpdate event.
It works fine (it opens the position with stoploss) if I use it for one chart. It even works if I open additional charts (for other instuments) and I attach this indicator to them.
But:
If I close and reopen Ninjatrader (or simply just disconnent and re-connect again) then all charts are loaded with the attached indicator.
And here comes the issue: Only on the last loaded chart works the indicator (and opens the order by clicking on the button) all other charts throws an exception by click on the button (to open an order):
"System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
at NinjaTrader.NinjaScript.Series`1.get_Item(Int32 barsAgo)
at NinjaTrader.NinjaScript.NinjaScriptBase.get_Item(I nt32 barsAgo)
at NinjaTrader.NinjaScript.Indicators.Profit.ABCOpenO rder.StopLossDistance(Boolean p_IsReverse, Boolean p_LongShort) in c:\Users\admin\Documents\NinjaTrader 8\bin\Custom\Indicators\Profit\ABCOpenOrder.cs:lin e 1407
at NinjaTrader.NinjaScript.Indicators.Profit.ABCOpenO rder.OnOrderUpdate(Object sender, OrderEventArgs e) in c:\Users\admin\Documents\NinjaTrader 8\bin\Custom\Indicators\Profit\ABCOpenOrder.cs:lin e 347
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at NinjaTrader.Cbi.Account.RaiseOrderUpdate(OrderEven tArgs e)
at NinjaTrader.Cbi.Account.CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, OrderEntry orderEntry, TimeInForce timeInForce, Int32 quantity, Double limitPrice, Double stopPrice, Int32 filled, Double averageFillPrice, OrderState initialOrderState, String initialOrderId, DateTime time, String oco, String name, DateTime gtd, String comment, DateTime statementDate, CustomOrder customOrder, Boolean raiseOrderUpdate, Int64 id)
at NinjaTrader.Cbi.Account.CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, OrderEntry orderEntry, TimeInForce timeInForce, Int32 quantity, Double limitPrice, Double stopPrice, String oco, String name, DateTime gtd, CustomOrder customOrder)
at NinjaTrader.NinjaScript.Indicators.Profit.ABCOpenO rder.<Button1Click>b__98_0(Object o) in c:\Users\admin\Documents\NinjaTrader 8\bin\Custom\Indicators\Profit\ABCOpenOrder.cs:lin e 571
"
If I switch the account on the account selector on the chart trader, then it works again and opens the orders as expected.
My assumption is that somehow the event subscription does not work correctly if the OnOrderUpdate event subscription has to be executed on multiple charts.
Can you please help me on this issue?
Thanks in advance,
Nintrader

Comment