Contains the instrument properties.
Esempio n. 1
0
        /// <summary>
        /// Clones the Instrument_Properties.
        /// </summary>
        public Instrument_Properties Clone()
        {
            Instrument_Properties copy = new Instrument_Properties(symbol, instrType);

            copy.Symbol          = Symbol;
            copy.InstrType       = InstrType;
            copy.Comment         = Comment;
            copy.Digits          = Digits;
            copy.LotSize         = LotSize;
            copy.Spread          = Spread;
            copy.SwapType        = SwapType;
            copy.SwapLong        = SwapLong;
            copy.SwapShort       = SwapShort;
            copy.CommissionType  = CommissionType;
            copy.CommissionScope = CommissionScope;
            copy.CommissionTime  = CommissionTime;
            copy.Commission      = Commission;
            copy.PriceIn         = PriceIn;
            copy.Slippage        = Slippage;
            copy.RateToEUR       = RateToEUR;
            copy.RateToUSD       = RateToUSD;
            copy.BaseFileName    = BaseFileName;

            return(copy);
        }
        /// <summary>
        /// Button Default Click
        /// <summary>
        void BtnDefault_Click(object sender, EventArgs e)
        {
            Instrument_Properties ip = new Instrument_Properties(Data.InstrProperties.Symbol, Data.InstrProperties.InstrType);

            nudSpread.Value     = (decimal)ip.Spread;
            nudSwapLong.Value   = (decimal)ip.SwapLong;
            nudSwapShort.Value  = (decimal)ip.SwapShort;
            nudSlippage.Value   = (decimal)ip.Slippage;
            nudCommission.Value = (decimal)ip.Commission;

            return;
        }
        /// <summary>
        /// The lbxInstruments selected index changed
        /// </summary>
        void LbxInstruments_SelectedValueChanged(object sender, EventArgs e)
        {
            if (lbxInstruments.SelectedItem == null)
            {
                return;
            }

            instrPropSelectedInstrument = Instruments.InstrumentList[lbxInstruments.SelectedItem.ToString()].Clone();
            SetPropertiesForm();

            return;
        }
        /// <summary>
        /// BtnAdd Clicked.
        /// </summary>
        void BtnAddInstrAdd_Click(object sender, EventArgs e)
        {
            if (ValidateSymbol(tbxAddInstrSymbol.Text, (Instrumet_Type)Enum.Parse(typeof(Instrumet_Type), cbxAddInstrType.Text)) &&
                !lbxInstruments.Items.Contains(tbxAddInstrSymbol.Text))
            {
                instrPropSelectedInstrument = new Instrument_Properties(tbxAddInstrSymbol.Text, (Instrumet_Type)Enum.Parse(typeof(Instrumet_Type), cbxAddInstrType.Text));
                SetPropertiesForm();
                SetSelectedInstrument();
            }
            else
            {
                MessageBox.Show(Language.T("Wrong Symbol!"), Language.T("Instrument Properties"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return;
        }
Esempio n. 5
0
        /// <summary>
        /// Parses the instruments file.
        /// </summary>
        static void ParseInstruments()
        {
            int instrumentsCount = xmlInstruments.GetElementsByTagName("instrument").Count;

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

            try
            {
                foreach (XmlNode nodeInstr in xmlInstruments.GetElementsByTagName("instrument"))
                {
                    string                symbol    = nodeInstr.SelectSingleNode("symbol").InnerText;
                    Instrumet_Type        instrType = (Instrumet_Type)Enum.Parse(typeof(Instrumet_Type), nodeInstr.SelectSingleNode("instrumentType").InnerText);
                    Instrument_Properties instrProp = new Instrument_Properties(symbol, instrType);
                    instrProp.Comment         = nodeInstr.SelectSingleNode("comment").InnerText;
                    instrProp.Digits          = int.Parse(nodeInstr.SelectSingleNode("digits").InnerText);
                    instrProp.LotSize         = int.Parse(nodeInstr.SelectSingleNode("contractSize").InnerText);
                    instrProp.Spread          = StringToFloat(nodeInstr.SelectSingleNode("spread").InnerText);
                    instrProp.SwapType        = (Commission_Type)Enum.Parse(typeof(Commission_Type), nodeInstr.SelectSingleNode("swapType").InnerText);
                    instrProp.SwapLong        = StringToFloat(nodeInstr.SelectSingleNode("swapLong").InnerText);
                    instrProp.SwapShort       = StringToFloat(nodeInstr.SelectSingleNode("swapShort").InnerText);
                    instrProp.CommissionType  = (Commission_Type)Enum.Parse(typeof(Commission_Type), nodeInstr.SelectSingleNode("commissionType").InnerText);
                    instrProp.CommissionScope = (Commission_Scope)Enum.Parse(typeof(Commission_Scope), nodeInstr.SelectSingleNode("commissionScope").InnerText);
                    instrProp.CommissionTime  = (Commission_Time)Enum.Parse(typeof(Commission_Time), nodeInstr.SelectSingleNode("commissionTime").InnerText);
                    instrProp.Commission      = StringToFloat(nodeInstr.SelectSingleNode("commission").InnerText);
                    instrProp.Slippage        = int.Parse(nodeInstr.SelectSingleNode("slippage").InnerText);
                    instrProp.PriceIn         = nodeInstr.SelectSingleNode("priceIn").InnerText;
                    instrProp.RateToUSD       = StringToFloat(nodeInstr.SelectSingleNode("rateToUSD").InnerText);
                    instrProp.RateToEUR       = StringToFloat(nodeInstr.SelectSingleNode("rateToEUR").InnerText);
                    instrProp.BaseFileName    = nodeInstr.SelectSingleNode("baseFileName").InnerText;
                    dictInstrument.Add(symbol, instrProp);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message, "Parsing Instruments");
            }
        }
Esempio n. 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);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public Instrument(Instrument_Properties instrProperties, int period)
 {
     this.instrProperties = instrProperties;
     this.period = period;
 }
        /// <summary>
        /// The lbxInstruments selected index changed
        /// </summary>
        void LbxInstruments_SelectedValueChanged(object sender, EventArgs e)
        {
            if (lbxInstruments.SelectedItem == null) return;

            instrPropSelectedInstrument = Instruments.InstrumentList[lbxInstruments.SelectedItem.ToString()].Clone();
            SetPropertiesForm();

            return;
        }
        /// <summary>
        /// BtnAdd Clicked.
        /// </summary>
        void BtnAddInstrAdd_Click(object sender, EventArgs e)
        {
            if (ValidateSymbol(tbxAddInstrSymbol.Text, (Instrumet_Type)Enum.Parse(typeof(Instrumet_Type), cbxAddInstrType.Text)) &&
                !lbxInstruments.Items.Contains(tbxAddInstrSymbol.Text))
            {
                instrPropSelectedInstrument = new Instrument_Properties(tbxAddInstrSymbol.Text, (Instrumet_Type)Enum.Parse(typeof(Instrumet_Type), cbxAddInstrType.Text));
                SetPropertiesForm();
                SetSelectedInstrument();
            }
            else
            {
                MessageBox.Show(Language.T("Wrong Symbol!"), Language.T("Instrument Properties"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return;
        }
        /// <summary>
        /// Clones the Instrument_Properties.
        /// </summary>
        public Instrument_Properties Clone()
        {
            Instrument_Properties copy = new Instrument_Properties(symbol, instrType);

            copy.Symbol          = Symbol;
            copy.InstrType       = InstrType;
            copy.Comment         = Comment;
            copy.Digits          = Digits;
            copy.LotSize         = LotSize;
            copy.Spread          = Spread;
            copy.SwapType        = SwapType;
            copy.SwapLong        = SwapLong;
            copy.SwapShort       = SwapShort;
            copy.CommissionType  = CommissionType;
            copy.CommissionScope = CommissionScope;
            copy.CommissionTime  = CommissionTime;
            copy.Commission      = Commission;
            copy.PriceIn         = PriceIn;
            copy.Slippage        = Slippage;
            copy.RateToEUR       = RateToEUR;
            copy.RateToUSD       = RateToUSD;
            copy.BaseFileName    = BaseFileName;

            return copy;
        }
Esempio n. 11
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Instrument(Instrument_Properties instrProperties, int period)
 {
     this.instrProperties = instrProperties;
     this.period          = period;
 }
Esempio n. 12
0
        /// <summary>
        /// Generates instrument.xml file.
        /// </summary>
        static XmlDocument GenerateXMLFile()
        {
            // Create the XmlDocument.
            XmlDocument xmlDoc = new XmlDocument();

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

            //Create the XML declaration.
            XmlDeclaration xmldecl;

            xmldecl = xmlDoc.CreateXmlDeclaration("1.0", null, null);

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

            xmlDoc.InsertBefore(xmldecl, root);

            foreach (KeyValuePair <string, Instrument_Properties> kvp in dictInstrument)
            {
                Instrument_Properties instrProp = kvp.Value;

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

                XmlElement element;

                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();
                instrument.AppendChild(element);

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

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

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

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

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

                element           = xmlDoc.CreateElement("commissionType");
                element.InnerText = instrProp.CommissionType.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();
                instrument.AppendChild(element);

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

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

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

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

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

                xmlDoc.DocumentElement.AppendChild(instrument);
            }

            return(xmlDoc);
        }
        /// <summary>
        /// Button Default Click
        /// <summary>
        void BtnDefault_Click(object sender, EventArgs e)
        {
            Instrument_Properties ip = new Instrument_Properties(Data.InstrProperties.Symbol, Data.InstrProperties.InstrType);

            nudSpread.Value     = (decimal)ip.Spread;
            nudSwapLong.Value   = (decimal)ip.SwapLong;
            nudSwapShort.Value  = (decimal)ip.SwapShort;
            nudSlippage.Value   = (decimal)ip.Slippage;
            nudCommission.Value = (decimal)ip.Commission;

            return;
        }