I defined a flag in "Initialize(self)" as "self.traded = False"
The only order-generating code is housed in "OnData" and guarded by:
if not self.traded and not self.Portfolio.Invested:
I must be missing something because on every minute bar a new series of orders is submitted, and I can't logically understand how this could be given the flag.
In fact, to further prevent unwanted behavior, every time this order block of code is run, "self.Liquidate()" is the first method called, so in my mind margin should never become exhausted because the order backlog should never build up enough to cause this.
And self.traded is reset once a day, when my daily consolidator spits out a new bar. The time portion of the consolidator code is as follows: "pivotConsolidator = TradeBarConsolidator(timedelta(days=1))"
I also tried to import a seperate module into "main.py" using "from pivots import carmillaPivots" ... does this functionality not work? I ended up embedding the module as a class method to get it to function.
This is my first backtest, and part of a project family of algorithms I plan to explore to learn the platform.
What am I missing?
P.S To verify I wasn't getting confused with the python language, I've done a few simple exercises such as the following:
'''simple script to test flags etc'''
class QC():
def __init__(self):
self.traded = False
self.invested = False
def m(self):
if not self.traded and not self.invested:
print('Executing trades')
def st(self, traded):
self.traded = traded
print(str(self.traded))
def si(self, invested):
self.invested = invested
print(str(self.invested))
#instantiate class instance
f = QC()
Douglas Stridsberg
Hey,
self.traded == True -> the == operator is a comparison operator - this row basically asks "is self.traded True?". You want it to be "set self.traded to True", so you need to use the = operator instead, just like you're doing in PivotBarHandler().
Link Liang
Hi Ian,
Just want to add, in addition to the operator self.traded == True on line 121, we also need to change the operator on line 122. In general, we use = operator to assign value to a variable.
Ian Larson
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!