Dear community,
I am trying to build a On-Balance Volume (OBV) indicator that I can use in the CoarseFiltterFunction as a filter to select stocks.
Anyone got suggestions on how to build this On-Balance Volume (OBV) indicator.
class CoarseUniverseAlgorithm(QCAlgorithm):
def Initialize(self):
self.AddUniverse(self.CoarseFilterFunction)
def CoarseFilterFunction(self, coarse):
...
class SelectionData():
def __init__(self):
self.obv = OnBalanceVolume()
def is_ready(self):
return self.obv.IsReady
def update(self, history):
for bar in history.itertuples():
tradeBar = TradeBar(bar.Index[1], bar.Index[0], bar.open, bar.high, bar.low, bar.close, bar.volume)
self.obv.Update(tradeBar)
The python code gives an Error as shown below.
Jon Brygge
The full code is shown below.
I have not added or used the OBV indicator in the CoarseSelectionFunction. I am only using this code as an example to build the OBV indicator.
Fred Painchaud
Hi Jon,
Here is a modified version of your algo. You found errors in the data. Here is the log for the error data (without volume):
Many tickers on March 5, 2021 don't have volume data, it seems…
You could report that here:
Your algo is not very efficient. Look into rolling windows instead of calling History for each day. But you are still learning so all fine.
Fred
Jon Brygge
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!