Overall Statistics |
Total Trades 2 Average Win 0% Average Loss -1.09% Compounding Annual Return -38.346% Drawdown 1.200% Expectancy -1 Net Profit -0.954% Sharpe Ratio -3.923 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.334 Beta -0.204 Annual Standard Deviation 0.068 Annual Variance 0.005 Information Ratio 0.79 Tracking Error 0.086 Treynor Ratio 1.303 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); AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick); SetWarmUp(TimeSpan.FromDays(7)); } public override void OnData(Slice data) { var holdings = Portfolio["EURUSD"].Quantity; var sma = SMA("EURUSD", 24, Resolution.Hour); var currentPrice = Securities["EURUSD"].BidPrice; var dayCount = TimeSpan.FromDays(10); var tradeTime = 0; 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()); } } } }