DataPeriodToString() публичный статический Метод

Converts a data period from DataPeriods type to string.
public static DataPeriodToString ( DataPeriods dataPeriod ) : string
dataPeriod DataPeriods
Результат string
Пример #1
0
        public static void ExportStrategyToIndicator()
        {
            StringBuilder sbLong  = new StringBuilder();
            StringBuilder sbShort = new StringBuilder();

            for (int iBar = Data.FirstBar; iBar < Data.Bars; iBar++)
            {
                for (int iPos = 0; iPos < Backtester.Positions(iBar); iPos++)
                {
                    if (Backtester.PosDir(iBar, iPos) == PosDirection.Long)
                    {
                        sbLong.AppendLine("				\""+ Data.Time[iBar].ToString() + "\",");
                    }

                    if (Backtester.PosDir(iBar, iPos) == PosDirection.Short)
                    {
                        sbShort.AppendLine("				\""+ Data.Time[iBar].ToString() + "\",");
                    }
                }
            }

            string strategy = Properties.Resources.StrategyToIndicator;

            strategy = strategy.Replace("#MODIFIED#", DateTime.Now.ToString());
            strategy = strategy.Replace("#INSTRUMENT#", Data.Symbol);
            strategy = strategy.Replace("#BASEPERIOD#", Data.DataPeriodToString(Data.Period));
            strategy = strategy.Replace("#STARTDATE#", Data.Time[Data.FirstBar].ToString());
            strategy = strategy.Replace("#ENDDATE#", Data.Time[Data.Bars - 1].ToString());

            strategy = strategy.Replace("#PERIODMINUTES#", ((int)Data.Period).ToString());
            strategy = strategy.Replace("#LISTLONG#", sbLong.ToString());
            strategy = strategy.Replace("#LISTSHORT#", sbShort.ToString());

            SaveFileDialog savedlg = new SaveFileDialog();

            savedlg.InitialDirectory = Data.SourceFolder;
            savedlg.AddExtension     = true;
            savedlg.Title            = Language.T("Custom Indicators");
            savedlg.Filter           = Language.T("Custom Indicators") + " (*.cs)|*.cs";

            if (savedlg.ShowDialog() == DialogResult.OK)
            {
                strategy = strategy.Replace("#INDICATORNAME#", Path.GetFileNameWithoutExtension(savedlg.FileName));
                StreamWriter sw = new StreamWriter(savedlg.FileName);
                try
                {
                    sw.Write(strategy);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, Language.T("Custom Indicators"));
                }
                finally
                {
                    sw.Close();
                }
            }

            return;
        }
Пример #2
0
 /// <summary>
 /// Generate the Market Statistics
 /// </summary>
 public static void GenerateMarketStats()
 {
     marketStatsValue[0]  = Data.Symbol.ToString();
     marketStatsValue[1]  = Data.DataPeriodToString(Data.Period);
     marketStatsValue[2]  = Data.Bars.ToString();
     marketStatsValue[3]  = Data.Update.ToString(dateFormat);
     marketStatsValue[4]  = Data.Update.ToString("HH:mm");
     marketStatsValue[5]  = Data.Time[0].ToString(dateFormat);
     marketStatsValue[6]  = Data.Time[0].ToString("HH:mm");
     marketStatsValue[7]  = Data.MinPrice.ToString();
     marketStatsValue[8]  = Data.MaxPrice.ToString();
     marketStatsValue[9]  = Data.AverageGap.ToString() + " " + Language.T("pips");
     marketStatsValue[10] = Data.MaxGap.ToString() + " " + Language.T("pips");
     marketStatsValue[11] = Data.AverageHighLow.ToString() + " " + Language.T("pips");
     marketStatsValue[12] = Data.MaxHighLow.ToString() + " " + Language.T("pips");
     marketStatsValue[13] = Data.AverageCloseOpen.ToString() + " " + Language.T("pips");
     marketStatsValue[14] = Data.MaxCloseOpen.ToString() + " " + Language.T("pips");
     marketStatsValue[15] = Data.DaysOff.ToString();
     marketStatsValue[16] = Configs.MaxBars.ToString();
     marketStatsValue[17] = Configs.UseStartDate ?
                            (new DateTime(Configs.StartYear, Configs.StartMonth, Configs.StartDay)).ToShortDateString() :
                            Language.T("No limits");
     marketStatsValue[18] = Configs.UseEndDate ?
                            (new DateTime(Configs.EndYear, Configs.EndMonth, Configs.EndDay)).ToShortDateString() :
                            Language.T("No limits");
     marketStatsValue[19] = Configs.FillInDataGaps ? Language.T("Accomplished") : Language.T("Switched off");
     marketStatsValue[20] = Configs.CutBadData     ? Language.T("Accomplished") : Language.T("Switched off");
     return;
 }
Пример #3
0
        /// <summary>
        /// Check the needed market conditions
        /// </summary>
        /// <param name="isMessage">To show the message or not</param>
        void AfterStrategyOpening(bool isMessage)
        {
            if (Data.Strategy.Symbol != Data.Symbol || Data.Strategy.DataPeriod != Data.Period)
            {
                bool toReload = true;

                if (isMessage)
                {
                    DialogResult result;

                    result = MessageBox.Show(
                        Language.T("The loaded strategy has been designed for a different market!") +
                        Environment.NewLine + Environment.NewLine +
                        Data.Strategy.Symbol + " " + Data.DataPeriodToString(Data.Strategy.DataPeriod) +
                        Environment.NewLine + Environment.NewLine +
                        Language.T("Do you want to load this market data?"),
                        Data.Strategy.StrategyName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    toReload = (result == DialogResult.Yes);
                }

                if (toReload)
                {
                    if (!Instruments.InstrumentList.ContainsKey(Data.Strategy.Symbol))
                    {
                        MessageBox.Show(
                            Language.T("There is no information for this market!") +
                            Environment.NewLine + Environment.NewLine +
                            Data.Strategy.Symbol + " " + Data.DataPeriodToString(Data.Strategy.DataPeriod),
                            Data.Strategy.StrategyName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        return;
                    }

                    string      symbol     = Data.Symbol;
                    DataPeriods dataPeriod = Data.Period;

                    SetMarket(Data.Strategy.Symbol, Data.Strategy.DataPeriod);

                    if (LoadInstrument(false) == 0)
                    {
                        Calculate(true);
                        PrepareScannerCompactMode();
                    }
                    else
                    {
                        SetMarket(symbol, dataPeriod);
                    }
                }
            }
            else if (!Data.IsIntrabarData)
            {
                PrepareScannerCompactMode();
            }

            return;
        }
Пример #4
0
        void ImportBarFile(JForex_Data_Files file)
        {
            StreamReader streamReader = new StreamReader(file.FilePath);
            StreamWriter streamWriter = new StreamWriter(file.FileTargetPath);

            string dateFormat;

            dateFormat = "yyyy.MM.dd HH:mm:ss";

            char            fieldSplitter  = ',';
            IFormatProvider formatProvider = System.Globalization.CultureInfo.InvariantCulture;
            string          line           = "";
            int             bars           = 0;

            try
            {
                while (!streamReader.EndOfStream)
                {
                    line = streamReader.ReadLine();
                    if (line.StartsWith("Time"))
                    {
                        continue; // Skips annotation line.
                    }
                    string[] data = line.Split(new char[] { fieldSplitter });

                    DateTime time   = DateTime.ParseExact(data[0], dateFormat, formatProvider);
                    double   open   = StringToDouble(data[1]);
                    double   high   = StringToDouble(data[2]);
                    double   low    = StringToDouble(data[3]);
                    double   close  = StringToDouble(data[4]);
                    int      volume = (int)StringToDouble(data[5]);

                    if (volume > 0 && !(open == high && open == low && open == close))
                    {
                        streamWriter.WriteLine(
                            time.ToString("yyyy-MM-dd\tHH:mm") + "\t" +
                            open.ToString() + "\t" +
                            high.ToString() + "\t" +
                            low.ToString() + "\t" +
                            close.ToString() + "\t" +
                            volume.ToString()
                            );
                        bars++;
                    }
                }
            }
            catch (Exception excaption)
            {
                MessageBox.Show(excaption.Message);
            }

            streamWriter.Close();
            streamReader.Close();
            SetInfoText(file.Symbol + " " + Data.DataPeriodToString((DataPeriods)file.Period) + " - " +
                        (Language.T("Bars")).ToLower() + ": " + bars.ToString() + Environment.NewLine);
        }
Пример #5
0
        /// <summary>
        /// Checks the loaded data
        /// </summary>
        void CheckLoadedData()
        {
            SetInstrumentDataStatusBar();

            if (!Configs.CheckData)
            {
                return;
            }

            string errorMessage = "";

            // Check for defective data
            int maxConsecutiveBars = 0;
            int maxConsecutiveBar  = 0;
            int consecutiveBars    = 0;
            int lastBar            = 0;

            for (int iBar = 0; iBar < Data.Bars; iBar++)
            {
                if (Data.Open[iBar] == Data.Close[iBar])
                {
                    if (lastBar == iBar - 1 || lastBar == 0)
                    {
                        consecutiveBars++;
                        lastBar = iBar;

                        if (consecutiveBars > maxConsecutiveBars)
                        {
                            maxConsecutiveBars = consecutiveBars;
                            maxConsecutiveBar  = iBar;
                        }
                    }
                }
                else
                {
                    consecutiveBars = 0;
                }
            }

            if (maxConsecutiveBars > 10)
            {
                errorMessage += Language.T("Defective till bar number:") + " " + (maxConsecutiveBar + 1) + " - " +
                                Data.Time[maxConsecutiveBar].ToString() + Environment.NewLine +
                                Language.T("You can try to cut it using \"Data Horizon\".") + Environment.NewLine +
                                Language.T("You can try also \"Cut Off Bad Data\".");
            }

            if (Data.Bars < 300)
            {
                errorMessage += Language.T("Contains less than 300 bars!") + Environment.NewLine +
                                Language.T("Check your data file or the limits in \"Data Horizon\".");
            }

            if (Data.DaysOff > 5 && Data.Period != DataPeriods.week)
            {
                errorMessage += Language.T("Maximum days off") + " " + Data.DaysOff + Environment.NewLine +
                                Language.T("The data is probably incomplete!") + Environment.NewLine +
                                Language.T("You can try also \"Cut Off Bad Data\".");
            }

            if (errorMessage != "")
            {
                errorMessage = Language.T("Market") + " " + Data.Symbol + " " + Data.DataPeriodToString(Data.Period) + Environment.NewLine + errorMessage;
                MessageBox.Show(errorMessage, Language.T("Data File Loading"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return;
        }
Пример #6
0
        /// <summary>
        /// LoadInstrument
        /// </summary>
        int LoadInstrument(bool useResource)
        {
            string      symbol;
            DataPeriods dataPeriod;

            Cursor = Cursors.WaitCursor;

            //  Takes the instrument symbol and period
            symbol     = tscbSymbol.Text;
            dataPeriod = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(tscbPeriod.SelectedIndex);
            Instrument_Properties instrProperties = Instruments.InstrumentList[symbol].Clone();

            //  Makes an instance of class Instrument
            Instrument instrument = new Instrument(instrProperties, (int)dataPeriod);

            instrument.DataDir      = Data.OfflineDataDir;
            instrument.FormatDate   = DateFormat.Unknown;
            instrument.MaxBars      = Configs.MaxBars;
            instrument.StartYear    = Configs.StartYear;
            instrument.StartMonth   = Configs.StartMonth;
            instrument.StartDay     = Configs.StartDay;
            instrument.EndYear      = Configs.EndYear;
            instrument.EndMonth     = Configs.EndMonth;
            instrument.EndDay       = Configs.EndDay;
            instrument.UseStartDate = Configs.UseStartDate;
            instrument.UseEndDate   = Configs.UseEndDate;

            // Loads the data
            int iLoadDataResult = 0;

            if (useResource)
            {
                iLoadDataResult = instrument.LoadResourceData();
            }
            else
            {
                iLoadDataResult = instrument.LoadData();
            }

            if (instrument.Bars > 0 && iLoadDataResult == 0)
            {
                Data.InstrProperties = instrProperties.Clone();

                Data.Bars   = instrument.Bars;
                Data.Period = dataPeriod;
                Data.Update = instrument.Update;

                Data.Time   = new DateTime[Data.Bars];
                Data.Open   = new double[Data.Bars];
                Data.High   = new double[Data.Bars];
                Data.Low    = new double[Data.Bars];
                Data.Close  = new double[Data.Bars];
                Data.Volume = new int[Data.Bars];

                for (int bar = 0; bar < Data.Bars; bar++)
                {
                    Data.Open[bar]   = instrument.Open(bar);
                    Data.High[bar]   = instrument.High(bar);
                    Data.Low[bar]    = instrument.Low(bar);
                    Data.Close[bar]  = instrument.Close(bar);
                    Data.Time[bar]   = instrument.Time(bar);
                    Data.Volume[bar] = instrument.Volume(bar);
                }

                Data.MinPrice         = instrument.MinPrice;
                Data.MaxPrice         = instrument.MaxPrice;
                Data.DaysOff          = instrument.DaysOff;
                Data.AverageGap       = instrument.AverageGap;
                Data.MaxGap           = instrument.MaxGap;
                Data.AverageHighLow   = instrument.AverageHighLow;
                Data.MaxHighLow       = instrument.MaxHighLow;
                Data.AverageCloseOpen = instrument.AverageCloseOpen;
                Data.MaxCloseOpen     = instrument.MaxCloseOpen;
                Data.DataCut          = instrument.Cut;
                Data.IsIntrabarData   = false;
                Data.IsTickData       = false;
                Data.IsData           = true;
                Data.IsResult         = false;

                // Configs.SetAccountExchangeRate();

                CheckLoadedData();
                Data.GenerateMarketStats();
                infpnlMarketStatistics.Update(Data.MarketStatsParam, Data.MarketStatsValue,
                                              Data.MarketStatsFlag, Language.T("Market Statistics"));
                infpnlAccountStatistics.Update(Backtester.AccountStatsParam, Backtester.AccountStatsValue,
                                               Backtester.AccountStatsFlags, Language.T("Account Statistics"));
            }
            else if (iLoadDataResult == -1)
            {
                MessageBox.Show(Language.T("Error in the data file!"), Language.T("Data file loading"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor = Cursors.Default;
                return(1);
            }
            else
            {
                MessageBox.Show(Language.T("There is no data for") + " " + symbol + " " + Data.DataPeriodToString(dataPeriod) + " " +
                                Language.T("in folder") + " " + Data.OfflineDataDir + Environment.NewLine + Environment.NewLine +
                                Language.T("Check the offline data directory path (Menu Market -> Data Directory)"),
                                Language.T("Data File Loading"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Cursor = Cursors.Default;
                return(1);
            }

            Cursor = Cursors.Default;

            return(0);
        }
Пример #7
0
        /// <summary>
        /// Loads the Intrabar data.
        /// </summary>
        private int LoadIntrabarData(DataPeriods period)
        {
            var instrument = new Instrument(Data.InstrProperties.Clone(), (int)period)
            {
                DataDir = Data.OfflineDataDir,
                MaxBars = Configs.MaxIntraBars
            };


            // Loads the data
            int loadingResult   = instrument.LoadData();
            int loadedIntrabars = instrument.Bars;

            if (loadingResult == 0 && loadedIntrabars > 0)
            {
                if (Data.Period != DataPeriods.week)
                {
                    if (instrument.DaysOff > 5)
                    {
                        _warningMessage += Environment.NewLine + Language.T("Data for:") + " " + Data.Symbol + " " +
                                           Data.DataPeriodToString(period) + " - " + Language.T("Maximum days off:") +
                                           " " + instrument.DaysOff;
                    }
                    if (Data.Update - instrument.Update > new TimeSpan(24, 0, 0))
                    {
                        _warningMessage += Environment.NewLine + Language.T("Data for:") + " " + Data.Symbol + " " +
                                           Data.DataPeriodToString(period) + " - " + Language.T("Updated on:") + " " +
                                           instrument.Update.ToString(CultureInfo.InvariantCulture);
                    }
                }

                int startBigBar;
                for (startBigBar = 0; startBigBar < Data.Bars; startBigBar++)
                {
                    if (Data.Time[startBigBar] >= instrument.Time(0))
                    {
                        break;
                    }
                }

                int stopBigBar;
                for (stopBigBar = startBigBar; stopBigBar < Data.Bars; stopBigBar++)
                {
                    if (Data.IntraBarsPeriods[stopBigBar] != Data.Period)
                    {
                        break;
                    }
                }

                // Seek for a place to put the intrabars.
                int lastIntraBar = 0;
                for (int bar = startBigBar; bar < stopBigBar; bar++)
                {
                    Data.IntraBarData[bar] = new Bar[(int)Data.Period / (int)period];
                    DateTime endTime  = Data.Time[bar] + new TimeSpan(0, (int)Data.Period, 0);
                    int      indexBar = 0;
                    for (int intrabar = lastIntraBar;
                         intrabar < loadedIntrabars && instrument.Time(intrabar) < endTime;
                         intrabar++)
                    {
                        if (instrument.Time(intrabar) >= Data.Time[bar])
                        {
                            Data.IntraBarData[bar][indexBar].Time  = instrument.Time(intrabar);
                            Data.IntraBarData[bar][indexBar].Open  = instrument.Open(intrabar);
                            Data.IntraBarData[bar][indexBar].High  = instrument.High(intrabar);
                            Data.IntraBarData[bar][indexBar].Low   = instrument.Low(intrabar);
                            Data.IntraBarData[bar][indexBar].Close = instrument.Close(intrabar);
                            Data.IntraBarsPeriods[bar]             = period;
                            Data.IntraBarBars[bar]++;
                            indexBar++;
                            lastIntraBar = intrabar;
                        }
                    }
                }
            }

            return(loadedIntrabars);
        }
Пример #8
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        private void LoadData(BackgroundWorker worker)
        {
            int periodsToLoad = 0;
            int allPeriods    = Enum.GetValues(typeof(DataPeriods)).Length;

            Data.IntraBars             = new int[allPeriods];
            Data.IntraBarData          = new Bar[Data.Bars][];
            Data.IntraBarBars          = new int[Data.Bars];
            Data.IntraBarsPeriods      = new DataPeriods[Data.Bars];
            Data.LoadedIntraBarPeriods = 0;

            for (int bar = 0; bar < Data.Bars; bar++)
            {
                Data.IntraBarsPeriods[bar] = Data.Period;
                Data.IntraBarBars[bar]     = 0;
            }

            // Counts how many periods to load
            for (int prd = 0; prd < allPeriods; prd++)
            {
                var period = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);
                if (period < Data.Period)
                {
                    periodsToLoad++;
                }
            }

            // Load the intrabar data (Starts from 1 Min)
            for (int prd = 0; prd < allPeriods && _isLoadingNow; prd++)
            {
                if (worker.CancellationPending)
                {
                    break;
                }

                int loadedBars = 0;
                var period     = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);

                SetLabelProgressText(Language.T("Loading:") + " " + Data.DataPeriodToString(period) + "...");

                if (period < Data.Period)
                {
                    loadedBars = LoadIntrabarData(period);
                    if (loadedBars > 0)
                    {
                        Data.IsIntrabarData = true;
                        Data.LoadedIntraBarPeriods++;
                    }
                }
                else if (period == Data.Period)
                {
                    loadedBars = Data.Bars;
                    Data.LoadedIntraBarPeriods++;
                }

                Data.IntraBars[prd] = loadedBars;

                // Report progress as a percentage of the total task.
                int percentComplete = periodsToLoad > 0 ? 100 * (prd + 1) / periodsToLoad : 100;
                percentComplete = percentComplete > 100 ? 100 : percentComplete;
                if (percentComplete > _progressPercent)
                {
                    _progressPercent = percentComplete;
                    worker.ReportProgress(percentComplete);
                }
            }

            CheckIntrabarData();
            RepairIntrabarData();

            if (Configs.UseTickData)
            {
                SetLabelProgressText(Language.T("Loading:") + " " + Language.T("Ticks") + "...");
                worker.ReportProgress(200);
                try
                {
                    LoadTickData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Repaint the panel Info
        /// </summary>
        private void PnlInfoPaint(object sender, PaintEventArgs e)
        {
            // +------------------------------------------------------+
            // |                   Data                               |
            // |------------------- ----------------------------------+
            // | Period  | Bars  | From | Until | Cover |  %  | Label |
            // |------------------------------------------------------+
            //xp0       xp1     xp2    xp3     xp4     xp5   xp6     xp7

            Graphics g = e.Graphics;

            g.Clear(LayoutColors.ColorControlBack);

            if (!Data.IsData || !Data.IsResult)
            {
                return;
            }

            var       pnl    = (Panel)sender;
            const int border = 2;
            const int xp0    = border;
            const int xp1    = 80;
            const int xp2    = 140;
            const int xp3    = 200;
            const int xp4    = 260;
            const int xp5    = 320;
            const int xp6    = 370;
            int       xp7    = pnl.ClientSize.Width - border;

            var size = new Size(xp7 - xp0, _infoRowHeight);

            var sf = new StringFormat {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near
            };

            // Caption background
            var   pntStart     = new PointF(0, 0);
            SizeF szfCaption   = new Size(pnl.ClientSize.Width - 0, 2 * _infoRowHeight);
            var   rectfCaption = new RectangleF(pntStart, szfCaption);

            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);

            // Caption Text
            var stringFormatCaption = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Near
            };
            string stringCaptionText = Language.T("Intrabar Data");
            float  captionWidth      = Math.Min(InfoPanel.ClientSize.Width, xp7 - xp0);
            float  captionTextWidth  = g.MeasureString(stringCaptionText, _fontInfo).Width;
            float  captionTextX      = Math.Max((captionWidth - captionTextWidth) / 2f, 0);
            var    pfCaptionText     = new PointF(captionTextX, 0);
            var    sfCaptionText     = new SizeF(captionWidth - captionTextX, _infoRowHeight);

            rectfCaption = new RectangleF(pfCaptionText, sfCaptionText);

            Brush brush = new SolidBrush(LayoutColors.ColorCaptionText);

            // First caption row
            g.DrawString(stringCaptionText, _fontInfo, brush, rectfCaption, stringFormatCaption);

            // Second title row
            g.DrawString(Language.T("Period"), _fontInfo, brush, (xp1 + xp0) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Bars"), _fontInfo, brush, (xp2 + xp1) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("From"), _fontInfo, brush, (xp3 + xp2) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Until"), _fontInfo, brush, (xp4 + xp3) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Coverage"), _fontInfo, brush, (xp5 + xp4) / 2f, _infoRowHeight, sf);
            g.DrawString("%", _fontInfo, brush, (xp6 + xp5) / 2f, _infoRowHeight, sf);
            g.DrawString(Language.T("Label"), _fontInfo, brush, (xp7 + xp6) / 2f, _infoRowHeight, sf);

            brush = new SolidBrush(LayoutColors.ColorControlText);
            int allPeriods = Enum.GetValues(typeof(DataPeriods)).Length;

            for (int period = 0; period <= allPeriods; period++)
            {
                int y     = (period + 2) * _infoRowHeight;
                var point = new Point(xp0, y);

                if (Math.Abs(period % 2f - 0) > 0.0001)
                {
                    g.FillRectangle(new SolidBrush(LayoutColors.ColorEvenRowBack), new Rectangle(point, size));
                }
            }

            // Tick statistics
            if (_isTickDataFile)
            {
                g.DrawString(Language.T("Tick"), _fontInfo, brush, (xp1 + xp0) / 2, 2 * _infoRowHeight, sf);
                if (Data.IsTickData && Configs.UseTickData)
                {
                    int firstBarWithTicks = -1;
                    int lastBarWithTicks  = -1;
                    int tickBars          = 0;
                    for (int b = 0; b < Data.Bars; b++)
                    {
                        if (firstBarWithTicks == -1 && Data.TickData[b] != null)
                        {
                            firstBarWithTicks = b;
                        }
                        if (Data.TickData[b] != null)
                        {
                            lastBarWithTicks = b;
                            tickBars++;
                        }
                    }
                    double percentage = 100d * tickBars / Data.Bars;

                    int    y     = 2 * _infoRowHeight;
                    string ticks = (Data.Ticks > 999999) ? (Data.Ticks / 1000).ToString(CultureInfo.InvariantCulture) + "K" : Data.Ticks.ToString(CultureInfo.InvariantCulture);
                    g.DrawString(ticks, _fontInfo, brush, (xp2 + xp1) / 2, y, sf);
                    g.DrawString((firstBarWithTicks + 1).ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp3 + xp2) / 2, y, sf);
                    g.DrawString((lastBarWithTicks + 1).ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp4 + xp3) / 2, y, sf);
                    g.DrawString(tickBars.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp5 + xp4) / 2, y, sf);
                    g.DrawString(percentage.ToString("F2"), _fontInfo, brush, (xp6 + xp5) / 2, y, sf);

                    var rectf = new RectangleF(xp6 + 10, y + 4, xp7 - xp6 - 20, 9);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.min1], 60);
                    rectf = new RectangleF(xp6 + 10, y + 7, xp7 - xp6 - 20, 3);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[DataPeriods.day], 60);
                }
            }

            for (int prd = 0; prd < allPeriods; prd++)
            {
                int startY = _isTickDataFile ? 3 : 2;
                int y      = (prd + startY) * _infoRowHeight;

                var    period      = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);
                int    intraBars   = Data.IntraBars == null || !Data.IsIntrabarData ? 0 : Data.IntraBars[prd];
                int    fromBar     = 0;
                int    untilBar    = 0;
                int    coveredBars = 0;
                double percentage  = 0;

                bool isMultyAreas = false;
                if (intraBars > 0)
                {
                    bool isFromBarFound  = false;
                    bool isUntilBarFound = false;
                    untilBar = Data.Bars;
                    for (int bar = 0; bar < Data.Bars; bar++)
                    {
                        if (!isFromBarFound && Data.IntraBarsPeriods[bar] == period)
                        {
                            fromBar        = bar;
                            isFromBarFound = true;
                        }
                        if (isFromBarFound && !isUntilBarFound &&
                            (Data.IntraBarsPeriods[bar] != period || bar == Data.Bars - 1))
                        {
                            if (bar < Data.Bars - 1)
                            {
                                isUntilBarFound = true;
                                untilBar        = bar;
                            }
                            else
                            {
                                untilBar = Data.Bars;
                            }
                            coveredBars = untilBar - fromBar;
                        }
                        if (isFromBarFound && isUntilBarFound && Data.IntraBarsPeriods[bar] == period)
                        {
                            isMultyAreas = true;
                            coveredBars++;
                        }
                    }
                    if (isFromBarFound)
                    {
                        percentage = 100d * coveredBars / Data.Bars;
                        fromBar++;
                    }
                    else
                    {
                        fromBar     = 0;
                        untilBar    = 0;
                        coveredBars = 0;
                        percentage  = 0;
                    }
                }
                else if (period == Data.Period)
                {
                    intraBars   = Data.Bars;
                    fromBar     = 1;
                    untilBar    = Data.Bars;
                    coveredBars = Data.Bars;
                    percentage  = 100;
                }

                g.DrawString(Data.DataPeriodToString(period), _fontInfo, brush, (xp1 + xp0) / 2, y, sf);

                if (coveredBars > 0 || period == Data.Period)
                {
                    g.DrawString(intraBars.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp2 + xp1) / 2, y, sf);
                    g.DrawString(fromBar.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp3 + xp2) / 2, y, sf);
                    g.DrawString(untilBar.ToString(CultureInfo.InvariantCulture), _fontInfo, brush, (xp4 + xp3) / 2, y, sf);
                    g.DrawString(coveredBars.ToString(CultureInfo.InvariantCulture) + (isMultyAreas ? "*" : ""), _fontInfo, brush, (xp5 + xp4) / 2, y, sf);
                    g.DrawString(percentage.ToString("F2"), _fontInfo, brush, (xp6 + xp5) / 2, y, sf);

                    var rectf = new RectangleF(xp6 + 10, y + 4, xp7 - xp6 - 20, 9);
                    Data.GradientPaint(g, rectf, Data.PeriodColor[period], 60);
                }
            }

            var penLine = new Pen(LayoutColors.ColorJournalLines);

            g.DrawLine(penLine, xp1, 2 * _infoRowHeight, xp1, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp2, 2 * _infoRowHeight, xp2, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp3, 2 * _infoRowHeight, xp3, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp4, 2 * _infoRowHeight, xp4, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp5, 2 * _infoRowHeight, xp5, pnl.ClientSize.Height);
            g.DrawLine(penLine, xp6, 2 * _infoRowHeight, xp6, pnl.ClientSize.Height);

            // Border
            var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption),
                                    border);

            g.DrawLine(penBorder, 1, 2 * _infoRowHeight, 1, pnl.ClientSize.Height);
            g.DrawLine(penBorder, pnl.ClientSize.Width - border + 1, 2 * _infoRowHeight, pnl.ClientSize.Width - border + 1,
                       pnl.ClientSize.Height);
            g.DrawLine(penBorder, 0, pnl.ClientSize.Height - border + 1, pnl.ClientSize.Width,
                       pnl.ClientSize.Height - border + 1);
        }
Пример #10
0
        /// <summary>
        /// Loads the Intrabar data.
        /// </summary>
        int LoadIntrabarData(DataPeriods period)
        {
            Instrument instrument = new Instrument(Data.InstrProperties.Clone(), (int)period);

            instrument.DataDir    = Data.OfflineDataDir;
            instrument.FormatDate = DateFormat.Unknown;
            instrument.MaxBars    = Configs.MAX_INTRA_BARS;

            // Loads the data
            int loadingResult   = instrument.LoadData();
            int loadedIntrabars = instrument.Bars;

            if (loadingResult == 0 && loadedIntrabars > 0)
            {
                if (Data.Period != DataPeriods.week)
                {
                    if (instrument.DaysOff > 5)
                    {
                        warningMessage += Environment.NewLine + Language.T("Data for:") + " " + Data.Symbol + " " +
                                          Data.DataPeriodToString(period) + " - " + Language.T("Maximum days off:") + " " + instrument.DaysOff;
                    }
                    if (Data.Update - instrument.Update > new TimeSpan(24, 0, 0))
                    {
                        warningMessage += Environment.NewLine + Language.T("Data for:") + " " + Data.Symbol + " " +
                                          Data.DataPeriodToString(period) + " - " + Language.T("Updated on:") + " " + instrument.Update.ToString();
                    }
                }

                int iStartBigBar = 0;
                for (iStartBigBar = 0; iStartBigBar < Data.Bars; iStartBigBar++)
                {
                    if (Data.Time[iStartBigBar] >= instrument.Time(0))
                    {
                        break;
                    }
                }

                int iStopBigBar = 0;
                for (iStopBigBar = iStartBigBar; iStopBigBar < Data.Bars; iStopBigBar++)
                {
                    if (Data.IntraBarsPeriods[iStopBigBar] != Data.Period)
                    {
                        break;
                    }
                }

                // Seek for the place
                int iReachedBar = 0;
                for (int bar = iStartBigBar; bar < iStopBigBar; bar++)
                {
                    Data.IntraBarData[bar] = new Bar[(int)Data.Period / (int)period];
                    DateTime endTime     = Data.Time[bar] + new TimeSpan(0, (int)Data.Period, 0);
                    int      iCurrentBar = 0;
                    for (int intrabar = iReachedBar; intrabar < loadedIntrabars && instrument.Time(intrabar) < endTime; intrabar++)
                    {
                        if (instrument.Time(intrabar) >= Data.Time[bar])
                        {
                            Data.IntraBarData[bar][iCurrentBar].Time  = instrument.Time(intrabar);
                            Data.IntraBarData[bar][iCurrentBar].Open  = instrument.Open(intrabar);
                            Data.IntraBarData[bar][iCurrentBar].High  = instrument.High(intrabar);
                            Data.IntraBarData[bar][iCurrentBar].Low   = instrument.Low(intrabar);
                            Data.IntraBarData[bar][iCurrentBar].Close = instrument.Close(intrabar);
                            Data.IntraBarsPeriods[bar] = period;
                            Data.IntraBarBars[bar]++;
                            iCurrentBar++;
                            iReachedBar = intrabar;
                        }
                    }
                }
            }

            return(loadedIntrabars);
        }