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(datetime.now()) #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)
Michael Manus
hi,
1) the ondata is called every time you defined in the resolution...so every minute.....
2) you could consolidate day resolution to one month bars ... should be possible
here an example how the consoldator works:
also check this out:
Michael Manus
also:
Edvinas Jablonskis
Thank you Micheal.
The reason i think that consolidating daily bars into monthly may be inacurate is because there are different amounts of trading days in certain months in the forex market. There is also no trading on certain holidays like christmas
Michael Manus
technically yes i know what you mean but try it first and test/log when you have your first data point. it should be on the first of month....
i am only a c# developer but if there is something like this
oneDayConsolidator = TradeBarConsolidator(timedelta(1))
from the first algo to create an day candle maybe there should be an method to create a month candle ......
Edvinas Jablonskis
I will take some time to research this and maybe make another post about it. Thank you Micheal
Edvinas Jablonskis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!