Overall Statistics
Total Trades
0
Average Win
0.00%
Average Loss
0.00%
Annual Return
0.000%
Drawdown
0%
Expectancy
0.000
Net Profit
0.000%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Trade Frequency
Daily trades
using System;
using System.Collections;
using System.Collections.Generic; 
using QuantConnect.Securities;  
using QuantConnect.Models;   

namespace QuantConnect { 
    
    public class QCUDailyBars : QCAlgorithm
    {
        string symbol = "SPY";
        Consolidator joiner = new Consolidator("SPY");
        
        public override void Initialize()
        {
            SetStartDate(2014, 5, 1);
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(25000); //Starting Cash in USD.
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
            SetRunMode(RunMode.Series);
        }
        
        public override void OnTradeBar(Dictionary<string, TradeBar> data) 
        {   
            joiner.AddSample( data["SPY"] );
            if (!joiner.Ready) return;
            TradeBar SPY_Day = joiner.Bar;
            
            //If code reaches here - its end of day: joiner.Bar is output saved to SPY_Day;
            Debug(SPY_Day.Time.ToString() + "," + SPY_Day.Open.ToString("C") + "," + SPY_Day.High.ToString("C") + "," + SPY_Day.Low.ToString("C") + "," + SPY_Day.Close.ToString("C"));
        }
    }
    
    
    /*
    *   Simplified generic bar consolidator:
    */
    public class Consolidator {
        
        private TradeBar _lastBar = new TradeBar();
        private string _symbol = "";
        private decimal _open = 0, _close = 0;
        private decimal _high = Decimal.MinValue;
        private decimal _low = Decimal.MaxValue;
        private long _volume = 0;
        
        public Consolidator(string symbol) {
            _symbol = symbol;
        }
        
        //Return true when tradebar ready i.e. at 15:59, or whatever function you want:
        public bool Ready {
            get {
                return (_lastBar.Time.Hour == 15 && _lastBar.Time.Minute == 59);
            }
        }
        
        //Output TradeBar:
        public TradeBar Bar {
            get {
                TradeBar x = new TradeBar(_lastBar.Time, _symbol, _open, _high, _low, _close, _volume);
                _open = 0; _close = 0; _volume = 0; _low = Decimal.MaxValue; _high = Decimal.MinValue;
                return x;
            }
        }
        
        public void AddSample(TradeBar bar) {
            if (_open == 0) _open = bar.Open;
            if (_high < bar.High) _high = bar.High;
            if (_low > bar.Low) _low = bar.Low;
            _close = bar.Close;
            _volume = bar.Volume;
            _lastBar = bar;
        }
    }
}