private void ConnectorOnScriptingListReceived(object sender, EventArgs <ScriptingReceivedEventArgs> args)
        {
            lock (Indicators)
            {
                Indicators.Clear();

                foreach (var item in args.Value.Indicators.ToList())
                {
                    Indicators.Add(item.Key, item.Value);
                }

                DefaultIndicators.Clear();
                DefaultIndicators.AddRange(args.Value.DefaultIndicators.ToList());
            }

            lock (Signals)
            {
                Signals.Clear();
                foreach (var item in args.Value.Signals)
                {
                    Signals.Add(item);
                }
            }

            ScriptingListUpdated?.Invoke();
        }
 protected void ResetStorys()
 {
     _currentDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");
     StoryDataList.Clear();
     TopStoryList.Clear();
     Indicators.Clear();
 }
Beispiel #3
0
        /// <summary>Remove and dispose all indicators</summary>
        public void Clear()
        {
            // Don't save, the caller should do that if needed
            foreach (var kv in Indicators)
            {
                Util.DisposeAll(kv.Value);
            }

            Indicators.Clear();
            NotifyIndicatorsChanged(NotifyCollectionChangedAction.Reset, null, null);
        }
Beispiel #4
0
        public void Dispose()
        {
            Bots?.Clear();
            Indicators?.Clear();

            MainLoopRunning = false;

            BackTestingChange  -= HandleBackTestingChange;
            AllowTradesChanged -= HandleAllowTradesChanged;

            PriceData = null;
            User      = null;
            Shutdown  = null;
            Util.Dispose(Log);
        }
        public override void Assign(StrategyBase from)
        {
            base.Assign(from);

            CustomTickerStrategy st = from as CustomTickerStrategy;

            if (st == null)
            {
                return;
            }
            StrategyInfo.Assign(st.StrategyInfo);
            Indicators.Clear();
            foreach (IndicatorBase indicator in st.Indicators)
            {
                Indicators.Add(indicator.Clone());
            }
        }
Beispiel #6
0
        private void HandleBackTestingChange(object sender, PrePostEventArgs e)
        {
            // If back testing is about to be enabled...
            if (!BackTesting && e.Before)
            {
                // Turn off the update thread for each exchange
                foreach (var exch in Exchanges)
                {
                    exch.UpdateThreadActive = false;
                }

                // Turn off the update thread for each price data instance
                foreach (var pd in PriceData)
                {
                    pd.UpdateThreadActive = false;
                }

                // Deactivate all live trading bots (actually, deactivate all of them)
                Bots.Clear();

                // Integrate market updates so that updates from live data don't end up in back testing data.
                IntegrateDataUpdates();

                // Save and reset the current Fund container
                Funds.SaveToSettings(Exchanges);
                Funds.AssignFunds(new FundData[0]);

                // Save and reset the indicator container
                Indicators.Save();
                Indicators.Clear();

                // Disable live trading
                AllowTrades = false;
            }

            // If back testing has just been enabled...
            if (BackTesting && e.After)
            {
                // Create the fund container from the back testing settings
                Funds.AssignFunds(SettingsData.Settings.BackTesting.TestFunds);

                // Create the back testing bots
                Bots.LoadFromSettings();

                // Reset the balance collections in each exchange
                foreach (var exch in Exchanges)
                {
                    exch.Balance.Clear();
                }

                // Create the simulation manager
                Simulation = new Simulation(TradingExchanges, PriceData, Bots);

                // Enable backtesting bots based on their settings
                foreach (var bot in Bots.Where(x => x.BackTesting))
                {
                    bot.Active = bot.BotData.Active;
                }

                // Restore the backtesting indicators
                Indicators.Load();
            }

            // If back testing is about to be disabled...
            if (BackTesting && e.Before)
            {
                // Deactivate all back testing bots (actually, deactivate all of them)
                Bots.Clear();

                // Remove (without saving) the current fund container
                Funds.AssignFunds(new FundData[0]);

                // Save and reset the indicator container
                Indicators.Save();
                Indicators.Clear();
            }

            // If back testing has just been disabled...
            if (!BackTesting && e.After)
            {
                // Clean up the simulation
                Simulation = null;

                // Restore the fund container from settings
                Funds.AssignFunds(SettingsData.Settings.LiveFunds);

                // Restore the indicators
                Indicators.Load();

                // Restore the live trading bots
                Bots.LoadFromSettings();

                // Reset the balance collections in each exchange
                foreach (var exch in Exchanges)
                {
                    exch.Balance.Clear();
                }

                // Turn on the update thread for each price data instance
                foreach (var pd in PriceData)
                {
                    pd.UpdateThreadActive = pd.RefCount != 0;
                }

                // Turn on the update thread for each exchange
                foreach (var exch in Exchanges)
                {
                    exch.UpdateThreadActive = exch.Enabled;
                }

                // Enable live trading bots based on their settings
                foreach (var bot in Bots.Where(x => !x.BackTesting))
                {
                    bot.Active = bot.BotData.Active;
                }
            }
        }