Exception:
Unhandled exception: Exception has been thrown by the target of an invocation.
Code:
protected override void OnStateChange()
{
ChartControl.Dispatcher.InvokeAsync(() =>
{
if (State == State.Historical)
GetMainControls();
});
}
private void GetMainControls()
{
chartWindow = Window.GetWindow(ChartControl.Parent) as Gui.Chart.Chart;
chartTraderGrid = (chartWindow.FindFirst("ChartWindowChartTraderCont rol") as Gui.Chart.ChartTrader).Content as System.Windows.Controls.Grid;
accountSelector = chartWindow.FindFirst("ChartTraderControlAccountSe lector") as AccountSelector;
qudQuantity = chartWindow.FindFirst("ChartTraderControlQuantityS elector") as QuantityUpDown;
atmStrategySelector = LogicalTreeHelper.FindLogicalNode(chartWindow, "cbxStrategySelector") as NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrateg ySelector;
if (accountSelector!=null)
{
selectedAccount = accountSelector.SelectedAccount;
accountSelector.SelectionChanged += (s, e) => selectedAccount = accountSelector.SelectedAccount;
}
btnClosePosition = new Button()
{
Content = "Close",
Background = Brushes.Orange,
Foreground = Brushes.White,
};
btnClosePosition.Click += btnClosePosition_Click;
}
protected void btnClosePosition_Click(object sender, RoutedEventArgs e)
{
if (selectedAccount==null)
return;
try{
TriggerCustomEvent(ClosePosition, new[]{Instrument});
}catch(Exception ex){Log(ex.ToString(),LogLevel.Error);}
}
private void ClosePosition(object instruments)
{
Instrument[] ins = instruments as Instrument[];
selectedAccount.Flatten(ins);
}

Comment