Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
using System;
using System.Linq;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Data;
using QuantConnect.Brokerages;
using QuantConnect.Data.Consolidators;

namespace QuantConnect.Algorithm.CSharp
{
    public class TestAlgorithm : QCAlgorithm
    {
        private SimpleMovingAverage spyMovingAverage;

        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        public override void Initialize()
        {
            //Set trading window
            SetStartDate(year: 2013, month: 10, day: 1);
            SetEndDate(year: 2013, month: 10, day: 8);
            //SetEndDate(DateTime.Now);

            var benchmark = AddEquity("SPY");
            SetBenchmark(benchmark.Symbol);
            //SetBenchmark(d => 1m);

            //Set brokermodel
            SetCash(100000);
            SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);

            //Set moving average
            var spy = AddEquity("SPY", Resolution.Minute);

            //var consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(30));
            //consolidator.DataConsolidated += OnTradeBarDataConsolidated;
            //SubscriptionManager.AddConsolidator("SPY", consolidator);

            spyMovingAverage = SMA(spy.Symbol, 60, Resolution.Minute);
            
           // RegisterIndicator("SPY", spyMovingAverage, consolidator);

            PlotIndicator("SPY", spyMovingAverage);

        }

        public void OnData(TradeBars data)
        {
            Plot("SPY", "Price", Securities["SPY"].Close);

            Plot("SPY", spyMovingAverage);
            Log(string.Format("{0}, {1}", Securities["SPY"].Price, spyMovingAverage));

            if (IsWarmingUp)
            {
                //Log("IsWarmingUp");
                return;
            }
            if (!spyMovingAverage.IsReady)
            {
                return;
            }

            if (spyMovingAverage == 0)
            {
                Log("spyMovingAverage == 0");
            }
        }
    }
}