Overall Statistics |
Total Trades 5230 Average Win 0.04% Average Loss -0.03% Compounding Annual Return -15.553% Drawdown 25.400% Expectancy -0.407 Net Profit -25.265% Sharpe Ratio -6.438 Probabilistic Sharpe Ratio 0% Loss Rate 78% Win Rate 22% Profit-Loss Ratio 1.64 Alpha -0.137 Beta 0.007 Annual Standard Deviation 0.021 Annual Variance 0 Information Ratio -2.066 Tracking Error 0.126 Treynor Ratio -18.231 Total Fees $0.00 |
import pandas as pd class ResistanceVerticalInterceptor(QCAlgorithm): def Initialize(self): self.SetStartDate(2018, 1, 1) # Set Start Date self.SetStartDate(2018, 6, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.assets = ["GBPUSD", "EURUSD"] #some other assets ["EURGBP","GBPJPY", "USDJPY"] self.count = len(self.assets) self.risk = 0.2 self.symbols = {} self.states = {} self.price = {} self.orderstop = {} self.stoploss= {} self.profittaking = {} self.SetWarmUp(2) self.market = Market.Oanda self.windows = {} for ticker in self.assets: symbol = self.AddForex(ticker, Resolution.Hour, self.market).Symbol self.states[symbol] = 0 self.price[symbol] = 0 self.orderstop[symbol] = 0 self.stoploss[symbol] = 0 self.profittaking[symbol] = 0 self.windows[symbol] = RollingWindow[TradeBar](2) def OnData(self, data): value = self.Portfolio.TotalPortfolioValue cash = self.Portfolio.Cash # go over all tickers for symbol in self.windows: if data.ContainsKey(symbol) and data.Bars[symbol] != None: self.windows[symbol].Add(data.Bars[symbol]) self.holdings = self.Portfolio[symbol].Quantity self.price[symbol] = self.Portfolio[symbol].AveragePrice if not self.windows[symbol].IsReady: continue firstBar = self.windows[symbol][0] O1 = firstBar.Open #open first candle C1 = firstBar.Close #close first candle L1 = firstBar.Low #low first candle H1 = firstBar.High #high first candle secondBar = self.windows[symbol][1] O2 = secondBar.Open #open second candle C2 = secondBar.Close #close second candle L2 = secondBar.Low #low second candle H2 = secondBar.High #high second candle W = H2 - L2 #range if self.states[symbol] != 0: # if long pattern if self.states[symbol] == 1: # and short pattern if O1 > C1: # and second second contains first if (L2 < L1) and (H2 > H1): self.Liquidate(symbol) self.states[symbol] = 0 self.Debug("Liquidating long") # if short pattern if self.states[symbol] == -1: # and long pattern if O1 < C1: # and second contains first if (L2 < L1) and (H2 > H1): self.Liquidate(symbol) self.states[symbol] = 0 self.Debug("Liquidating short") else: self.Debug("Holding") if self.states[symbol] == 0: # go long if first green if O1 < C1: # and second contains first if (L2 < L1) and (H2 > H1): #self.SetHoldings(symbol, cash*self.risk) self.orderstop[symbol] = (H1 + 0.1 * W) self.stoploss[symbol] = (H1 - 0.2* W) self.profittaking[symbol] = (H1 + 0.8* W) # stop order self.StopMarketOrder(symbol, cash*self.risk, self.orderstop[symbol]) # stoploss self.StopMarketOrder(symbol, -cash*self.risk, self.stoploss[symbol]) # profit taking self.LimitOrder(symbol, -cash*self.risk, self.profittaking[symbol]) self.states[symbol] = 1 self.Debug("Buy") # go short if first red if O1 > C1: # and second second contains first if (L2 < L1) and (H2 > H1): self.orderstop[symbol] = (L1 - 0.1 * W) self.stoploss[symbol] = (L1 + 0.2* W) self.profittaking[symbol] = (L1 - 0.8* W) # stop order self.StopMarketOrder(symbol, -cash*self.risk, self.orderstop[symbol]) # stoploss self.StopMarketOrder(symbol, cash*self.risk, self.stoploss[symbol]) # profit taking self.LimitOrder(symbol, cash*self.risk, self.profittaking[symbol]) self.states[symbol] = -1 self.Debug("Sell")