Overall Statistics |
Total Trades 129 Average Win 2.10% Average Loss 0% Compounding Annual Return 257.778% Drawdown 37.900% Expectancy 0 Net Profit 265.620% Sharpe Ratio 1.58 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 1.023 Beta 0.896 Annual Standard Deviation 0.712 Annual Variance 0.507 Information Ratio 1.423 Tracking Error 0.71 Treynor Ratio 1.255 Total Fees $0.00 |
namespace QuantConnect { public class TimeBasedAlgo : QCAlgorithm { public override void Initialize() { SetStartDate(2017, 1, 1); SetEndDate(2018, 1, 1); SetCash(5000); SetBenchmark("SPY"); SetBrokerageModel(BrokerageName.OandaBrokerage); AddForex("EURUSD", Resolution.Hour, Market.Oanda); SetWarmUp(TimeSpan.FromDays(7)); var sma = SMA("EURUSD", 24, Resolution.Hour); } public override void OnData(Slice data) { if (IsWarmingUp) return; var sma = SMA("EURUSD", 24, Resolution.Hour); var holdings = Portfolio["EURUSD"].Quantity; var currentPrice = data["EURUSD"].Bid.Close; var close = Securities["EURUSD"].Close; var limitPriceUp = close * 1.002m; var limitPriceDown = close * 1.0016m; DateTime endTime = DateTime.Today.AddDays(10); bool tradeInPlace; if(Portfolio["EURUSD"].Invested) { tradeInPlace = true; } else { tradeInPlace = false; } if(holdings <= 0 & currentPrice > sma & tradeInPlace == false) { MarketOrder("EURUSD", 100000); LimitOrder("EURUSD", -100000, limitPriceUp); // SetHoldings("EURUSD", 1); Log("Purchased EURUSD on " + Time.ToShortDateString()); if(tradeInPlace == true && Portfolio["EURUSD"].IsLong) { Schedule.On(DateRules.On(endTime), TimeRules.At(1, 0), () => { Liquidate("EURUSD"); //SetHoldings("EURUSD", 0); List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD"); Log("Cancelled All Orders & Closed Long Trade " + Time.ToShortDateString()); }); } } if(holdings <= 0 & currentPrice < sma & tradeInPlace == false) { MarketOrder("EURUSD", -100000); LimitOrder("EURUSD", 100000, limitPriceDown); //SetHoldings("EURUSD", 1); Log("Sold EURUSD on " + Time.ToShortDateString()); if(tradeInPlace == true && Portfolio["EURUSD"].IsShort) { Schedule.On(DateRules.On(endTime), TimeRules.At(1, 0), () => { Liquidate("EURUSD"); // SetHoldings("EURUSD", 0); List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD"); Log("Cancelled All Orders & Closed Short Trade " + Time.ToShortDateString()); }); } } } } }