Clone() public method

Clones the Instrument_Properties.
public Clone ( ) : Instrument_Properties
return Instrument_Properties
        /// <summary>
        /// BtnAccept Clicked.
        /// </summary>
        void BtnAccept_Click(object sender, EventArgs e)
        {
            if (ValidatePropertiesForm())
            {
                SetSelectedInstrument();
                if (Instruments.InstrumentList.ContainsKey(instrPropSelectedInstrument.Symbol))
                {   // The instrument exists. We change it.
                    Instruments.InstrumentList[instrPropSelectedInstrument.Symbol] = instrPropSelectedInstrument.Clone();
                }
                else
                {   // The instrument doesn't exist. We create it.
                    Instruments.InstrumentList.Add(instrPropSelectedInstrument.Symbol, instrPropSelectedInstrument.Clone());
                    lbxInstruments.Items.Add(instrPropSelectedInstrument.Symbol);
                    bNeedReset = true;
                }
            }

            return;
        }
Beispiel #2
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);
        }