示例#1
0
        public override void Initialize()
        {
            SetStartDate(2015, 6, 26);
            SetEndDate(2015, 7, 2);
            SetCash(25000);

            AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute);

            // define our 15 minute consolidator
            var fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15));

            // if we want to make decisions every 15 minutes as well, we can add an event handler
            // to the DataConsolidated event
            fifteenMinuteConsolidator.DataConsolidated += OnFiftenMinuteSPY;

            int fast = 15;
            int slow = 30;

            // define our EMA, we'll manually register this, so we aren't using the helper function 'EMA(...)'
            var fastEmaOnFifteenMinuteBars = new ExponentialMovingAverage("SPY_EMA15", fast);
            var slowEmaOnFifteenMinuteBars = new ExponentialMovingAverage("SPY_EMA30", slow);

            // we can define complex indicator's using various extension methods.
            // here I use the 'Over' extension method which performs division
            // so this will be fast/slow. This returns a new indicator that represents
            // the division operation between the two
            var ratio = fastEmaOnFifteenMinuteBars.Over(slowEmaOnFifteenMinuteBars, "SPY_Ratio_EMA");

            // now we can use the 'Of' extension method to define the ROC on the ratio
            // The 'Of' extension method allows combining multiple indicators together such
            // that the data from one gets sent into the other
            var rocpOfRatio = new RateOfChangePercent("SPY_ROCP_Ratio", fast).Of(ratio);

            // we an even define a smoothed version of this indicator
            var smoothedRocpOfRatio = new ExponentialMovingAverage("SPY_Smoothed_ROCP_Ratio", 5).Of(rocpOfRatio);

            // register our indicator and consolidator together. this will wire the consolidator up to receive
            // data for the specified symbol, and also set up the indicator to receive its data from the consolidator
            RegisterIndicator("SPY", fastEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close);
            RegisterIndicator("SPY", slowEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close);

            // register the indicator to be plotted along
            PlotIndicator("SPY", fastEmaOnFifteenMinuteBars);
            PlotIndicator("SPY", slowEmaOnFifteenMinuteBars);
            PlotIndicator("SPY_ROCP_Ratio", rocpOfRatio, smoothedRocpOfRatio);
            PlotIndicator("SPY_Ratio_EMA", ratio);
        }
示例#2
0
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
            SetStartDate(2000, 01, 01);
            SetEndDate(2004, 01, 01);
            SetCash(25000);
            AddSecurity(SecurityType.Equity, symbol, Resolution.Daily);
            var shortval = Config.GetInt("EMA_VAR1", 10);
            var longval  = Config.GetInt("EMA_VAR2", 50);

            emaShort = EMA(symbol, shortval, Resolution.Daily);
            emaLong  = EMA(symbol, longval, Resolution.Daily);
            for (int i = 0; i < MAXRETURNS; i++)
            {
                _tradeReturns.Add(0);
            }
            startTime = DateTime.Now;
        }
        /// <summary>
        /// Called at the start of your algorithm to setup your requirements:
        /// </summary>
        public override void Initialize()
        {
            //Set the date range you want to run your algorithm:
            SetStartDate(1998, 1, 1);
            SetEndDate(DateTime.Today.AddDays(-1));

            //Set the starting cash for your strategy:
            SetCash(100000);

            //Add any stocks you'd like to analyse, and set the resolution:
            // Find more symbols here: http://quantconnect.com/data
            AddSecurity(SecurityType.Equity, "SPY", resolution: Resolution.Minute);

            //EMA Average Trackers:
            emaShort = new ExponentialMovingAverage(10);
            emaLong  = new ExponentialMovingAverage(50);
        }
        /// <summary>
        /// Called at the start of your algorithm to setup your requirements:
        /// </summary>
        public override void Initialize()
        {
            //Set the date range you want to run your algorithm:
            SetStartDate(1998, 1, 1);
            SetEndDate(DateTime.Today.AddDays(-1));

            //Set the starting cash for your strategy:
            SetCash(100000);

            //Add any stocks you'd like to analyse, and set the resolution:
            // Find more symbols here: http://quantconnect.com/data
            AddSecurity(SecurityType.Equity, "SPY", resolution: Resolution.Minute);

            //EMA Average Trackers:
            emaShort = new ExponentialMovingAverage(10);
            emaLong = new ExponentialMovingAverage(50);
        }
示例#5
0
        public override void Initialize()
        {
            SetStartDate(2013, 10, 7);
            SetEndDate(2013, 10, 11);
            SetCash(250000);

            foreach (var symbol in Symbols)
            {
                AddSecurity(SecurityType.Equity, symbol, Resolution.Second);
                // Define an Identity Indicator with the close price.
                Identity priceIdentityIndicator = new Identity(symbol + "PriceIdentityIndicator");
                RegisterIndicator(symbol, priceIdentityIndicator, Resolution.Second, Field.Close);
                // Define an EMA.
                ExponentialMovingAverage EMA = new ExponentialMovingAverage("EMA_" + symbol, 100);
                RegisterIndicator(symbol, EMA, Resolution.Minute, Field.Close);
                // Inject the Price Identity indicator and the EMA in the Strategy object.
                StrategyDict.Add(symbol, new NoStrategy(symbol, priceIdentityIndicator, EMA));

                stockLogging.Add(symbol, new StringBuilder());
            }
        }