Сложно тут что то прочесть)
Код лучше отображать так:
private void buttonStartRobot_Click(object sender, RoutedEventArgs e)
{
this.GuiAsync(() =>
{
if (_portfolio == null)
{
MessageBox.Show("Портфель не задан");
return;
}
/*
if (_security == null)
{
MessageBox.Show("Инструмент не задан");
return;
}*/
if (Securities.SelectedSecurity == null)
{
MessageBox.Show("Не выбран инструмент!");
return;
}
if (Muzrik == null)
{
MessageBox.Show("Терминал не задан");
return;
}
Muzrik.RegisterMarketDepth(Securities.SelectedSecurity);
//Создаем менеджер
_candleManager = new CandleManager(Muzrik);
_candleSeries = new CandleSeries(typeof(TickCandle), Securities.SelectedSecurity, 1);
_candleManager.Start(_candleSeries);
if (_strategy == null)
{
//создаем торговую стратегию
_strategy = new RobotStrategy(_candleManager, _candleSeries, _timeFrame, _slippage,
_alert_volume, _stop_long, _stop_short, _profit_long, _profit_short,
_ots_long, _ots_short, _hour_close, _minute_close)
{
Volume = _kol,
Security = Securities.SelectedSecurity,
//Security = _security,
Portfolio = _portfolio,
Trader = Muzrik
};
//Лог
_logManager.Sources.Add(_strategy);
//Создаем генератор отчетов (не доделано)
//ExcelStrategyReport report = new ExcelStrategyReport(_strategy, String.Format("report\\{0}_{1:00}_{2:00}.xls", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
//report.Generate();
if (_strategy.ProcessState == ProcessStates.Stopped)
{
_strategy.Start();
}
buttonStartRobot.IsEnabled = false;
buttonStopRobot.IsEnabled = true;
}
});
}
Я еще пересмотрю Ваш код, а пока советую Вам тщательно пройтись отладчиком по вашему приложению (F11 в Visual Studio).
Не уверен что поможет, но попробуйте сделать так:
if (_strategy == null)
{
//создаем торговую стратегию
_strategy = new RobotStrategy(_candleManager, _candleSeries, _timeFrame, _slippage,
_alert_volume, _stop_long, _stop_short, _profit_long, _profit_short,
_ots_long, _ots_short, _hour_close, _minute_close)
{
Volume = _kol,
Security = Securities.SelectedSecurity,
//Security = _security,
Portfolio = _portfolio,
Trader = Muzrik
};
Muzrik.RegisterMarketDepth(Securities.SelectedSecurity);
Зарегистрируйте стакан после создания стратегии.