Hi guys,
I've read about how consolidation should work but seems I can't get my head around it and seem to find stuff that does not match any understanding I have with it.
I've tried consolidating Forex tick data in 30 minute bars and then tried to make sense of the logic behind it.
Here goes:
1. first algo, just outputs the bid/ask values:
def Initialize(self):
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.SetStartDate(2018, 10, 1) # Set Start Date
self.SetEndDate(2018, 10, 1) # Set Start Date
self.SetCash(1000) # Set Strategy Cash
self.AddForex("EURUSD", Resolution.Tick, Market.Oanda)
def OnData(self, data):
self.Log("Bid " + str(self.Securities["EURUSD"].BidPrice))
self.Log("ASK " + str(self.Securities["EURUSD"].AskPrice))
2. second algorithm uses a consolidator to generate 30 minute bars:
def Initialize(self):
self.SetStartDate(2018, 10, 1) # Set Start Date
self.SetEndDate(2018, 10, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddForex("EURUSD", Resolution.Tick)
consolidator = TickQuoteBarConsolidator(timedelta(minutes=30))
consolidator.DataConsolidated += self.OnDataConsolidated
self.SubscriptionManager.AddConsolidator("EURUSD", consolidator)
def OnDataConsolidated(self, sender, bar):
self.Debug(str(self.Time) + " > New Bar! " + str(bar.Open))
When I look at the first line in the logfile for the consolidator algo, I have:
2018-10-0100:30:00 2018-10-01 00:30:00.173000 > New Bar! 1.159645
If I look at the tick bid/ask values for the begining of that minute, I have:
01/10/201800:29:57Bid1.1593701/10/201800:29:57ASK1.1595201/10/201800:30:02Bid1.1593701/10/201800:30:02ASK1.1595101/10/201800:30:02Bid1.1593601/10/201800:30:02ASK1.1595001/10/201800:30:03Bid1.1593701/10/201800:30:03ASK1.15951I don't understand where the bar.Open value (1.159645) comes from, looking at the Bid/Ask values for around that time.
When backtesting an algo using minute resolution, I noticed that the price the market orders were filled was usually the last bid/ask of the previous minute so when I was looking at open/close data to generate a trendline (for ex), the market orders were pretty far away from the open/close values.
Hope my question makes sense.
Dan