Forex_Strategy_Builder.Chart.GenerateDynamicInfo C# (CSharp) Метод

GenerateDynamicInfo() приватный Метод

Generates the DynamicInfo.
private GenerateDynamicInfo ( int barNumb ) : void
barNumb int
Результат void
        void GenerateDynamicInfo(int barNumb)
        {
            if (!isDynInfoShown || !isInfoPanelShown) return;

            barNumb = Math.Max(0, barNumb);
            barNumb = Math.Min(chartBars - 1, barNumb);

            int bar;
            bar = firstBar + barNumb;
            bar = Math.Min(Data.Bars - 1, bar);

            if (barOld == bar) return;
            barOld = bar;

            int row = 0;
            asInfoValue = new String[200];
            asInfoValue[row++] = (bar + 1).ToString();
            asInfoValue[row++] = Data.Time[bar].ToString(Data.DF);
            asInfoValue[row++] = Data.Time[bar].ToString("HH:mm");
            if (isDEBUG)
            {
                asInfoValue[row++] = Data.Open[bar].ToString();
                asInfoValue[row++] = Data.High[bar].ToString();
                asInfoValue[row++] = Data.Low[bar].ToString();
                asInfoValue[row++] = Data.Close[bar].ToString();
            }
            else
            {

                asInfoValue[row++] = Data.Open[bar].ToString(Data.FF);
                asInfoValue[row++] = Data.High[bar].ToString(Data.FF);
                asInfoValue[row++] = Data.Low[bar].ToString(Data.FF);
                asInfoValue[row++] = Data.Close[bar].ToString(Data.FF);
            }
            asInfoValue[row++] = Data.Volume[bar].ToString();

            asInfoValue[row++] = "";
            if (Configs.AccountInMoney)
            {
                // Balance
                asInfoValue[row++] = Backtester.MoneyBalance(bar).ToString("F2");

                // Equity
                asInfoValue[row++] = Backtester.MoneyEquity(bar).ToString("F2");

                // Profit Loss
                if (Backtester.SummaryTrans(bar) == Transaction.Close  ||
                    Backtester.SummaryTrans(bar) == Transaction.Reduce ||
                    Backtester.SummaryTrans(bar) == Transaction.Reverse)
                    asInfoValue[row++] = Backtester.MoneyProfitLoss(bar).ToString("F2");
                else
                    asInfoValue[row++] = "   -";

                // Floating P/L
                if (Backtester.Positions(bar) > 0 && Backtester.SummaryTrans(bar) != Transaction.Close)
                    asInfoValue[row++] = Backtester.MoneyFloatingPL(bar).ToString("F2");
                else
                    asInfoValue[row++] = "   -";
            }
            else
            {
                // Balance
                asInfoValue[row++] = Backtester.Balance(bar).ToString();

                // Equity
                asInfoValue[row++] = Backtester.Equity(bar).ToString();

                // Profit Loss
                if (Backtester.SummaryTrans(bar) == Transaction.Close  ||
                    Backtester.SummaryTrans(bar) == Transaction.Reduce ||
                    Backtester.SummaryTrans(bar) == Transaction.Reverse)
                    asInfoValue[row++] = Backtester.ProfitLoss(bar).ToString();
                else
                    asInfoValue[row++] = "   -";

                // Profit Loss
                if (Backtester.Positions(bar) > 0 && Backtester.SummaryTrans(bar) != Transaction.Close)
                    asInfoValue[row++] = Backtester.FloatingPL(bar).ToString();
                else
                    asInfoValue[row++] = "   -";
            }

            for (int slot = 0; slot < Data.Strategy.Slots; slot++)
            {
                if (Data.Strategy.Slot[slot] != null)
                {
                    int compToShow = 0;
                    foreach (IndicatorComp indComp in Data.Strategy.Slot[slot].Component)
                        if (indComp.ShowInDynInfo) compToShow++;
                    if (compToShow == 0) continue;

                    asInfoValue[row++] = "";
                    asInfoValue[row++] = "";
                    foreach (IndicatorComp indComp in Data.Strategy.Slot[slot].Component)
                    {
                        if (indComp.ShowInDynInfo)
                        {
                            IndComponentType indDataTipe = indComp.DataType;
                            if (indDataTipe == IndComponentType.AllowOpenLong  ||
                                indDataTipe == IndComponentType.AllowOpenShort ||
                                indDataTipe == IndComponentType.ForceClose     ||
                                indDataTipe == IndComponentType.ForceCloseLong ||
                                indDataTipe == IndComponentType.ForceCloseShort)
                                asInfoValue[row++] = (indComp.Value[bar] < 1 ? Language.T("No") : Language.T("Yes"));
                            else
                            {
                                if (isDEBUG)
                                {
                                    asInfoValue[row++] = indComp.Value[bar].ToString();
                                }
                                else
                                {
                                    double dl = Math.Abs(indComp.Value[bar]);
                                    string sFR = dl < 10 ? "F5" : dl < 100 ? "F4" : dl < 1000 ? "F3" : dl < 10000 ? "F2" : dl < 100000 ? "F1" : "F0";
                                    if (indComp.Value[bar] != 0)
                                        asInfoValue[row++] = indComp.Value[bar].ToString(sFR);
                                    else
                                        asInfoValue[row++] = "   -";
                                }
                            }
                        }
                    }
                }
            }

            // Positions
            int pos;
            for (pos = 0; pos < Backtester.Positions(bar); pos++)
            {
                asInfoValue[row++] = "";
                asInfoValue[row++] = Language.T(Backtester.PosDir(bar, pos).ToString());
                asInfoValue[row++] = Backtester.PosLots(bar, pos).ToString();
                asInfoValue[row++] = Language.T(Backtester.PosTransaction(bar, pos).ToString());
                asInfoValue[row++] = Backtester.PosOrdNumb(bar, pos).ToString();
                asInfoValue[row++] = Backtester.PosOrdPrice(bar, pos).ToString(Data.FF);
                asInfoValue[row++] = Backtester.PosPrice(bar, pos).ToString(Data.FF);

                // Profit Loss
                if (Backtester.PosTransaction(bar, pos) == Transaction.Close  ||
                    Backtester.PosTransaction(bar, pos) == Transaction.Reduce ||
                    Backtester.PosTransaction(bar, pos) == Transaction.Reverse)
                    asInfoValue[row++] = Configs.AccountInMoney ?
                        Backtester.PosMoneyProfitLoss(bar, pos).ToString("F2") :
                        Math.Round(Backtester.PosProfitLoss(bar, pos)).ToString();
                else
                    asInfoValue[row++] = "   -";

                // Floating P/L
                if (pos == Backtester.Positions(bar) - 1 && Backtester.PosTransaction(bar, pos) != Transaction.Close)
                    asInfoValue[row++] = Configs.AccountInMoney ?
                        Backtester.PosMoneyFloatingPL(bar, pos).ToString("F2"):
                        Math.Round(Backtester.PosFloatingPL(bar, pos)).ToString();
                else
                    asInfoValue[row++] = "   -";
            }

            if (posCount != pos)
            {
                posCount = pos;
                SetupDynamicInfo();
                isDrawDinInfo = true;
                pnlInfo.Invalidate();
            }
            else
            {
                pnlInfo.Invalidate(new Rectangle(XDynInfoCol2, 0, dynInfoWidth - XDynInfoCol2, pnlInfo.ClientSize.Height));
            }

            return;
        }