Overall Statistics |
Total Trades 1 Average Win 1.35% Average Loss 0.00% Annual Return 2.866% Drawdown 1.000% Expectancy 0.000 Net Profit 1.354% Sharpe Ratio 1.4 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Trade Frequency Weekly trades |
-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(2014, 01, 01); SetEndDate(2014, 04, 30); SetCash(25000); AddSecurity(SecurityType.Equity, "MSFT", Resolution.Minute); SetRunMode(RunMode.Series); } //Handle TradeBar Events: a TradeBar occurs on every time-interval public override void OnTradeBar(Dictionary<string, TradeBar> data) { if (!barConsolidator.Update(data["MSFT"])) return; TradeBar msft = barConsolidator.Bar; if (!Portfolio.HoldStock) { Log("Time: " + msft.Time); Order("MSFT", 100); } } } }
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); } } }