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 |
-no value-
using System; using System.Collections; using System.Collections.Generic; using System.Text; using QuantConnect.Securities; using QuantConnect.Models; namespace QuantConnect { //Basic Template using a Tick Condenser Class public class QCUFiveMinuteBars : QCAlgorithm, IAlgorithm { //Use our new consolidator class - 5 minutes / 5 bars joined. public Consolidator barConsolidator = new Consolidator(5); //Initialize the data and resolution you require for your strategy: public override void Initialize() { SetStartDate(2016, 03, 23); SetEndDate(2016, 03, 25); SetCash(25000); AddSecurity(SecurityType.Equity, "MSFT", Resolution.Minute); //SetRunMode(RunMode.Automatic); } //Handle TradeBar Events: a TradeBar occurs on every time-interval //public override void OnTradeBar(Dictionary<string, TradeBar> data) public virtual void OnTradeBar(Dictionary<string, TradeBar> data) { //Add this 1 min to the Consolidator. if (!barConsolidator.Update(data["MSFT"])) return; //Once we have 5 bars it returns true, and we fetch the bar here: TradeBar msft = barConsolidator.Bar; //Now we can use the 5 min bar: //if (!Portfolio.HoldStock) { Order("MSFT", 1); //Debug("Long 100 Microsoft Stock: " + msft.Time); Debug("OHLCV:"+msft.Open+","+msft.High+","+msft.Low+","+msft.Close+","+msft.Volume); //} } } }
using System; using System.Collections; using System.Collections.Generic; using QuantConnect.Securities; using QuantConnect.Models; namespace QuantConnect { public class Consolidator { private int requestedCount = 0; private int barCount = 0; private Queue<TradeBar> barQueue; //Accessor - Create the x-"Bar" when the Update returns true. public TradeBar Bar { get { return this.Generate(); } } //Initialize the Consolidator public Consolidator(int iBars) { //Number of TradeBars we want to join together (e.g. 5 min bars = 5 x 1 min bars) this.requestedCount = iBars; this.barCount = 0; // Queue to store the bars temporarily. this.barQueue = new Queue<TradeBar>(barCount); } // Add a bar to the list, when it totals X bars return a new tradebar. public bool Update(TradeBar bar) { //Add this bar to the queue: barQueue.Enqueue(bar); //Use a counter to speed up the counting. barCount++; if (barCount == requestedCount) { return true; } else { return false; } } //Using the barQueue generate a new "consolidated bar" then return private TradeBar Generate() { string symbol = ""; long volume = 0; DateTime barOpenTime = new DateTime(); decimal open = Decimal.Zero, high = Decimal.MinValue, low = Decimal.MaxValue, close = Decimal.Zero; //Create the new bar: while(barCount > 0) { TradeBar bar = barQueue.Dequeue(); if (barOpenTime == new DateTime()) barOpenTime = bar.Time; if (symbol == "") symbol = bar.Symbol; if (open == Decimal.Zero) open = bar.Open; if (high < bar.High) high = bar.High; if (low > bar.Low) low = bar.Low; close = bar.Close; volume = bar.Volume; barCount--; } //Reset ready for next bar: barQueue.Clear(); //Create the new trade bar. return new TradeBar(barOpenTime, symbol, open, high, low, close, volume); } } }