void signals_ItemAdded(object sender, SignalEventArgs e) { ComboBoxItem item = new ComboBoxItem() { Background = Brushes.DarkGray, Foreground = e.Signal.Pen.Brush, Content = e.Signal.Name, Tag = e.Signal }; e.Signal.Tag = item; // Add item to the combo box. selectedSignal.Items.Add(item); if (!Signals.Contains(SelectedSignal)) { if (Signals.Any()) { SelectedSignal = Signals.First(); } else if (SelectedSignal != null) { SelectedSignal = null; } } }
private void HandleWriteToEboFromIotEdge(string decodedString) { Logger.LogTrace(LogCategory.Processor, this.Name, $"Starting to write values sent from "); try { if (Signals == null || !Signals.Any()) { Logger.LogInfo(LogCategory.Processor, this.Name, $"There are no Signals in the in-memory cache. Please check that the Setup Processor has been run."); return; } var iotEdgeMessage = JsonConvert.DeserializeObject <IotEdgeMessage>(decodedString); if (iotEdgeMessage == null || !iotEdgeMessage.Actuations.Any()) { return; } var toSet = GetListOfValuesToSetInEbo(iotEdgeMessage); SetValuesInEbo(toSet, iotEdgeMessage); SendConfirmationResponseToIotEdge(iotEdgeMessage); } catch (Exception ex) { Logger.LogError(LogCategory.Processor, this.Name, ex.ToJSON()); } }
protected override IEnumerable <Prompt> Execute_Subclass() { if (Signals == null || !Signals.Any()) { GetSignalNullReason(); return(Prompts); } try { StartMqttClient().Wait(); } catch (Exception ex) { Logger.LogError(LogCategory.Processor, this.Name, $"Starting MQTT Client failed"); Prompts.Add(ex.ToPrompt()); return(Prompts); } _tempSignals = Signals.ToList(); // Read existing subscriptions if (!ReadExistingSubscriptions(_tempSignals).Result) { Prompts.Add(new Prompt { Message = $"Did not successfully read all existing subscriptions." }); } // Subscribe and read new subscriptions if (!SubscribeAndReadNew(_tempSignals).Result) { Prompts.Add(new Prompt { Message = $"Did not successfully read all new subscriptions." }); } Logger.LogTrace(LogCategory.Processor, this.Name, "Waiting for all messages be be published..."); while (ManagedMqttClient.PendingApplicationMessagesCount > 0) { Logger.LogTrace(LogCategory.Processor, this.Name, $"{ManagedMqttClient.PendingApplicationMessagesCount} messages left waiting to be published.."); if (this.IsCancellationRequested) { return(new List <Prompt>()); } Task.Delay(1000).Wait(); } Logger.LogTrace(LogCategory.Processor, this.Name, "Stopping Managed MQTT Client.."); ManagedMqttClient.StopAsync().Wait(); while (ManagedMqttClient.IsStarted) { Logger.LogTrace(LogCategory.Processor, this.Name, "Still waiting for MQTT Client to Stop..."); Task.Delay(1000).Wait(); } // Update the cache with new values.. Signals = _tempSignals; return(Prompts); }
void signals_ItemRemoved(object sender, SignalEventArgs e) { selectedSignal.Items.Remove(e.Signal.Tag); if (!Signals.Contains(SelectedSignal)) { if (Signals.Any()) { SelectedSignal = Signals.First(); } else if (SelectedSignal != null) { SelectedSignal = null; } } }
public void DisplayText(int index, string title) { if (_newSignalSettings == null) { throw new NullReferenceException("The signal container NewSignalSettings object is null"); } else if (_signalStatsSettings == null) { throw new NullReferenceException("The signal container SignalStatsSettings object is null"); } if (!Signals.Any()) { return; } var profitableSignals = Signals.Where(iSignal => IsProfitable(iSignal, index)); var losingSignals = Signals.Where(iSignal => !profitableSignals.Contains(iSignal)); var stringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(title)) { stringBuilder.AppendLine(title); stringBuilder.AppendLine(); } // Strong signals statistics var strongSignalsAccuracy = profitableSignals.Count() / (double)Signals.Count * 100; var strongProfitableSignalsMedianRiskRewardRatio = profitableSignals.Select(iSignal => iSignal.RewardRiskRatio).Median(); var strongLosingSignalsMedianRiskRewardRatio = losingSignals.Select(iSignal => iSignal.RewardRiskRatio).Median(); var strongProfitableSignalsMedianLossInPips = _symbol.ToPips(profitableSignals.Select(iSignal => iSignal.TradeType == TradeType.Buy ? iSignal.MaxDownMove : iSignal.MaxUpMove).Median()); var strongProfitableSignalsMedianGainInPips = _symbol.ToPips(profitableSignals.Select(iSignal => iSignal.TradeType == TradeType.Buy ? iSignal.MaxUpMove : iSignal.MaxDownMove).Median()); var strongLosingSignalsMedianLossInPips = _symbol.ToPips(losingSignals.Select(iSignal => iSignal.TradeType == TradeType.Buy ? iSignal.MaxDownMove : iSignal.MaxUpMove).Median()); var strongLosingSignalsMedianGainInPips = _symbol.ToPips(losingSignals.Select(iSignal => iSignal.TradeType == TradeType.Buy ? iSignal.MaxUpMove : iSignal.MaxDownMove).Median()); var strongAllSignalsMedianLossInPips = _symbol.ToPips(Signals.Select(iSignal => iSignal.TradeType == TradeType.Buy ? iSignal.MaxDownMove : iSignal.MaxUpMove).Median()); var strongAllSignalsMedianGainInPips = _symbol.ToPips(Signals.Select(iSignal => iSignal.TradeType == TradeType.Buy ? iSignal.MaxUpMove : iSignal.MaxDownMove).Median()); var profitableSignalsTotalGainInPips = _symbol.ToPips(profitableSignals.Select(iSignal => CalculateGain(iSignal, index)).Sum()); var losingSignalsGainInPips = _symbol.ToPips(losingSignals.Select(iSignal => CalculateLoss(iSignal, index)).Sum()); var proftiableSignalsMedianHoldingTimeInMinutes = profitableSignals.Select(iSignal => iSignal.HoldingTime.TotalMinutes).Median(); var losingSignalsMedianHoldingTimeInMinutes = losingSignals.Select(iSignal => iSignal.HoldingTime.TotalMinutes).Median(); var allSignalsMedianHoldingTimeInMinutes = Signals.Select(iSignal => iSignal.HoldingTime.TotalMinutes).Median(); var profitableSignalsMedianHoldingTime = TimeSpan.FromMinutes(double.IsNaN(proftiableSignalsMedianHoldingTimeInMinutes) ? 0 : proftiableSignalsMedianHoldingTimeInMinutes); var losingSignalsMedianHoldingTime = TimeSpan.FromMinutes(double.IsNaN(losingSignalsMedianHoldingTimeInMinutes) ? 0 : losingSignalsMedianHoldingTimeInMinutes); var allSignalsMedianHoldingTime = TimeSpan.FromMinutes(double.IsNaN(allSignalsMedianHoldingTimeInMinutes) ? 0 : allSignalsMedianHoldingTimeInMinutes); stringBuilder.AppendLine(string.Format("Signals #: {0}", Signals.Count)); stringBuilder.AppendLine(string.Format("Signals Accuracy: {0}%", Math.Round(strongSignalsAccuracy, 2))); stringBuilder.AppendLine(string.Format("Profitable Signals Median Reward:Risk: {0}", Math.Round(strongProfitableSignalsMedianRiskRewardRatio, 2))); stringBuilder.AppendLine(string.Format("Losing Signals Median Reward:Risk: {0}", Math.Round(strongLosingSignalsMedianRiskRewardRatio, 2))); stringBuilder.AppendLine(string.Format("Profitable Signals Median Loss (Pips): {0}", Math.Round(strongProfitableSignalsMedianLossInPips, 2))); stringBuilder.AppendLine(string.Format("Profitable Signals Median Gain (Pips): {0}", Math.Round(strongProfitableSignalsMedianGainInPips, 2))); stringBuilder.AppendLine(string.Format("Losing Signals Median Loss (Pips): {0}", Math.Round(strongLosingSignalsMedianLossInPips, 2))); stringBuilder.AppendLine(string.Format("Losing Signals Median Gain (Pips): {0}", Math.Round(strongLosingSignalsMedianGainInPips, 2))); stringBuilder.AppendLine(string.Format("All Signals Median Loss (Pips): {0}", Math.Round(strongAllSignalsMedianLossInPips, 2))); stringBuilder.AppendLine(string.Format("All Signals Median Gain (Pips): {0}", Math.Round(strongAllSignalsMedianGainInPips, 2))); stringBuilder.AppendLine(string.Format("Signals Total Gain (Pips): {0}", Math.Round(profitableSignalsTotalGainInPips - losingSignalsGainInPips, 2))); stringBuilder.AppendLine(string.Format("Profitable Signals Median Holding Time: {0}", profitableSignalsMedianHoldingTime)); stringBuilder.AppendLine(string.Format("Losing Signals Median Holding Time: {0}", losingSignalsMedianHoldingTime)); stringBuilder.AppendLine(string.Format("All Signals Median Holding Time: {0}", allSignalsMedianHoldingTime)); stringBuilder.AppendLine(); var text = stringBuilder.ToString(); var objectName = string.Format("Stats_{0}", _signalStatsSettings.ChartObjectNamesSuffix); _signalStatsSettings.Chart.DrawStaticText(objectName, text, _signalStatsSettings.StatsVerticalAlignment, _signalStatsSettings.StatsHorizontalAlignment, _signalStatsSettings.StatsColor); }