private void RecalculateSignals(IDictionary <SignalBase, Selection> signals) { foreach (var item in signals) { if (item.Key.IsBusy()) { continue; } try { var signal = item.Key; var queuedTicks = signal.StartMethod == StartMethod.NewTick ? GetSignalTicksQueue(signal.Name, signal.Owner) : null; signal.Start(item.Value, queuedTicks); if (signal.State == SignalState.Stopped) { var exitAlerts = signal.GetActualAlerts(); if (exitAlerts != null && exitAlerts.Count > 0) { _connector.SciriptingAlert(exitAlerts, ScriptingType.Signal, signal.Name, signal.Owner); } CodeExit?.Invoke(ScriptingType.Signal, signal.Name, signal.Owner); return; } var alerts = signal.GetActualAlerts(); if (alerts != null && alerts.Count > 0) { _connector.SciriptingAlert(alerts, ScriptingType.Signal, signal.Name, signal.Owner); } } catch (AppDomainUnloadedException) { } catch (Exception e) { Logger.Error(e.Message, e); } } }
private void UpdateBacktestStatus(object state) { var finished = new List <Tuple <string, string> >(); lock (_userWorkingSignals) { foreach (var s in _userWorkingSignals) { //check backtest progress var key = s.Owner + "|" + s.Name; if (_startedBacktestSignals.Contains(key)) { var gotNewResults = false; var progress = 0F; if (!_sentBacktestReports.ContainsKey(key) || //no reports have been sent yet _sentBacktestReports[key] > s.BacktestResults.Count) //or backtest was restarted { gotNewResults = true; _sentBacktestReports[key] = s.BacktestResults.Count; progress = s.BacktestProgress; _connector.BacktestReport(s.BacktestResults.ToList(), s.BacktestProgress, s.Owner); } else if (_sentBacktestReports[key] < s.BacktestResults.Count) //got new reports to send { gotNewResults = true; var idx = _sentBacktestReports[key]; var count = s.BacktestResults.Count - idx; _sentBacktestReports[key] = s.BacktestResults.Count; progress = s.BacktestProgress; _connector.BacktestReport(s.BacktestResults.GetRange(idx, count), s.BacktestProgress, s.Owner); } if (gotNewResults && s.BacktestResults.Any()) { SaveBacktestResults(s.Owner, s.Name, s.BacktestResults); } if (progress >= 100F) { _startedBacktestSignals.Remove(key); finished.Add(new Tuple <string, string>(s.Name, s.Owner)); s.SetSignalState(SignalState.Stopped); CodeExit?.Invoke(ScriptingType.Signal, s.Name, s.Owner); } } //check for alerts var alerts = s.GetActualAlerts(); if (alerts != null && alerts.Count > 0) { _connector.SciriptingAlert(alerts, ScriptingType.Signal, s.Name, s.Owner); } } } foreach (var item in finished) { RemoveWorkingSignal(item.Item1, item.Item2); } _tmrSignalsBacktest.Change(1000, Timeout.Infinite); }