Ejemplo n.º 1
0
        public BackTest(BackTestConfiguration _config)
        {
            //set internal vars

            runLength        = _config.runLength;
            maxTradesPerDay  = _config.maxTradesPerDay;
            currencyPair     = _config.currencyPair;
            timeFrame        = _config.timeFrame;
            riskPercent      = _config.riskPercent;
            riskVsReward     = _config.riskVsReward;
            startingBalance  = _config.startingBalance;
            startDate        = _config.startDate;
            connectionString = _config.connectionString;
            //initialize defaults

            profitTrades = default;
            lossTrades   = default;
            totalTrades  = default;
            trade        = default;

            closingPrice      = new List <double>();
            myAccountSettings = new AccountSettings {
                BASEURI = BASEURI, APIKEY = APIKEY, ID = ID
            };

            myAccount   = new AccountAccessor(myAccountSettings);
            instruments = new InstrumentAccessor(myAccountSettings, currencyPair);


            orders = new OrderAccessor(myAccountSettings);
        }
Ejemplo n.º 2
0
        public TradeEngine()
        {
            //create main timer for polling
            mainTimer           = new System.Timers.Timer();
            mainTimer.Interval  = 150000;        //launch polling event every 2.5 minutes
            mainTimer.AutoReset = true;
            mainTimer.Enabled   = true;

            myAccountSettings = new AccountSettings {
                BASEURI = BASEURI, APIKEY = APIKEY, ID = ID
            };

            //initialize default variables
            myAccount = new AccountAccessor(myAccountSettings);
            myAccount.RegisterTimer(mainTimer);

            instruments = new InstrumentAccessor(myAccountSettings, "EUR_USD");
            instruments.RegisterTimer(mainTimer);

            orders = new OrderAccessor(myAccountSettings);

            //OMG, initialize  first object in collection
            SMA50 = new List <IndicatorOverTime>();
            SMA50.Add(new IndicatorOverTime {
                result = Indicators.SMA((instruments.GetBars(50, "M5"))), time = instruments.GetBars(1, "M5").candles[0].time
            });


            trend = new TrendDirection();

            //set because log file is written before trend is actually calculated, so should be sideways until there is enough data to actually determine the trend
            trend = TrendDirection.Sideways;

            tradeEngineLog = new  LogData();

            //write headers to csv
            using (StreamWriter writer = new StreamWriter(outFile))
            {
                CsvWriter csvWriter = new CsvWriter(writer);
                csvWriter.WriteHeader <LogData>();
                csvWriter.NextRecord();
            }



            WriteLog();
            mainTimer.Elapsed += OnUpdate;
        }