Hello guys, I´m trying to take access to the candlestick patterns libraries that are in the GitHub LEAN documentation, but there is not too much information related to how to calculate it in a universe selection approach. Second, I want to know if there is any way to get access to TradeBars in order to obtain the OHLC of equities and with this information develop my own custom candlestick pattern?

In the next code, I want to use for the moment a simple condition to filter the stock that has an RSI value lower than 40 and the DojiStar built-in CandlestickPatterns library, but I don´t know how to use it in a universe selection approach:

import typing
import QuantConnect.Indicators.CandlestickPatterns
import datetime

class EMAMomentumUniverse(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2020, 10, 11)
self.SetEndDate(2020, 11, 11)
self.SetCash(1000)
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction)
self.averages = { }


def CoarseSelectionFunction(self, universe):
selected = []
universe = sorted(universe, key=lambda c: c.DollarVolume, reverse=True)
universe = [c for c in universe if (c.Price > 10)][:100]

for coarse in universe:
symbol = coarse.Symbol

if symbol not in self.averages:
# 1. Call history to get an array of 200 days of history data
history = self.History(symbol, 200, Resolution.Daily)

#2. Adjust SelectionData to pass in the history result
self.averages[symbol] = SelectionData(history)

#here is where im trying to create the bool variable.
self.hammer = DojiStar(symbol)

self.averages[symbol].update(self.Time, coarse.AdjustedPrice)



if self.averages[symbol].is_ready() and (self.averages[symbol].rsi.Current.Value < 40):

selected.append(symbol)

return selected[:10]

def OnSecuritiesChanged(self, changes):

for security in changes.RemovedSecurities:

self.Liquidate(security.Symbol)

for security in changes.AddedSecurities:
self.SetHoldings(security.Symbol, 0.10)




class SelectionData():

#3. Update the constructor to accept a history array
def __init__(self, history ):

self.rsi = RelativeStrengthIndex(14)

#4. Loop over the history data and update the indicators

for data in history.itertuples():

self.rsi.Update(data.Index[1], data.close)



def is_ready(self):

return self.rsi.IsReady

def update(self, time, price):

self.rsi.Update(time, price)

 

Thanks a lot!