Overall Statistics |
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $17.30 |
import pandas as pd import csv from io import StringIO class ParticleResistanceCoreWave(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 8, 12) # Set Start Date self.SetEndDate(2020, 8, 12) # Set End Date self.SetCash(10000) # Set Strategy Cash csv081220 = self.Download("https://www.dropbox.com/s/4m6xfc34qnhr2x2/updowntriggers081220.csv?dl=1") self.df = pd.read_csv(StringIO(csv081220),header=None) #copy the csv that you want to use in the parentheses after StringIO self.Symbols = self.df.iloc[0].values.tolist() self._macd = dict() for symbol in self.Symbols: self.AddEquity(symbol, Resolution.Minute) self._macd[symbol] = self.MACD(symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute) self.SetWarmUp(26) self.tradedsymbols = [] #Put symbols in this list to prevent trading twice in a day def OnData(self, data): #--------------------------------Define data from csv for trading--------------------------------- new_header = self.df.iloc[0] df = self.df[1:] df.columns = new_header for symbol in self.Symbols: symboldf = df[symbol] singlesymboldf = symboldf updownlist = singlesymboldf.tolist() uptrigger = float(updownlist[0]) downtrigger = float(updownlist[1]) #-------------------------Open Long Position if Price Crosses Up Trigger----------------- if self.Securities[symbol].Price > uptrigger and symbol not in self.tradedsymbols: self.SetHoldings(symbol, .25) self.tradedsymbols.append(symbol) #-----------------------Open Short Position if Price Crosses Down Trigger-------------- if self.Securities[symbol].Price < downtrigger and symbol not in self.tradedsymbols: self.SetHoldings(symbol, -.25) self.tradedsymbols.append(symbol) if not all([_macd.IsReady for symbol, _macd in self._macd.items()]): return #----------------------------Close Positions Based On MACD Value---------------------------- if self.Portfolio[symbol].HoldingsValue > 0: for symbol, _macd in self._macd.items(): if _macd.Current.Value < 0: self.Liquidate(symbol) if self.Securities[symbol].Price < uptrigger*.95: self.Liquidate(symbol) if self.Portfolio[symbol].HoldingsValue < 0: for symbol, _macd in self._macd.items(): if _macd.Current.Value > 0: self.Liquidate(symbol) if self.Securities[symbol].Price > downtrigger*1.05: self.Liquidate(symbol)