Back

Crypto Data, How to get the High and Low price of the previous 24 hour roll over window

Hi so I'm pretty new to this (I'm still in school using the summer covid break to try my hand at some trading strategies). So this may be beginner stuff; but I keep running into issues about the helper functions. So I've tried to use a rolling window to go ahead and pump in data from the last 24 hours into a trade bar (the crypto documentation says crypto falls under forex so I used quote bars); however I've run into a runtime error that prevents daily data consolidation...

I was hoping for some help... I'll be looking forward to any assistance. 

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.


Are you using a trade bar consolidator function? Aslo, could you share your code?

1

Hi Joe Batsulli, Weird I attached my project; I'll try again though

0


Joe Bastulli Hey Sorry for not tagging you; forgot to do that, I have attached my project up above tho; thanks for getting to me.

0

Joe Bastulli 

Hi, so the code above is the wrong one... but the project name is right. I don't know whats going on there but I'm copy and pasting the code below

 


class TachyonQuantumAutosequencers(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 22)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)

        self.AddCrypto("BTCUSD", Resolution.Hour, Market.GDAX)
        
        consolidator = TradeBarConsolidator(24)
        consolidator.DataConsolidated += self.OnDailyData
        self.SubscriptionManager.AddConsolidator("BTCUSD", consolidator)

        self.daily = RollingWindow[QuoteBar](2)
        self.window = RollingWindow[QuoteBar](2)
        
    def OnDailyData(self, sender, bar):
        self.daily.Add(bar)
    
    # Accessing requested data
    def OnData(self, data):
        # via a tradebar dictionary (symbol - bar)
        
        ## Problem is over here
        self.window.Add(data["BTCUSD"])
        if not (self.window.IsReady and self.daily.IsReady): return
    
        currBar = self.window[0].Close
        yesterdayc = self.daily[1].Close
        
        data.Bars["BTCUSD"].Close
        
        #self.Log(" BTCUSD price {data.Bars["BTCUSD"].Close}" )
        
        self.Log("BTCUSD price: " + str(data.Bars["BTCUSD"].Close))

 

0

Joe Bastulli ; I wish I could delete my previous 2 comments; I have finally been able to attach the right code to comment 

0


from QuantConnect.Data.Market import TradeBar
from datetime import timedelta

class TachyonQuantumAutosequencers(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2020, 7, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash

# list of symbols we want to trade
self.symbolList = ["BTCUSD","ETHUSD","LTCUSD","BCHUSD"]

# dictionary to hold rolling window for each symbol
self.daily = {}

for name in self.symbolList:
cryptoSymbol = self.AddCrypto(name, Resolution.Daily, Market.GDAX).Symbol
dailyConsolidator = TradeBarConsolidator(timedelta(days=1))
dailyConsolidator.DataConsolidated += self.DailyConsolidator
self.SubscriptionManager.AddConsolidator(cryptoSymbol, dailyConsolidator)
self.daily[cryptoSymbol] = RollingWindow[float](2)

def DailyConsolidator(self, sender, bar):
symbol = bar.Symbol
close = bar.Close
volume = bar.Volume

# update rolling window
self.daily[symbol].Add(close)

if not (self.daily[symbol].IsReady): return

self.Debug('{} {}'.format(symbol, close))

# Accessing requested data
def OnData(self, data):
pass

Here is one way to use the consolidator.  If you are not using intraday data, I would just use the OnData function instead.

1

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