Esempio n. 1
0
        /// <summary>
        ///     Loads, filters and saves all data files.
        /// </summary>
        private void LoadSaveData()
        {
            string[] files = Directory.GetFiles(Data.OfflineDataDir, "*.csv");
            foreach (string file in files)
            {
                string symbol = GetSymbolFromFileName(file);
                int    period = GetPeriodFromFileName(file);
                if (string.IsNullOrEmpty(symbol) || period == 0)
                {
                    continue;
                }

                InstrumentProperties instrProperties = Instruments.InstrumentList[symbol].Clone();
                var instrument = new Instrument(instrProperties, period)
                {
                    DataDir      = Data.OfflineDataDir,
                    MaxBars      = Configs.MaxBars,
                    StartTime    = Configs.DataStartTime,
                    EndTime      = Configs.DataEndTime,
                    UseStartTime = Configs.UseStartTime,
                    UseEndTime   = Configs.UseEndTime
                };

                int loadDataResult = instrument.LoadData();

                if (instrument.Bars > 0 && loadDataResult == 0)
                {
                    var stringBuilder = new StringBuilder(instrument.Bars);
                    for (int bar = 0; bar < instrument.Bars; bar++)
                    {
                        stringBuilder.AppendLine(
                            instrument.Time(bar).ToString("yyyy-MM-dd") + "\t" +
                            instrument.Time(bar).ToString("HH:mm") + "\t" +
                            instrument.Open(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.High(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.Low(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.Close(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.Volume(bar).ToString(CultureInfo.InvariantCulture)
                            );
                    }
                    try
                    {
                        var sw = new StreamWriter(file);
                        sw.Write(stringBuilder.ToString());
                        sw.Close();

                        TbxOutput.Text += symbol + period + " bars: " + instrument.Bars + Environment.NewLine;
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     LoadInstrument
        /// </summary>
        private void LoadInstrument()
        {
            const string     symbol     = "EURUSD";
            const DataPeriod dataPeriod = DataPeriod.D1;

            var instrProperties  = new InstrumentProperties(symbol);
            var instrument       = new Instrument(instrProperties, (int)dataPeriod);
            int loadResourceData = instrument.LoadResourceData();

            if (instrument.Bars <= 0 || loadResourceData != 0)
            {
                return;
            }

            Data.InstrProperties = instrProperties.Clone();
            Data.Bars            = instrument.Bars;
            Data.Period          = dataPeriod;
            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.IsData = true;
        }
        /// <summary>
        ///     Loads, filters and saves all data files.
        /// </summary>
        private void LoadSaveData()
        {
            string[] files = Directory.GetFiles(Data.OfflineDataDir, "*.csv");
            foreach (string file in files)
            {
                string symbol = GetSymbolFromFileName(file);
                int period = GetPeriodFromFileName(file);
                if (string.IsNullOrEmpty(symbol) || period == 0)
                    continue;

                InstrumentProperties instrProperties = Instruments.InstrumentList[symbol].Clone();
                var instrument = new Instrument(instrProperties, period)
                    {
                        DataDir = Data.OfflineDataDir,
                        MaxBars = Configs.MaxBars,
                        StartTime = Configs.DataStartTime,
                        EndTime = Configs.DataEndTime,
                        UseStartTime = Configs.UseStartTime,
                        UseEndTime = Configs.UseEndTime
                    };

                int loadDataResult = instrument.LoadData();

                if (instrument.Bars > 0 && loadDataResult == 0)
                {
                    var stringBuilder = new StringBuilder(instrument.Bars);
                    for (int bar = 0; bar < instrument.Bars; bar++)
                    {
                        stringBuilder.AppendLine(
                            instrument.Time(bar).ToString("yyyy-MM-dd") + "\t" +
                            instrument.Time(bar).ToString("HH:mm") + "\t" +
                            instrument.Open(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.High(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.Low(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.Close(bar).ToString(CultureInfo.InvariantCulture) + "\t" +
                            instrument.Volume(bar).ToString(CultureInfo.InvariantCulture)
                            );
                    }
                    try
                    {
                        var sw = new StreamWriter(file);
                        sw.Write(stringBuilder.ToString());
                        sw.Close();

                        TbxOutput.Text += symbol + period + " bars: " + instrument.Bars + Environment.NewLine;
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                }
            }
        }
        /// <summary>
        ///     LoadInstrument
        /// </summary>
        private int LoadInstrument(bool useResource)
        {
            Cursor = Cursors.WaitCursor;

            //  Takes the instrument symbol and period
            string symbol = ComboBoxSymbol.Text;
            var dataPeriod = (DataPeriod) Enum.GetValues(typeof (DataPeriod)).GetValue(ComboBoxPeriod.SelectedIndex);
            InstrumentProperties instrProperties = Instruments.InstrumentList[symbol].Clone();

            //  Makes an instance of class Instrument
            var instrument = new Instrument(instrProperties, (int) dataPeriod)
                {
                    DataDir = Data.OfflineDataDir,
                    MaxBars = Configs.MaxBars,
                    StartTime = Configs.DataStartTime,
                    EndTime = Configs.DataEndTime,
                    UseStartTime = Configs.UseStartTime,
                    UseEndTime = Configs.UseEndTime
                };

            // Loads the data
            int loadDataResult = useResource
                                     ? instrument.LoadResourceData(Resources.EURUSD1440, DataPeriod.D1)
                                     : instrument.LoadData();

            if (instrument.Bars > 0 && loadDataResult == 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();
                InfoPanelMarketStatistics.Update(Data.MarketStatsParam, Data.MarketStatsValue,
                                                 Data.MarketStatsFlag, Language.T("Market Statistics"));
                InfoPanelAccountStatistics.Update(Backtester.AccountStatsParam, Backtester.AccountStatsValue,
                                                  Backtester.AccountStatsFlags, Language.T("Account Statistics"));
            }
            else if (loadDataResult == -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;
        }
Esempio n. 5
0
        /// <summary>
        ///     LoadInstrument
        /// </summary>
        private void LoadInstrument()
        {
            const string symbol = "EURUSD";
            const DataPeriod dataPeriod = DataPeriod.D1;

            var instrProperties = new InstrumentProperties(symbol);
            var instrument = new Instrument(instrProperties, (int) dataPeriod);
            int loadResourceData = instrument.LoadResourceData();

            if (instrument.Bars <= 0 || loadResourceData != 0) return;

            Data.InstrProperties = instrProperties.Clone();
            Data.Bars = instrument.Bars;
            Data.Period = dataPeriod;
            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.IsData = true;
        }