public static double CalculateRisk(double p_PriceLine, double p_StopLossLine, double p_Percentage, AdditionalData p_AdditionalData, CrossCurrencyData p_CrossCurrencyData) { if (p_AdditionalData == null) return 0; int l_risk = (int)(p_AdditionalData.AccountBalance * p_Percentage / 100); int l_volumeOnRisk = 0; if (p_AdditionalData.SymbolCurrency.EndsWith(p_AdditionalData.AccountCurrency)) { l_volumeOnRisk = (int)(l_risk / (Math.Abs(p_StopLossLine - p_PriceLine))); } else if (p_AdditionalData.SymbolCurrency.StartsWith(p_AdditionalData.AccountCurrency)) { l_volumeOnRisk = (int)(l_risk / (Math.Abs(p_StopLossLine - p_PriceLine)) * p_PriceLine); } else { if (p_CrossCurrencyData == null) { //throw new Exception("No cross currency data provided"); return 0; } if (p_CrossCurrencyData.CurrencyPair.StartsWith(p_AdditionalData.AccountCurrency)) { l_volumeOnRisk = (int)(l_risk * p_CrossCurrencyData.Ask / (Math.Abs(p_StopLossLine - p_PriceLine))); } else { l_volumeOnRisk = (int)(l_risk / p_CrossCurrencyData.Ask / (Math.Abs(p_StopLossLine - p_PriceLine))); } } l_volumeOnRisk = (int)(l_volumeOnRisk / 1000) * 1000; return l_volumeOnRisk; }
private AdditionalData GetAddData() { AdditionalData l_Result = new AdditionalData(); l_Result.AccountBalance = Account.Balance; l_Result.AccountCurrency = Account.Currency; l_Result.SymbolPipSize = Symbol.PipSize; l_Result.SymbolPointSize = Symbol.PointSize; l_Result.SymbolCurrency = Symbol.Code; l_Result.Ask = Symbol.Ask; l_Result.Bid = Symbol.Bid; return l_Result; }
public void SendAdditionalData(AdditionalData p_Data) { DashboardInstance.SendAdditionalData(p_Data); }
private void SetPlotModel() { if (oxyMainPlot.Model != null) oxyMainPlot.Model = null; PlotModel l_PlotModel = new PlotModel("Remote CTrader chart"); l_PlotModel.PlotAreaBorderColor = OxyColor.FromRgb(0, 0, 0); CandleStickSeries l_CandleSticks = new CandleStickSeries(); l_CandleSticks.DataFieldClose = "Close"; l_CandleSticks.DataFieldOpen = "Open"; l_CandleSticks.DataFieldHigh = "Max"; l_CandleSticks.DataFieldLow = "Min"; l_CandleSticks.DataFieldX = "Time"; l_CandleSticks.CandleWidth = 5; l_CandleSticks.Background = OxyColor.FromRgb(0, 0, 0); if (m_SelectedRobot > 0) { m_MarketData = m_PipeProxy.GetMarketDataByLength(m_SelectedRobot, 100); m_AdditionalData = m_PipeProxy.GetAdditionalData(m_SelectedRobot); } l_CandleSticks.ItemsSource = m_MarketData; l_PlotModel.Series.Add(l_CandleSticks); #region Bottom Axis setup DateTimeAxis l_BottomAxis = new DateTimeAxis(); l_BottomAxis.StringFormat = "yy-MM-dd hh:mm"; l_BottomAxis.IntervalType = DateTimeIntervalType.Auto; l_BottomAxis.FontSize = 8; l_PlotModel.Axes.Add(l_BottomAxis); l_BottomAxis.AxisChanged += l_BottomAxis_AxisChanged; #endregion #region Side Axis setup LinearAxis l_SideAxis = new LinearAxis(); l_PlotModel.Axes.Add(l_SideAxis); l_SideAxis.AxisChanged += l_SideAxis_AxisChanged; #endregion #region Initialize top line m_TopLine = new LineAnnotation(); m_TopLine.Color = OxyColor.FromRgb(125, 230, 125); m_TopLine.LineStyle = LineStyle.Solid; m_TopLine.StrokeThickness = 3; m_TopLine.Type = LineAnnotationType.Horizontal; m_TopLine.Selectable = true; m_TopLine.TextColor = m_TopLine.Color; m_TopLine.Y = m_MarketData.Last().Close; m_TopLine.Text = m_TopLine.Y.ToString("N4"); l_PlotModel.Annotations.Add(m_TopLine); #endregion #region Initialize bottom line m_BottomLine = new LineAnnotation(); m_BottomLine.Color = OxyColor.FromRgb(230, 125, 125); m_BottomLine.LineStyle = LineStyle.Solid; m_BottomLine.StrokeThickness = 3; m_BottomLine.Type = LineAnnotationType.Horizontal; m_BottomLine.Selectable = true; m_BottomLine.Y = m_MarketData.Last().Close; m_BottomLine.TextColor = m_BottomLine.Color; m_BottomLine.Text = m_BottomLine.Y.ToString("N4"); l_PlotModel.Annotations.Add(m_BottomLine); #endregion #region Initialize pending order line m_PendingLine = new LineAnnotation(); m_PendingLine.Color = OxyColor.FromRgb(125, 125, 230); m_PendingLine.LineStyle = LineStyle.Solid; m_PendingLine.StrokeThickness = 3; m_PendingLine.Type = LineAnnotationType.Horizontal; m_PendingLine.Selectable = true; m_PendingLine.Y = m_MarketData.Last().Close; m_PendingLine.TextColor = m_PendingLine.Color; m_PendingLine.Text = m_PendingLine.Y.ToString("N4"); if(chbPEnabled.IsEnabled) l_PlotModel.Annotations.Add(m_PendingLine); #endregion oxyMainPlot.Model = l_PlotModel; l_PlotModel.Updated += l_PlotModel_Updated; }
public void SendAdditionalData(AdditionalData p_Data) { m_AdditionalData = p_Data; }