/// <summary> /// Calculates the strategy. /// </summary> /// <param name="recalcIndicators">true - to recalculate all the indicators.</param> void Calculate(bool recalcIndicators) { bool isUPBVChanged = Data.Strategy.AdjustUsePreviousBarValue(); // Calculates the indicators by slots if it's necessary if (recalcIndicators) { foreach (IndicatorSlot indSlot in Data.Strategy.Slot) { string indicatorName = indSlot.IndicatorName; SlotTypes slotType = indSlot.SlotType; Indicator indicator = Indicator_Store.ConstructIndicator(indicatorName, slotType); indicator.IndParam = indSlot.IndParam; indicator.Calculate(slotType); indSlot.IndicatorName = indicator.IndicatorName; indSlot.IndParam = indicator.IndParam; indSlot.Component = indicator.Component; indSlot.SeparatedChart = indicator.SeparatedChart; indSlot.SpecValue = indicator.SpecialValues; indSlot.MinValue = indicator.SeparatedChartMinValue; indSlot.MaxValue = indicator.SeparatedChartMaxValue; indSlot.IsDefined = true; } } // Searches the indicators' components to determine the Data.FirstBar Data.FirstBar = Data.Strategy.SetFirstBar(); // Logging Data.Log("Calculate the strategy"); // Calculates the backtest Backtester.Calculate(); Backtester.CalculateAccountStats(); Data.IsResult = true; if (isUPBVChanged) { RebuildStrategyLayout(); } smallIndicatorChart.InitChart(); smallIndicatorChart.Invalidate(); smallBalanceChart.SetChartData(); smallBalanceChart.InitChart(); smallBalanceChart.Invalidate(); SetupJournal(); infpnlAccountStatistics.Update( Backtester.AccountStatsParam, Backtester.AccountStatsValue, Backtester.AccountStatsFlags, Language.T("Account Statistics")); return; }
private void CalculateStrategy() { Backtester.Calculate(); Backtester.CalculateAccountStats(); }
/// <summary> /// Calculates the selected indicator. /// </summary> private void CalculateIndicator(bool bCalculateStrategy) { if (!Data.IsData || !Data.IsResult || !_isPaint) { return; } SetOppositeSignalBehaviour(); SetClosingLogicConditions(); Indicator indicator = IndicatorStore.ConstructIndicator(_indicatorName, _slotType); // List parameters for (int i = 0; i < 5; i++) { indicator.IndParam.ListParam[i].Index = ListParam[i].SelectedIndex; indicator.IndParam.ListParam[i].Text = ListParam[i].Text; indicator.IndParam.ListParam[i].Enabled = ListParam[i].Enabled; } // Numeric parameters for (int i = 0; i < 6; i++) { indicator.IndParam.NumParam[i].Value = (double)NumParam[i].Value; indicator.IndParam.NumParam[i].Enabled = NumParam[i].Enabled; } // Check parameters for (int i = 0; i < 2; i++) { indicator.IndParam.CheckParam[i].Checked = CheckParam[i].Checked; indicator.IndParam.CheckParam[i].Enabled = CheckParam[i].Enabled; indicator.IndParam.CheckParam[i].Enabled = CheckParam[i].Text == "Use previous bar value" || CheckParam[i].Enabled; } if (!CalculateIndicator(_slotType, indicator)) { return; } if (bCalculateStrategy) { //Sets Data.Strategy Data.Strategy.Slot[_slot].IndicatorName = indicator.IndicatorName; Data.Strategy.Slot[_slot].IndParam = indicator.IndParam; Data.Strategy.Slot[_slot].Component = indicator.Component; Data.Strategy.Slot[_slot].SeparatedChart = indicator.SeparatedChart; Data.Strategy.Slot[_slot].SpecValue = indicator.SpecialValues; Data.Strategy.Slot[_slot].MinValue = indicator.SeparatedChartMinValue; Data.Strategy.Slot[_slot].MaxValue = indicator.SeparatedChartMaxValue; Data.Strategy.Slot[_slot].IsDefined = true; // Search the indicators' components to determine Data.FirstBar Data.FirstBar = Data.Strategy.SetFirstBar(); // Check "Use previous bar value" if (Data.Strategy.AdjustUsePreviousBarValue()) { for (int i = 0; i < 2; i++) { if (indicator.IndParam.CheckParam[i].Caption == "Use previous bar value") { AChbCheck[i].Checked = Data.Strategy.Slot[_slot].IndParam.CheckParam[i].Checked; } } } Backtester.Calculate(); Backtester.CalculateAccountStats(); } SetIndicatorNotification(indicator); Data.IsResult = true; }