Overall Statistics |
Total Trades 23 Average Win 2.23% Average Loss -1.27% Compounding Annual Return -26.274% Drawdown 27.100% Expectancy -0.724 Net Profit -26.333% Sharpe Ratio -1.361 Probabilistic Sharpe Ratio 0.239% Loss Rate 90% Win Rate 10% Profit-Loss Ratio 1.76 Alpha -0.186 Beta -0.123 Annual Standard Deviation 0.154 Annual Variance 0.024 Information Ratio -1.095 Tracking Error 0.369 Treynor Ratio 1.707 Total Fees $0.00 |
import decimal as d from datetime import timedelta class MovingAverageCrossAlgorithm(QCAlgorithm): def Initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.SetTimeZone("Europe/Rome") self.SetStartDate(2020, 1, 1) #Set Start Date self.SetEndDate(2020, 12, 31) #Set End Date self.SetCash(100000) #Set Strategy Cash self.currencies = ["EURUSD", "GBPUSD", "USDJPY"] for c in self.currencies: self.symbol = self.AddForex(c, Resolution.Hour) self.fast = self.EMA(c, 50, Resolution.Hour) self.slow = self.EMA(c, 200, Resolution.Hour) self.warm = self.SetWarmUp(200) self.quant = 100000 def OnData(self, data): tolerance = 0.00015 for curr in self.currencies: if not self.Portfolio.Invested: #if not self.Portfolio[curr].IsLong: price = data[curr].Close if self.fast.Current.Value > self.slow.Current.Value * d.Decimal(1 + tolerance): self.MarketOrder(curr, self.quant) self.StopMarketOrder(curr, -self.quant, (price * 0.99)) self.LimitOrder(curr, -self.quant, (price * 1.02)) # if self.Portfolio[c].IsLong: # if self.fast.Current.Value < self.slow.Current.Value: # self.Liquidate(c) def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) if order.Status == OrderStatus.Filled: if order.Type == OrderType.Limit or order.Type == OrderType.Limit: self.Transactions.CancelOpenOrders(order.Symbol) if order.Status == OrderStatus.Canceled: self.Log(str(orderEvent))