Overall Statistics |
Total Trades 3 Average Win 0% Average Loss 0.00% Compounding Annual Return 33.612% Drawdown 1.500% Expectancy -1 Net Profit 3.001% Sharpe Ratio 3.069 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.188 Beta 0.129 Annual Standard Deviation 0.063 Annual Variance 0.004 Information Ratio 1.972 Tracking Error 0.078 Treynor Ratio 1.493 Total Fees $0.00 |
namespace QuantConnect { public class TimeBasedAlgo : QCAlgorithm { private SimpleMovingAverage sma; public override void Initialize() { SetStartDate(2017, 1, 1); SetEndDate(2017, 2, 1); SetCash(20000000); SetBenchmark("SPY"); SetBrokerageModel(BrokerageName.OandaBrokerage); AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick); sma = SMA("EURUSD", 24, Resolution.Hour); SetWarmUp(TimeSpan.FromDays(7)); } public override void OnData(Slice data) { if (IsWarmingUp) return; var holdings = Portfolio["EURUSD"].Quantity; var currentPrice = Securities["EURUSD"].BidPrice; var dayCount = TimeSpan.FromDays(10); var totalTime = 0; bool tradeInPlace = false; if(holdings <= 0) { tradeInPlace = false; } if(holdings > 0) { tradeInPlace = true; } if(holdings <= 0 & currentPrice > sma & tradeInPlace == false) { MarketOrder("EURUSD", 100000); LimitOrder("EURUSD", -100000, 20); SetHoldings("EURUSD", 1); Log("Purchased EURUSD on " + Time.ToShortDateString()); } if(holdings <= 0 & currentPrice < sma & tradeInPlace == false) { MarketOrder("EURUSD", -100000); LimitOrder("EURUSD", 100000, 20); SetHoldings("EURUSD", 1); Log("Sold EURUSD on " + Time.ToShortDateString()); } if (Portfolio["EURUSD"].IsLong && totalTime > 10 ) { MarketOrder("EURUSD", -100000); List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD"); totalTime = 0; SetHoldings("EURUSD", 0); Log("Cancelled All Orders & Closed Long Trade " + Time.ToShortDateString()); } if (Portfolio["EURUSD"].IsShort && totalTime > 10 ) { MarketOrder("EURUSD", 100000); List<OrderTicket> cancelledOrders = Transactions.CancelOpenOrders("EURUSD"); totalTime = 0; SetHoldings("EURUSD", 0); Log("Cancelled All Orders & Closed Short Trade " + Time.ToShortDateString()); } } } }