import numpy as np
class BasicTemplateAldgorithm(QCAlgorithm):
def Initialize(self):
# Set the cash we'd like to use for our backtest
# This is ignored in live trading
self.SetCash(1000)
# Start and end dates for the backtest.
# These are ignored in live trading.
self.SetStartDate(2016,6,1)
self.SetEndDate(2018,10,1)
# Set Brokerage model to load OANDA fee structure.
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
# Add assets you'd like to see
self.eurusd = self.AddForex("EURUSD", Resolution.Minute)
self.usdcad = self.AddForex("USDCAD", Resolution.Minute)
self.eurusd_bb = self.BB("EURUSD", 16, 2.0 )
self.usdcad_bb = self.BB("USDCAD", 16, 2.0 )
def OnData(self, data):
# Simple buy and hold template
self.eurusd_holding = self.Portfolio['EURUSD'].Quantity
self.usdcad_holding = self.Portfolio['USDCAD'].Quantity
if(self.eurusd.Open > self.eurusd_bb.UpperBand):
#self.percent = .05
self.setHoldings('EURUSD', .05, True)
elif(self.eurusd.Open <= self.eurusd_bb.MiddleBand):
self.setHoldings('EURUSD', 0, True)
Hello,
I am trying to learn how to use this api, but I keep getting an error "Cannot get managaed object"
The line that it lists as the cause is the commented line 'self.percent = .05' so I am guessing it is one of the lines before or after it.
from other posts, it looks like this is caused by trying to use an object without prepending 'self' to it, but I don't think I have forgotten it anywhere.
Can someone please tell me what this error means and how to fix it?
Jing Wu
1) BollingerBand indicator needs the arguments moving average type and resolution.
2) To get the upper band value, you should use self.eurusd_bb.UpperBand.Current.Value
3) The forex has the quote bar data with bid/ask price. For example, to get the open of ask price in OnData(self, data), you can use data["EURUSD"].Ask.Open.
4) You should initialize the indicator with self.SetWarmUp() and check if the indicator is ready before retrieving the indicator value.
Matthew Emerson
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!