Hi
I am trying to get at tradebar object so that I can get high, low, close, open. I am using code from the Futures - Handling data documentation but I does not work. I keep getting the :
Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'QuantConnect.Securities.Future.Future'>) method. Please checkout the API documentation.
at on_data
bar = data.bars.get(self._future)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 19
My code is as follows:
class PensiveYellowGreenBaboon(QCAlgorithm):
buyorder = None
sellorder = None
profit = None
stoploss = None
bar = None
def initialize(self):
self.set_start_date(2023, 1, 1)
self.set_cash(100000)
self._future = self.add_future(Futures.Indices.SP_500_E_MINI,
resolution = Resolution.MINUTE)
def on_data(self, data: slice) -> None:
bar = data.bars.get(self._future)
invested = self.check_for_existing_orders_or_positions()
if not invested:
if data.time.hour == 9 and data.time.minute == 31:
buyorder = self.stop_market_order(self._future, 2, bar.high+0.25)
sellorder = self.stop_market_order(self._future, 2, bar.Low-0.25)
def check_for_existing_orders_or_positions(self):
if self.portfolio.invested:
return True
if self.transactions.get_open_orders_remaining_quantity() > 0:
return True
return False
Mia Alissi
Sources: Handling Data - QuantConnect.com, Handling Data - QuantConnect.com, Handling Data - QuantConnect.com, Handling Data - QuantConnect.com, Handling Data - QuantConnect.com
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.
Sunes Journey
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!