Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio NaN Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha NaN Beta NaN Annual Standard Deviation 0 Annual Variance 0 Information Ratio NaN Tracking Error NaN Treynor Ratio NaN Total Fees $0.00 |
using System; using System.Linq; using QuantConnect.Data.Consolidators; using QuantConnect.Indicators; using QuantConnect.Data.Market; using QuantConnect.Algorithm; using QuantConnect.Data.Custom; namespace QuantConnect { public class KYJIndicators : QCAlgorithm { //string crude = "CME/CLN2015"; string symbol = "SPY"; MovingAverageConvergenceDivergence macd; RelativeStrengthIndex rsi; MoneyFlowIndex mfi; decimal price; TradeBar symbolDaily; //Initialize the data and resolution you require for your strategy: public override void Initialize () { SetStartDate (2015, 5, 18); SetEndDate (2015, 5, 21); SetCash (25000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity (SecurityType.Equity, symbol, Resolution.Minute, fillDataForward: false); //AddData<QuandlFuture> (crude, Resolution.Daily); //Set up Indicators macd = MACD (symbol, 12, 26, 9, MovingAverageType.Simple, Resolution.Minute); rsi = RSI (symbol, 14, MovingAverageType.Simple, Resolution.Minute); mfi = MFI (symbol, 14, Resolution.Minute); //Setup Consolidators // define our daily trade bar consolidator. we can access the daily bar // from the DataConsolidated events var dailyConsolidator = new TradeBarConsolidator (TimeSpan.FromDays (1)); // attach our event handler. the event handler is a function that will be called // each time we produce a new consolidated piece of data dailyConsolidator.DataConsolidated += OnDataDaily; // this call adds our daily consolidator to the manager to receive updates // from the engine SubscriptionManager.AddConsolidator (symbol, dailyConsolidator); } public void OnDataDaily (object sender, TradeBar consolidated) { symbolDaily = consolidated; Log(Time.ToString("u") + " Close price: " + consolidated.Close); } //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. //public void OnData (Quandl data) public void OnData (TradeBars data) { /* if (!macd.IsReady || !rsi.IsReady || !mfi.IsReady) { return; } */ decimal macdLine = macd.Fast - macd.Slow; decimal macdHistogram = Math.Round(macdLine - macd.Signal,3); price = Math.Round(data[symbol].Close, 3); // MFI not working (always 100) if (!Portfolio.Invested && (rsi < 30) ) { SetHoldings (symbol, 0.75); Log (Time.ToString ("u") + " Purchased: " + symbol + " price = " + price + " MACDHis = " + macdHistogram + " RSI = " + rsi + " MFI = " + mfi); } else if (Portfolio.Invested && (rsi > 70) ) { Liquidate (symbol); Log (Time.ToString ("u") + " Sold: " + symbol + " price = " + price + " MACDHis = " + macdHistogram + " RSI = " + rsi + " MFI = " + mfi); } } // Fire plotting events once per day: public override void OnEndOfDay (string symbol) { /* if (!macd.IsReady || !rsi.IsReady || !mfi.IsReady) { return; } */ //Plot("MACD", "Price", price); //Plot("MACD", macd.Fast, macd.Slow); Plot ("RSI", "rsi", rsi); Plot ("RSI", "price", price); //Plot ("MFI", mfi); } } // Custom quandl data type for setting customized value column name. // Value column is used for the primary trading calculations and charting. public class QuandlFuture : Quandl { public QuandlFuture () : base (valueColumnName: "Settle") { } } }