I put together a simple example for Consolidator Indicators using:
However, I am at a loss to get it working. I was attempting to create indicators covering the exact same time spans but at the 1 minute and 5 minute resolutions. Any help would be appreciated. I cannot post the backtest since it just produces errors, but the code is below:
# CryptoVolatilityTap (v4, ETHUSD, Minute, Py)
# Tap crypto volatility spikes
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Data import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Data.Consolidators import *
from datetime import datetime
import decimal as d
import numpy as np
class CVTap(QCAlgorithm):
def Initialize(self):
# define email address for buy/sell notifications
# please change prior to Live deploy
#self.email_address = 'xxxxx@gmail.com'
self.SetStartDate(2017,9,1) #Set Start Date
self.SetEndDate(2017,11,14) #Set End Date
self.SetCash(1000) #Set Strategy Cash
# define crypto we want to trade on
# ETHUSD or LTCUSD or BTCUSD
self.target_crypto = "ETHUSD"
# Set brokerage to GDAX for cryptos
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
# Add crypto at minute resolution
self.AddCrypto(self.target_crypto, Resolution.Minute)
# create consolidator for 15 minute
consFiveMin = TradeBarConsolidator(5)
consFiveMin.DataConsolidated += self.OnDataConsolidated
self.SubscriptionManager.AddConsolidator(self.target_crypto, consFiveMin)
# Define exponential moving average at 1 min resolution
self.ema_very_fast_one_min = self.EMA(self.target_crypto, 10)
# Define exponential moving average at 5 min resolution
self.ema_very_fast_five_min = self.EMA(self.target_crypto, 2, consFiveMin)
# Plot 1 Min EMAs
self.PlotIndicator(
self.target_crypto_one_min,
)
# Plot 5 Min EMAs
self.PlotIndicator(
self.target_crypto_five_min,
)
def OnDataConsolidated(self, sender, bar):
self.Debug(str(self.Time) + " > New 5 Min Bar!")
def OnData(self, data):
self.Debug(str(self.Time) + " > New 1 Min Bar!")
Jared Broad
Hi Liquid; thanks for giving it a solid effort! "EMA" is the short hand helper, but you can create indicator objects manually and update them. See the example attached.
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.
Liquidgenius
Excellent clarification, thank you Jared Broad
Liquidgenius
I broke out the example further to illustrate using a base resolution tick to generate indicators at the same and larger consolidated resolutions, all covering the same length window:
Hopefully, this is a useful example to someone else. These examples work well for Cryptos where the market is essentially always open, however you will want to reference the DataConsolidationAlgorithm.py example on Github when dealing with markets that experience trading days and closed periods or the QuantConnect docs for Consolidators and Consolidated Indicators. Thanks again Jared for helping me to better understand this process.
Filib Uster
I cloned your code, but the backtest does not seem to reproduce the indicator plot. What could be the problem?
Link Liang
Hi Filib,
Our charting is slightly different from what we had in 2017. Here I made a little modification to replicate the same chart you see in the previous post. Just don't use same name for every indicator and it will look good in backtesting terminal!
Hope it helps!
Kanat Mergenbayev
Hi want to check simple moving average numbers. But somehow consolidator uses non regular hours to calculate simple moving average. Besides could you please check if I am doing everything correct in 30 minute simple moving average calculations.
regards Kanat
Alexandre Catarino
Hi Kanat Mergenbayev ,
Please check out the docs, under Indicators, for more information on working with indicators and consolidators.
Obimba Smart Chukwunenye
Thanks for this.
So does this mean when using consolidators, I would have to write my trading logic on on OnDataConsolidated event handler instead of OnData ?Â
Louis Szeto
Hi ObimbaÂ
It depends on the data dependency of your trading logic. If your trading logic is purely based on consolidated bars/indicators, yes, you'll have to implement that in OnDataConsolidated event handler.
Best
Louis
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.
Obimba Smart Chukwunenye
Again how does data flow when using consolidated data in a framework model. How do I generate insights based on consolidated data ?
Louis Szeto
Hi Obimba
Please refer to this thread.
Best
Louis
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.
Liquidgenius
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!