Overall Statistics |
Total Trades 36 Average Win 0.07% Average Loss -0.04% Compounding Annual Return -57.646% Drawdown 0.600% Expectancy -0.596 Net Profit -0.518% Sharpe Ratio -17.911 Loss Rate 86% Win Rate 14% Profit-Loss Ratio 1.82 Alpha 0 Beta 0 Annual Standard Deviation 0.024 Annual Variance 0.001 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $72.00 |
-no value-
namespace QuantConnect { public class QCUMovingAverageCross : QCAlgorithm { int quantity = 0; decimal price = 0; decimal tolerance = 0m; //0.1% safety margin in prices to avoid bouncing. string symbol = "EURUSD"; //Set up the EMA Class: ExponentialMovingAverage emaShort; ExponentialMovingAverage emaLong; ExponentialMovingAverage emaShortSecond; ExponentialMovingAverage emaLongSecond; public override void Initialize() { SetStartDate(2014, 1, 1); SetEndDate(2014, 1, 2); SetCash(25000); AddSecurity(SecurityType.Forex, symbol, Resolution.Second); emaShort = EMA(symbol, 10, Resolution.Minute); emaLong = EMA(symbol, 50, Resolution.Minute); emaShortSecond = EMA(symbol, 10*60, Resolution.Second); emaLongSecond = EMA(symbol, 50*60, Resolution.Second); } //Handle TradeBar Events: a TradeBar occurs on every time-interval public void OnData(TradeBars data) { price = Securities[symbol].Close; if (!emaShort.IsReady || !emaLong.IsReady) return; Plot("EMAs","EMAShort",emaShort); Plot("EMAs","EMALong",emaLong); Plot("EMAs","EMAShortSecond",emaShortSecond); Plot("EMAs","EMALongSecond",emaLongSecond); Plot("EMAs","BarClose",price); decimal cash = Portfolio.Cash; int holdings = Portfolio[symbol].Quantity; quantity = Convert.ToInt32((cash * 0.5m) / price); if (holdings > 0 || holdings == 0) { if ((emaShort * (1+tolerance)) < emaLong) { Order(symbol, -(holdings + quantity)); Log(Time.ToShortDateString() + " > Go Short > Holdings: " + holdings.ToString() + " Quantity:" + quantity.ToString() + " Samples: " + emaShort.Samples); } } else if (holdings < 0 || holdings == 0) { if ((emaShort * (1 - tolerance)) > emaLong) { Order(symbol, Math.Abs(holdings) + quantity); Log(Time.ToShortDateString() + "> Go Long > Holdings: " + holdings.ToString() + " Quantity:" + quantity.ToString() + " Samples: " + emaShort.Samples); } } } } }