none of my consolidators work:
class TxTrader(QCAlgorithm):
def initialize(self):
self.set_start_date(year=2024, month=1, day=1)
# MASSIVE BEARMARKET DATES:
# self.set_start_date(year=2021, month=11, day=12)
# self.set_end_date(year=2022, month=11, day=12)
self.set_account_currency("USDT")
self.set_cash(100000)
self.set_brokerage_model(BrokerageName.BINANCE, AccountType.CASH)
self.universe_settings.Resolution = Resolution.HOUR
self.add_universe(CoinGeckoUniverse, self.CoinGecko_selector)
self.trading_cryptos = dict()
'''
############ trading cryptos will look something like this:
self.traded_cryptos = {'BTCUSDT' : {'crypto' : None,
'indicators' : {'rsi' : None, 'atr' : None}
},
'SOLUSDT' : {'crypto' : None,
'indicators' : {'rsi' : None, 'atr' : None}
}
} ..... etc
############
'''
def CoinGecko_selector(self, data: List[CoinGeckoUniverse]) -> List[Symbol]:
# for datum in data:
# self.debug(f'{datum.coin},{datum.market_cap},{datum.price}')
# define our selection criteria
# filtered = [crypto for crypto in data if ]
selected = sorted(data, key=lambda x: x.market_cap, reverse=True)[:5]
# Use the CreateSymbol method to generate the Symbol object for
return [x.create_symbol(Market.BINANCE, "USDT") for x in selected]
def on_securities_changed(self, changes):
for security in changes.added_securities:
symbol = security.symbol.value
if symbol not in self.trading_cryptos.keys():
self.deploy_tradebot(symbol, Resolution.HOUR, Market.BINANCE, consolidation=2)
self.log(f'Added {symbol}')
else:
self.debug(f'ALREADY TRADING {symbol} !')
for security in changes.removed_securities:
symbol = security.symbol.value
if symbol in self.trading_cryptos.keys():
self.disable_tradebot(symbol)
self.log(f'Removed {symbol}')
else:
self.debug(f'ALREADY DELETED {symbol} !')
def on_consolidated_data(self, sender: object, consolidated: TradeBar) -> None:
self.log(f'current in on_consolidated_data for {consolidated.symbol}')
def deploy_tradebot(self, symbol, _resolution, _market, consolidation=1):
self.trading_cryptos[symbol] = dict()
self.trading_cryptos[symbol]['crypto'] = self.add_crypto(symbol, _resolution, _market)
_symbol = self.trading_cryptos[symbol]['crypto'].symbol
self.log(f'deploying {symbol}')
if _resolution is Resolution.DAILY:
consolidated_time = timedelta(days=consolidation)
elif _resolution is Resolution.HOUR:
self.log('HOUR NIGGA')
consolidated_time = timedelta(hours=consolidation)
elif _resolution is Resolution.MINUTE:
consolidated_time = timedelta(minutes=consolidation)
else:
self.error('Consolidator resolution not defined')
######## initialise indicators ########
self.trading_cryptos[symbol]['indicators'] = dict()
self.trading_cryptos[symbol]['indicators']['vwma_l'] = self.vwma(symbol, self.indicator_params['vwma_l_period'])
#######################################
consolidator = TradeBarConsolidator(consolidated_time)
consolidator.data_consolidated += self.on_consolidated_data
self.subscription_manager.add_consolidator(_symbol, consolidator)
self.trading_cryptos[symbol]['consolidator'] = consolidator
def disable_tradebot(self, symbol):
self.liquidate(symbol)
self.trading_cryptos[symbol]['consolidator'].DataConsolidated -= self.on_consolidated_data
self.subscription_manager.remove_consolidator(symbol, self.trading_cryptos[symbol]['consolidator'])
del self.trading_cryptos[symbol]
########################################
I appreciate any help
Mia Alissi
Make sure to define
indicator_params
and verify the attributes forCoinGeckoUniverse
. Adjust the universe selection logic as necessary for your specific use case.Sources: Time Period Consolidators - QuantConnect.com, Multiple Symbol Consolidation Algorithm, Count Consolidators - QuantConnect.com, Mixed-Mode Consolidators - QuantConnect.com, Data Consolidation Algorithm
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.
Tamer
you're right, the problem was with the universe selection process. For some reason, the on_securities_changed method was triggered correctly. But for some reason when I used a normal coarse filter the consolidators worked
Â
Tamer
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!