コード例 #1
0
        /// <summary>
        ///     Clones the Instrument_Properties.
        /// </summary>
        public InstrumentProperties Clone()
        {
            var copy = new InstrumentProperties(Symbol, InstrType)
            {
                Symbol          = Symbol,
                InstrType       = InstrType,
                Comment         = Comment,
                Digits          = Digits,
                LotSize         = LotSize,
                Spread          = Spread,
                SwapUnit        = SwapUnit,
                SwapLong        = SwapLong,
                SwapShort       = SwapShort,
                CommissionUnit  = CommissionUnit,
                CommissionScope = CommissionScope,
                CommissionTime  = CommissionTime,
                Commission      = Commission,
                PriceIn         = PriceIn,
                Slippage        = Slippage,
                RateToEUR       = RateToEUR,
                RateToUSD       = RateToUSD,
                BaseFileName    = BaseFileName
            };

            return(copy);
        }
コード例 #2
0
        private Bar[] aBar;                                    // An array containing the data

        /// <summary>
        ///     Constructor
        /// </summary>
        public Instrument(InstrumentProperties instrProperties, int period)
        {
            DataDir              = "." + Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar;
            EndTime              = new DateTime(2020, 1, 1, 0, 0, 0);
            StartTime            = new DateTime(1990, 1, 1, 0, 0, 0);
            MaxBars              = 20000;
            this.instrProperties = instrProperties;
            Period = period;
        }
コード例 #3
0
        private Bar[] aBar; // An array containing the data

        /// <summary>
        ///     Constructor
        /// </summary>
        public Instrument(InstrumentProperties instrProperties, int period)
        {
            DataDir = "." + Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar;
            EndTime = new DateTime(2020, 1, 1, 0, 0, 0);
            StartTime = new DateTime(1990, 1, 1, 0, 0, 0);
            MaxBars = 20000;
            this.instrProperties = instrProperties;
            Period = period;
        }
コード例 #4
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);
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        ///     Parses the instruments file.
        /// </summary>
        private static void ParseInstruments()
        {
            int instrumentsCount = XmlInstruments.GetElementsByTagName("instrument").Count;

            dictInstrument = new Dictionary <string, InstrumentProperties>(instrumentsCount);

            try
            {
                foreach (XmlNode nodeInstr in XmlInstruments.GetElementsByTagName("instrument"))
                {
                    string symbol    = nodeInstr.SelectSingleNode("symbol").InnerText;
                    var    instrType =
                        (InstrumetType)
                        Enum.Parse(typeof(InstrumetType), nodeInstr.SelectSingleNode("instrumentType").InnerText);
                    var instrProp = new InstrumentProperties(symbol, instrType)
                    {
                        Comment         = nodeInstr.SelectSingleNode("comment").InnerText,
                        Digits          = int.Parse(nodeInstr.SelectSingleNode("digits").InnerText),
                        LotSize         = int.Parse(nodeInstr.SelectSingleNode("contractSize").InnerText),
                        Spread          = StringToFloat(nodeInstr.SelectSingleNode("spread").InnerText),
                        SwapUnit        = ParseChargeUnit(nodeInstr.SelectSingleNode("swapType").InnerText),
                        SwapLong        = StringToFloat(nodeInstr.SelectSingleNode("swapLong").InnerText),
                        SwapShort       = StringToFloat(nodeInstr.SelectSingleNode("swapShort").InnerText),
                        CommissionUnit  = ParseChargeUnit(nodeInstr.SelectSingleNode("commissionType").InnerText),
                        CommissionScope =
                            (CommissionScope)
                            Enum.Parse(typeof(CommissionScope),
                                       nodeInstr.SelectSingleNode("commissionScope").InnerText),
                        CommissionTime =
                            (CommissionTime)
                            Enum.Parse(typeof(CommissionTime),
                                       nodeInstr.SelectSingleNode("commissionTime").InnerText),
                        Commission   = StringToFloat(nodeInstr.SelectSingleNode("commission").InnerText),
                        Slippage     = int.Parse(nodeInstr.SelectSingleNode("slippage").InnerText),
                        PriceIn      = nodeInstr.SelectSingleNode("priceIn").InnerText,
                        RateToUSD    = StringToFloat(nodeInstr.SelectSingleNode("rateToUSD").InnerText),
                        RateToEUR    = StringToFloat(nodeInstr.SelectSingleNode("rateToEUR").InnerText),
                        BaseFileName = nodeInstr.SelectSingleNode("baseFileName").InnerText
                    };
                    dictInstrument.Add(symbol, instrProp);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Parsing Instruments");
            }
        }
コード例 #6
0
        /// <summary>
        /// Clones the Instrument_Properties.
        /// </summary>
        public InstrumentProperties Clone()
        {
            var copy = new InstrumentProperties(Symbol)
            {
                Symbol         = Symbol,
                Digits         = Digits,
                LotSize        = LotSize,
                Spread         = Spread,
                StopLevel      = StopLevel,
                SwapLong       = SwapLong,
                SwapShort      = SwapShort,
                TickValue      = TickValue,
                MinLot         = MinLot,
                MaxLot         = MaxLot,
                LotStep        = LotStep,
                MarginRequired = MarginRequired
            };


            return(copy);
        }
コード例 #7
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;
        }
コード例 #8
0
        /// <summary>
        /// Clones the Instrument_Properties.
        /// </summary>
        public InstrumentProperties Clone()
        {
            var copy = new InstrumentProperties(Symbol)
                           {
                               Symbol = Symbol,
                               Digits = Digits,
                               LotSize = LotSize,
                               Spread = Spread,
                               StopLevel = StopLevel,
                               SwapLong = SwapLong,
                               SwapShort = SwapShort,
                               TickValue = TickValue,
                               MinLot = MinLot,
                               MaxLot = MaxLot,
                               LotStep = LotStep,
                               MarginRequired = MarginRequired
                           };

            return copy;
        }
コード例 #9
0
 /// <summary>
 ///     Clones the Instrument_Properties.
 /// </summary>
 public InstrumentProperties Clone()
 {
     var copy = new InstrumentProperties(Symbol, InstrType)
         {
             Symbol = Symbol,
             InstrType = InstrType,
             Comment = Comment,
             Digits = Digits,
             LotSize = LotSize,
             Spread = Spread,
             SwapUnit = SwapUnit,
             SwapLong = SwapLong,
             SwapShort = SwapShort,
             CommissionUnit = CommissionUnit,
             CommissionScope = CommissionScope,
             CommissionTime = CommissionTime,
             Commission = Commission,
             PriceIn = PriceIn,
             Slippage = Slippage,
             RateToEUR = RateToEUR,
             RateToUSD = RateToUSD,
             BaseFileName = BaseFileName
         };
     return copy;
 }
コード例 #10
0
        /// <summary>
        ///     Generates instrument.xml file.
        /// </summary>
        private static XmlDocument GenerateXmlFile()
        {
            // Create the XmlDocument.
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<fsb></fsb>");

            // Create the XML declaration.
            XmlDeclaration xmldecl = xmlDoc.CreateXmlDeclaration("1.0", null, null);

            // Add new node to the document.
            XmlElement root = xmlDoc.DocumentElement;

            xmlDoc.InsertBefore(xmldecl, root);

            foreach (var kvp in dictInstrument)
            {
                InstrumentProperties instrProp = kvp.Value;

                // Creates an instrument element.
                XmlElement instrument = xmlDoc.CreateElement("instrument");

                XmlElement element = xmlDoc.CreateElement("symbol");
                element.InnerText = instrProp.Symbol;
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("instrumentType");
                element.InnerText = instrProp.InstrType.ToString();
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("comment");
                element.InnerText = instrProp.Comment;
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("digits");
                element.InnerText = instrProp.Digits.ToString(CultureInfo.InvariantCulture);
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("contractSize");
                element.InnerText = instrProp.LotSize.ToString(CultureInfo.InvariantCulture);
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("spread");
                element.InnerText = instrProp.Spread.ToString(CultureInfo.InvariantCulture);
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("swapType");
                element.InnerText = instrProp.SwapUnit.ToString();
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("swapLong");
                element.InnerText = instrProp.SwapLong.ToString(CultureInfo.InvariantCulture);
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("swapShort");
                element.InnerText = instrProp.SwapShort.ToString(CultureInfo.InvariantCulture);
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("commissionType");
                element.InnerText = instrProp.CommissionUnit.ToString();
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("commissionScope");
                element.InnerText = instrProp.CommissionScope.ToString();
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("commissionTime");
                element.InnerText = instrProp.CommissionTime.ToString();
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("commission");
                element.InnerText = instrProp.Commission.ToString(CultureInfo.InvariantCulture);
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("slippage");
                element.InnerText = instrProp.Slippage.ToString(CultureInfo.InvariantCulture);
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("priceIn");
                element.InnerText = instrProp.PriceIn;
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("rateToUSD");
                element.InnerText = instrProp.RateToUSD.ToString("F4");
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("rateToEUR");
                element.InnerText = instrProp.RateToEUR.ToString("F4");
                instrument.AppendChild(element);

                element           = xmlDoc.CreateElement("baseFileName");
                element.InnerText = instrProp.BaseFileName;
                instrument.AppendChild(element);

                if (xmlDoc.DocumentElement != null)
                {
                    xmlDoc.DocumentElement.AppendChild(instrument);
                }
            }

            return(xmlDoc);
        }
コード例 #11
0
        /// <summary>
        ///     Parses the instruments file.
        /// </summary>
        private static void ParseInstruments()
        {
            int instrumentsCount = XmlInstruments.GetElementsByTagName("instrument").Count;
            dictInstrument = new Dictionary<string, InstrumentProperties>(instrumentsCount);

            try
            {
                foreach (XmlNode nodeInstr in XmlInstruments.GetElementsByTagName("instrument"))
                {
                    string symbol = nodeInstr.SelectSingleNode("symbol").InnerText;
                    var instrType =
                        (InstrumetType)
                        Enum.Parse(typeof (InstrumetType), nodeInstr.SelectSingleNode("instrumentType").InnerText);
                    var instrProp = new InstrumentProperties(symbol, instrType)
                        {
                            Comment = nodeInstr.SelectSingleNode("comment").InnerText,
                            Digits = int.Parse(nodeInstr.SelectSingleNode("digits").InnerText),
                            LotSize = int.Parse(nodeInstr.SelectSingleNode("contractSize").InnerText),
                            Spread = StringToFloat(nodeInstr.SelectSingleNode("spread").InnerText),
                            SwapUnit = ParseChargeUnit(nodeInstr.SelectSingleNode("swapType").InnerText),
                            SwapLong = StringToFloat(nodeInstr.SelectSingleNode("swapLong").InnerText),
                            SwapShort = StringToFloat(nodeInstr.SelectSingleNode("swapShort").InnerText),
                            CommissionUnit = ParseChargeUnit(nodeInstr.SelectSingleNode("commissionType").InnerText),
                            CommissionScope =
                                (CommissionScope)
                                Enum.Parse(typeof (CommissionScope),
                                           nodeInstr.SelectSingleNode("commissionScope").InnerText),
                            CommissionTime =
                                (CommissionTime)
                                Enum.Parse(typeof (CommissionTime),
                                           nodeInstr.SelectSingleNode("commissionTime").InnerText),
                            Commission = StringToFloat(nodeInstr.SelectSingleNode("commission").InnerText),
                            Slippage = int.Parse(nodeInstr.SelectSingleNode("slippage").InnerText),
                            PriceIn = nodeInstr.SelectSingleNode("priceIn").InnerText,
                            RateToUSD = StringToFloat(nodeInstr.SelectSingleNode("rateToUSD").InnerText),
                            RateToEUR = StringToFloat(nodeInstr.SelectSingleNode("rateToEUR").InnerText),
                            BaseFileName = nodeInstr.SelectSingleNode("baseFileName").InnerText
                        };
                    dictInstrument.Add(symbol, instrProp);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Parsing Instruments");
            }
        }
コード例 #12
0
        /// <summary>
        ///     The lbxInstruments selected index changed
        /// </summary>
        private void LbxInstrumentsSelectedValueChanged(object sender, EventArgs e)
        {
            if (LbxInstruments.SelectedItem == null) return;

            instrPropSelectedInstrument = Instruments.InstrumentList[LbxInstruments.SelectedItem.ToString()].Clone();
            SetPropertiesForm();
        }
コード例 #13
0
 /// <summary>
 ///     BtnAdd Clicked.
 /// </summary>
 private void BtnAddInstrAddClick(object sender, EventArgs e)
 {
     if (
         ValidateSymbol(TbxAddInstrSymbol.Text,
                        (InstrumetType) Enum.Parse(typeof (InstrumetType), CbxAddInstrType.Text)) &&
         !LbxInstruments.Items.Contains(TbxAddInstrSymbol.Text))
     {
         instrPropSelectedInstrument = new InstrumentProperties(TbxAddInstrSymbol.Text,
                                                                (InstrumetType)
                                                                Enum.Parse(typeof (InstrumetType),
                                                                           CbxAddInstrType.Text));
         SetPropertiesForm();
         SetSelectedInstrument();
     }
     else
     {
         MessageBox.Show(Language.T("Wrong Symbol!"), Language.T("Instrument Properties"), MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
     }
 }
コード例 #14
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Instrument(InstrumentProperties instrProperties, int iPeriod)
 {
     _instrProperties = instrProperties;
     _period          = iPeriod;
 }
コード例 #15
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Instrument(InstrumentProperties instrProperties, int iPeriod)
 {
     _instrProperties = instrProperties;
     _period = iPeriod;
 }