Back

Consolidator Indicators - Help Needed

I put together a simple example for Consolidator Indicators using: 

https://www.quantconnect.com/docs#Consolidating-Datahttps://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/DataConsolidationAlgorithm.py

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!")

Update Backtest








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.

  • PlotIndicators was funky for some reason, we'll dig into that.
  • If want a non-standard bar length need to add the consolidated data to class manally, see the DataConsolidated event.
  • Slightly misnamed "self.target_crypto_one_min"
  • You can't pass in the consolidator to the indicator, but that is a pretty cool idea so will take it as a suggesion! "self.EMA(self.target_crypto, 2, consFiveMin)"
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.


Excellent clarification, thank you Jared Broad 

0

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:

  • EMA at 1 minute base resolution covering 2 hours
  • EMA at 5 minute consolidated resolution covering 2 hours
  • EMA at 1 hour consolidated resolution covering 2 hours

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.

4


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