Overall Statistics |
Total Trades 2 Average Win 0% Average Loss -0.33% Compounding Annual Return 0.678% Drawdown 0.400% Expectancy -1 Net Profit 0.004% Sharpe Ratio 0.222 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0.014 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
namespace QuantConnect { public class TimeBasedAlgo : QCAlgorithm { public override void Initialize() { SetStartDate(2018, 1, 1); SetEndDate(2018, 1, 2); SetCash(5000); SetBenchmark("SPY"); SetBrokerageModel(BrokerageName.OandaBrokerage); AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick); } public override void OnData(Slice data) { var holdings = Portfolio["EURUSD"].Quantity; var sma = SMA("EURUSD", 24, Resolution.Hour); var currentPrice = Securities["EURUSD"].BidPrice; 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); SetHoldings("EURUSD", 1); Log("Purchased EURUSD on " + Time.ToShortDateString()); if(tradeInPlace == true && Portfolio["EURUSD"].IsLong) { Schedule.On(DateRules.On(endTime), TimeRules.At(13, 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); SetHoldings("EURUSD", 1); Log("Sold EURUSD on " + Time.ToShortDateString()); if(tradeInPlace == true && Portfolio["EURUSD"].IsShort) { Schedule.On(DateRules.On(endTime), TimeRules.At(13, 0), () => { Liquidate("EURUSD"); SetHoldings("EURUSD", 0); List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD"); Log("Cancelled All Orders & Closed Short Trade " + Time.ToShortDateString()); }); } } } } }