Back

Correct way to create, warm up and use an indicator in a 5 minute consolidation

Sorry if this is the wrong place to post this but I was wondering if someone could look at this code and comment on if its the correct way to use and ADX indicator in a 5 minute data consolidation?  Thanks for your time! 

import numpy as np
import datetime
import calendar


class VPPlgorithm(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(2013,1,18) #Set Start Date
self.SetEndDate(2013,11,21) #Set End Date
self.SetCash(10000) #Set Strategy Cash
self.AddForex("USDJPY", Resolution.Minute, Market.Oanda)
self.SetBrokerageModel(BrokerageName.OandaBrokerage)

self.adx = AverageDirectionalIndex("USDJPY",14)

fiveMinuteConsolidator = QuoteBarConsolidator(datetime.timedelta(minutes=5))
fiveMinuteConsolidator.DataConsolidated += self.FiveMinuteBarHandler
self.SubscriptionManager.AddConsolidator("USDJPY", fiveMinuteConsolidator)
self.RegisterIndicator("USDJPY", self.adx, fiveMinuteConsolidator)

self.SetWarmUp(5*14, Resolution.Minute)


def FiveMinuteBarHandler(self, sender, consolidated):
if self.adx.IsReady:
self.Log("ADX: " + str(self.adx.Current.Value))


def OnData(self, data):
pass
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.


i think you have to manually update the indicator.

you set usdjpy symbol which will take the resolution also for the  adx which is minute.

search for .Update(........) in the community

which will bring up:

https://www.quantconnect.com/forum/discussion/3622/adx-ibasedatabar-forex/p1
0

Hi Greg,

You've got it correct! Registering the Indicator along with the Consolidator will make sure that the ADX Indicator is updated every 5 minutes. The documentation on this method, as well as manual updating, can be found here.

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.


Thanks Jack!  Really appreciate your reply.  I built the code based on how I read the the doc in the link you included and felt this is how it should be done however without peer review and/or testing (preferably both) code is otherwise useless (i.e. gigo).  I have no idea how to write tests to validate my indicator correctness in this environment so your input is invaluable.  In general (not just quantconnect for sure), I wonder how many systems produce misleading results due to improper indicator or other input calculations?!?!?   Thanks again for your help! 

0

Glad I could help! A good way to write tests, especially for this, is to log price and Indicator value in the OnData() method and then check again the Indicator value that gets pumped through the consolidator. If you feel comfortable reading source code, you can find more information about how our Indicators function here and how Consolidators function here. Hard to say exactly how other platforms do consolidaton and indicator calculation, but all of our code is open source and available for you to read!

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.


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

 
";