/// <summary> /// Displays simulation result /// </summary> /// <param name="result"></param> private void DisplaySimulationResult(SimulationResult result) { foreach (var point in chartCtrl.Series[Constants.PriceSerieName].Points) { MarketAction action = result.Actions.Where(x => x.Date == (point.Tag as OHLC).Date).FirstOrDefault(); if (action != null) { point.MarkerImage = action.ActionType == ActionType.Bid ? "MaxMarker.bmp" : "MinMarker.bmp"; point.MarkerImageTransparentColor = Color.White; } else if (!string.IsNullOrEmpty(point.MarkerImage)) { point.MarkerImage = string.Empty; } } }
/// <summary> /// Starts backtesting /// </summary> private void RunBackTests() { if (_candles == null || _candles.Count == 0) { ErrorHelper.DisplayErrorMessage("Not enough data to run the simulation"); return; } int i = 0; var strategy = TradingStrategy; foreach (var candle in _candles) { var temp = _candles.Take(i++); strategy.OnTick(temp.ToList()); } var pair = chartSelector.SelectedPair; var res = strategy.GetResult(); var nbUnitsItem2 = res.BalanceItem1 * _candles.Last().Close; lblResult.Text = string.Format("{0:0.00} {3} - {1:0.00} {4} - Total: {2:0.00} {5}", res.BalanceItem2, res.BalanceItem1, res.BalanceItem2 + nbUnitsItem2, pair.Item2, pair.Item1, pair.Item2); var actions = strategy.Actions; var simRes = new SimulationResult { Actions = actions }; chartCtrl.NotifySimulationResult(simRes); }
/// <summary> /// Notifies the control that a simulation finished /// </summary> /// <param name="result"></param> public void NotifySimulationResult(SimulationResult result) { DisplaySimulationResult(result); }