示例#1
0
        /// <summary>
        ///     Exports the bar summary
        /// </summary>
        public void ExportBarSummary()
        {
            string stage = String.Empty;

            if (Data.IsProgramBeta)
            {
                stage = " " + Language.T("Beta");
            }
            else if (Data.IsProgramReleaseCandidate)
            {
                stage = " " + "RC";
            }

            string ff = Data.Ff; // Format modifier to print float numbers
            string df = Data.Df; // Format modifier to print date
            var    sb = new StringBuilder();

            sb.Append("Forex Strategy Builder v" + Data.ProgramVersion + stage + Environment.NewLine);
            sb.Append("Strategy name: " + Data.Strategy.StrategyName + Environment.NewLine);
            sb.Append("Exported on " + DateTime.Now + Environment.NewLine);
            sb.Append(Data.Symbol + " " + Data.PeriodString + "; Values in points" + Environment.NewLine);

            sb.Append("Bar Numb\t");
            sb.Append("Date\t");
            sb.Append("Hour\t");
            sb.Append("Open\t");
            sb.Append("High\t");
            sb.Append("Low\t");
            sb.Append("Close\t");
            sb.Append("Volume\t");
            sb.Append("Direction\t");
            sb.Append("Lots\t");
            sb.Append("Transaction\t");
            sb.Append("Price\t");
            sb.Append("Profit Loss\t");
            sb.Append("Floating P/L\t");
            sb.Append("Spread\t");
            sb.Append("Rollover\t");
            sb.Append("Balance\t");
            sb.Append("Equity\t");
            sb.Append("Interpolation" + Environment.NewLine);

            for (int bar = 0; bar < Data.Bars; bar++)
            {
                sb.Append((bar + 1) + "\t");
                sb.Append(Data.Time[bar].ToString(df) + "\t");
                sb.Append(Data.Time[bar].ToString("HH:mm") + "\t");
                sb.Append(Data.Open[bar].ToString(ff) + "\t");
                sb.Append(Data.High[bar].ToString(ff) + "\t");
                sb.Append(Data.Low[bar].ToString(ff) + "\t");
                sb.Append(Data.Close[bar].ToString(ff) + "\t");
                sb.Append(Data.Volume[bar] + "\t");
                if (Backtester.IsPos(bar))
                {
                    sb.Append(Backtester.SummaryDir(bar) + "\t");
                    sb.Append(Backtester.SummaryLots(bar) + "\t");
                    sb.Append(Backtester.SummaryTrans(bar) + "\t");
                    sb.Append(Backtester.SummaryPrice(bar).ToString(ff) + "\t");
                    sb.Append(Backtester.ProfitLoss(bar) + "\t");
                    sb.Append(Backtester.FloatingPL(bar) + "\t");
                }
                else
                {
                    sb.Append("\t\t\t\t\t\t");
                }
                sb.Append(Backtester.ChargedSpread(bar) + "\t");
                sb.Append(Backtester.ChargedRollOver(bar) + "\t");
                sb.Append(Backtester.Balance(bar) + "\t");
                sb.Append(Backtester.Equity(bar) + "\t");
                sb.Append(Backtester.BackTestEvalToString(bar) + "\t");
                sb.Append(Environment.NewLine);
            }

            string fileName = Data.Strategy.StrategyName + "-" + Data.Symbol + "-" + Data.Period.ToString();

            SaveData(fileName, sb);
        }
示例#2
0
        /// <summary>
        ///     Navigates to a bar.
        /// </summary>
        private void Navigate(string sDir)
        {
            switch (sDir)
            {
            case "< !":
                for (int i = barCurrent - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.BackTestEval(i) == BacktestEval.Ambiguous)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case "! >":
                for (int i = barCurrent + 1; i < Data.Bars; i++)
                {
                    if (Backtester.BackTestEval(i) == BacktestEval.Ambiguous)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case "<<":
                for (int i = barCurrent - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.SummaryTrans(i) != Transaction.Transfer &&
                        Backtester.SummaryTrans(i) != Transaction.None)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case ">>":
                for (int i = barCurrent + 1; i < Data.Bars; i++)
                {
                    if (Backtester.SummaryTrans(i) != Transaction.Transfer &&
                        Backtester.SummaryTrans(i) != Transaction.None)
                    {
                        barCurrent = i;
                        break;
                    }
                }
                break;

            case "<max":
                int maxWp  = 0;
                int maxBar = barCurrent;
                for (int i = barCurrent - 1; i >= Data.FirstBar; i--)
                {
                    if (Backtester.WayPoints(i) > maxWp)
                    {
                        maxWp  = Backtester.WayPoints(i);
                        maxBar = i;
                    }
                }
                barCurrent = maxBar;
                break;

            case ">max":
                maxWp  = 0;
                maxBar = barCurrent;
                for (int i = barCurrent + 1; i < Data.Bars; i++)
                {
                    if (Backtester.WayPoints(i) > maxWp)
                    {
                        maxWp  = Backtester.WayPoints(i);
                        maxBar = i;
                    }
                }
                barCurrent = maxBar;
                break;

            case "<":
                if (barCurrent > Data.FirstBar)
                {
                    barCurrent--;
                }
                break;

            case ">":
                if (barCurrent < Data.Bars - 1)
                {
                    barCurrent++;
                }
                break;

            case "Go":
                barCurrent = (int)nudGo.Value - 1;
                break;
            }

            SetBtnNavigate();

            barInfo = Language.T("Bar") + ": " + (barCurrent + 1) +
                      " " + Data.Time[barCurrent].ToString(Data.Df) +
                      " " + Data.Time[barCurrent].ToString("HH:mm") + "; " +
                      Language.T("Interpolation method") + ": " +
                      Backtester.InterpolationMethodToString();

            var rectPnlChart = new Rectangle(Border, infoRowHeight, pnlChart.ClientSize.Width - 2 * Border,
                                             pnlChart.ClientSize.Height - infoRowHeight - Border);

            pnlChart.Invalidate(rectPnlChart);

            var rectPnlInfo = new Rectangle(Border, 2 * infoRowHeight, pnlInfo.ClientSize.Width - 2 * Border,
                                            pnlInfo.ClientSize.Height - 2 * infoRowHeight - Border);

            pnlInfo.Invalidate(rectPnlInfo);

            nudGo.Value = barCurrent + 1;
        }