Back

Multi Time Frame Forex Bars

I am trying to implement Forex strategies based on multi-time-frame-bars.

The following code

class MultiTimeFrameForexScalping(QCAlgorithm):

def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2015, 12, 1) #Set Start Date
self.SetEndDate(2015, 12, 5) #Set End Date
self.SetCash(5000) #Set Strategy Cash
self.forexPair = "EURUSD"
self.AddForex(self.forexPair, Resolution.Minute, Market.Oanda)

fiveMinutesConsolidator = TradeBarConsolidator(timedelta(minutes=30))
fiveMinutesConsolidator.DataConsolidated += self.fiveMinutesBarHandler
sixtyMinutesConsolidator = TradeBarConsolidator(timedelta(minutes=60))
sixtyMinutesConsolidator.DataConsolidated += self.sixtyMinutesBarHandler
self.SubscriptionManager.AddConsolidator(self.forexPair, fiveMinutesConsolidator)
self.SubscriptionManager.AddConsolidator(self.forexPair, sixtyMinutesConsolidator)
self.fiveMinutesBars = queue(5)
self.sixtyMinutesBars = queue(5)

def fiveMinutesBarHandler(self, sender, consolidated):
self.fiveMinuteBars.put(consolidated)

def sixtyMinutesBarHandler(self, sender, consolidated):
self.sixtyMinuteBars.put(consolidated)

throws 

During the algorithm initialization, the following exception has occurred: ArgumentException : Type mismatch found between consolidator and symbol. Symbol: EURUSD does not support input type: TradeBar. Supported types: QuoteBar.

at QuantConnect.Data.SubscriptionManager.AddConsolidator (QuantConnect.Symbol symbol, QuantConnect.Data.Consolidators.IDataConsolidator consolidator) [0x000f5] in <0231d19d68ca47818f527e368535d623>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at Initialize in main.py:line 44

Is that the correct way to do something like that? What is wrong with the code? 

Update Backtest







0

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.


Hey Filib,

FX data is returned as QuoteBars, not TradeBars. This means you must create QuoteBarConsolidators instead of TradeBarConsolidators for your FX data.

fiveMinutesConsolidator = QuoteBarConsolidator(timedelta(minutes=5))
fiveMinutesConsolidator.DataConsolidated += self.fiveMinutesBarHandler

sixtyMinutesConsolidator = QuoteBarConsolidator(timedelta(minutes=60))
sixtyMinutesConsolidator.DataConsolidated += self.sixtyMinutesBarHandler

self.SubscriptionManager.AddConsolidator(self.forexPair, fiveMinutesConsolidator)
self.SubscriptionManager.AddConsolidator(self.forexPair, sixtyMinutesConsolidator)

 

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed