Overall Statistics
using QuantConnect.Data.Consolidators;

namespace QuantConnect 
{   
    /*
    *   QuantConnect University: FOREX - Using Currency Data
    *
    *   QuantConnect allows you to use currency data for your backtest with a 
    *   simple line of code. See the SecurityType.Forex below.
    */
    
    
    public class FOREXBasicTemplateAlgorithm : QCAlgorithm
    {
        BollingerBands _bb;
        //Use our new consolidator class - 15 minutes / 15 bars joined.
        decimal _price;
        
        public override void Initialize()
        {
            SetStartDate(2015, 1, 4);         
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(2000);
            AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Minute);
            _bb = BB("EURUSD", 20, 1, MovingAverageType.Simple);
            var fifteenConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15));

            fifteenConsolidator.DataConsolidated += OnDataFifteen;
            SubscriptionManager.AddConsolidator("EURUSD",fifteenConsolidator);
            RegisterIndicator("EURUSD", _bb, fifteenConsolidator, x => x.Value);
  
        }

        public void OnData(TradeBars data) 
        {   
            if (!_bb.IsReady) return;
            
            TradeBar EURUSD = data["EURUSD"];

            if (!Portfolio.HoldStock) 
            {
                Order("EURUSD", 1000);
                Debug("Purchased EURUSD on " + Time.ToShortDateString());
            }
        }
        
        private void OnDataFifteen(object sender,TradeBar consolidated)
        {

            _price = consolidated.Close;

            Plot("BB", "Price", _price);
            Plot("BB", _bb.UpperBand, _bb.MiddleBand, _bb.LowerBand);            
        }
        
        // Fire plotting events once per day:
        public override void OnEndOfDay() 
        {
            Log("EndOfDay");
        }

    }
}