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.Drawing; // for Color namespace QuantConnect { public class ExampleStochasticChartingAlgorithm : QCAlgorithm { TradeBars prices = new TradeBars(); Stochastic sto; String _symbol = "XIV"; String _plotter = "Stochastic"; int overBought = 20; int overSold = 80; private DateTime _currentTime; private DateTime _LastSampleTime; public override void Initialize() { SetStartDate(2016, 8, 25); SetEndDate(2017, 1, 19); int KPeriod = 14; int DPeriod = 5; AddSecurity(SecurityType.Equity, _symbol, Resolution.Daily); //https://github.com/QuantConnect/Lean/blob/master/Algorithm/QCAlgorithm.Indicators.cs#L530 sto = STO(_symbol,14,KPeriod,DPeriod,Resolution.Daily); //Warmup Time SetWarmUp(TimeSpan.FromDays(15)); //Charting in https://github.com/QuantConnect/Lean/blob/master/Common/Charting.cs Chart plotter = new Chart(_plotter); plotter.AddSeries(new Series("D", SeriesType.Line, " ",Color.Red)); plotter.AddSeries(new Series("K", SeriesType.Line, " ",Color.Blue)); plotter.AddSeries(new Series("Over Bought", SeriesType.Line, " ",Color.Black)); //plotter.AddSeries(new Series("Over Sold", SeriesType.Line, " ",Color.Black)); AddChart(plotter); Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromMinutes(10)), () => { Log("STO Values: " + sto.StochD + ", " + sto.StochK); }); } //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. public void OnData(TradeBars data) { // Access current tradebar data. TradeBar dataBar = data[_symbol]; _currentTime = dataBar.Time; // If warming up... if (IsWarmingUp) { // Feed the stochastic even on warming up. if (_LastSampleTime.Minute != dataBar.Time.Minute) { Log("WARMUP - Stochastic.Update(): Fired at: " + dataBar.Time); sto.Update(dataBar); } // Update Sample TimeStamp _LastSampleTime = dataBar.Time; // Return until algorithm is ready to execute. return; } if (sto.IsReady) { Plot(_plotter,"D", sto.StochD); Plot(_plotter,"K", sto.StochK); Plot(_plotter,"Over Bought", overBought); Plot(_plotter,"Over Sold", overSold); Plot(_plotter,"XIV Price", dataBar.Price); } } public override void OnEndOfDay() { } } }