Below i have attatched some code i found in one of Jareds posts which consolidates 30 minutes into 1 bar. I have 2 questions

1. Why am i unsuccesful in using the data from the bar i created in a loop to execute the buy order?

2. Is it possible to use consolidators accurately to create Montly or weekly timeframe data for forex?

from datetime import datetime, timedelta class DataConsolidationAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2017,1,1) self.SetEndDate( #Set End Date self.AddForex("EURUSD", Resolution.Minute) # define our 30 minute trade bar consolidator. we can # access the 30 minute bar from the DataConsolidated events Consolidator = QuoteBarConsolidator(timedelta(minutes=30)) # attach our event handler. The event handler is a function that will # be called each time we produce a new consolidated piece of data. Consolidator.DataConsolidated += self.MinuteBarHandler # this call adds our 30-minute consolidator to # the manager to receive updates from the engine self.SubscriptionManager.AddConsolidator("EURUSD", Consolidator) def MinuteBarHandler(self, sender, bar): '''This is our event handler for our 30-minute trade bar defined above in Initialize(). So each time the consolidator produces a new 30-minute bar, this function will be called automatically. The sender parameter will be the instance of the IDataConsolidator that invoked the event ''' close = bar.Close Open = bar.Open high = bar.High low = bar.Low self.Debug(str(self.Time) + " " + str(close)+ " "+str(Open)) def OnData(self, data): price = self.Securities["EURUSD"].Price if 0 < high: self.Buy("EURUSD",1000)