class EnglishBreakfast(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 11, 14) # Set Start Date
self.SetStartDate(2020,12,14)
self.SetCash(100000) # Set Strategy Cash
self.forex = self.AddForex("GBPUSD", Resolution.Minute, Market.Oanda)
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
def OnData(self, data):
if self.Time.hour == 4 and self.Time.minute == 15:
self.gbpusdBeginPrice = data["GBPUSD"].Close
if self.Time.hour == 8 and self.Time.minute == 30:
self.gbpusdClosePrice = data["GBPUSD"].Close
if not self.Portfolio.Invested and self.gbpusdClosePrice < self.gbpusdBeginPrice and self.Time.hour == 8 and self.Time.minute == 31:
self.gbpusdBuyPrice = data ["GBPUSD"].Close.Bid
self.MarketOrder("GBPUSD",+3)
self.Debugg(self.gbpusdBuyPrice)
self.StopMarketOrder("GBPUSD",-3, self.gbpusdBuyPrice * 0.998) # Stop Loss
self.StopMarketOrder("GBPUSD",-1, self.gbpusdBuyPrice * 1.002) # Take Profit 1
self.StopMarketOrder("GBPUSD",-1, self.gbpusdBuyPrice * 1.004) # Take Profit 2
self.StopMarketOrder("GBPUSD",-1, self.gbpusdBuyPrice * 1.006) # Take Profit 3
elif not self.Portfolio.Invested and self.gbpusdClosePrice < self.gbpusdBeginPrice and self.Time.hour == 8 and self.Time.minute ==31:
gbpusdSellPrice = data ["GBPUSD"].Close.Ask
self.MarketOrder("GBPUSD",-3)
self.Debugg(gbpusdSellPrice)
self.StopMarketOrder("GBPUSD",+3, self.gbpusdSellPrice * 1.002) # Stop Loss
self.StopMarketOrder("GBPUSD",+1,self.gbpusdSellPrice * 0.998) # Take Profit 1
self.StopMarketOrder("GBPUSD",+1,self.gbpusdSellPrice * 0.996) # Take Profit 2
self.StopMarketOrder("GBPUSD",+1,self.gbpusdSellPrice * 0.994) # Take Profit 3