| Overall Statistics |
|
Total Trades 0 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 -1.093 Tracking Error 0.068 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
class LouisLesson4(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2021, 1, 1)
self.SetCash(1000)
self.eurusd = self.AddEquity("EURUSD", Resolution.Hour).Symbol
# self.SetBenchmark("SPY") # plot benchmark chart on backtest result
self.SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin)
#self.entryPrice = 0
#self.period = timedelta(31)
self.nextEntryTime = self.Time
def OnData(self, data):
if not self.eurusd in data:
return
# 3 ways to access to last close price
# price = self.data.Bars[self.eurusd].Close
price = data[self.eurusd].Close
# price = self.Securities[self.eurusd].Close
if not self.Portfolio.Invested:
if self.nextEntryTime <= self.Time:
# 2 ways to calculate quantity (this example was for SPY)
# self.SetHoldings(self.eurusd, 1) # 1 = percentage of portfolio 100%
self.MarketOrder(self.eurusd, int(self.Portfolio.Cash / price)) # specify qty as second arg
self.Log(f"BUY EURUSD @ {price}")
# self.debug(f"BUY EURUSD @ {price}") # logs to console
self.entryPrice = price
# already invested
elif self.entryPrice * 1.1 < price or self.entryPrice * 0.9 > price:
self.Liquidate() # close all positions
# self.Liquidate(self.eurusd) # close only specified position
self.Log(f"SELL EURUSD @ {price}")
self.nextEntryTime = self.Time + self.period