If I try to debug using Visual Studio, the ninja process terminates and I am unable to debug.
Error: Unhandled Exception: The Object reference is not set to an instance of an object.
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
if (State == State.Realtime)
{
try
{
if (ChartControl != null)
{
if (account != null)
{
currAccountName = account.ToString();
prevAccount = account;
//NinjaTrader.Code.Output.Process(string.Format("{0} : OBU | CurrentAccount {1}", Time[0], currAccountName.ToString()), PrintTo.OutputTab1);
}
ChartControl.Dispatcher.InvokeAsync((Action)(() =>
{
//You have to put the stuff below within this ChartControl.Dispatcher.InvokeAsync((Action)(() =>, because you are trying to access something on a different thread.
accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
//NinjaTrader.Code.Output.Process(string.Format("{0} : OBU Async | CurrentAccount {1}", Time[0], currAccountName.ToString()), PrintTo.OutputTab1);
accountSelector.SelectionChanged += (o, args) =>
{
//NinjaTrader.Code.Output.Process(string.Format("{0} : OBU Async | SelectedAccount {1}", Time[0], accountSelector.SelectedAccount.ToString()), PrintTo.OutputTab1);
if (accountSelector.SelectedAccount != null && currAccountName != accountSelector.SelectedAccount.ToString())
{
prevAccount.ExecutionUpdate -= OnExecutionUpdate;
prevAccount.OrderUpdate -= OnOrderUpdate;
prevAccount.PositionUpdate -= OnPositionUpdate;
NinjaTrader.Code.Output.Process(string.Format("{0} : Unsubscribed {1}", Time[0], prevAccount.ToString()), PrintTo.OutputTab1);
account = accountSelector.SelectedAccount;
account.ExecutionUpdate += OnExecutionUpdate;
account.OrderUpdate += OnOrderUpdate;
account.PositionUpdate += OnPositionUpdate;NinjaTrader.Code.Output.Process(string.Format("{0} : Subscribed {1}", Time[0], account.ToString()), PrintTo.OutputTab1);
currAccountName = account.ToString();
}
};
}));
}
}
catch (Exception ex)
{
NinjaTrader.Code.Output.Process(string.Format("OAU | {0}", ex.ToString()), PrintTo.OutputTab1);
}
Draw.TextFixed(this, "Account", "Account Selected: " + account.ToString(), TextPosition.BottomRight);
}
}

Comment