Hope you guys can help me out, been trying to debug this for over a week. Im a pretty newbie in Python. Im trying to test a simple algo using the one Forex pair.
Im buying when the RSI is below 20 and the currentbar greater than the previousbar on 15 min timeframe. after taking the lesson on trailing stops i have added a trailing stop but i get the following error. My code is pretty messy so any feedback is more than welcome
Runtime Error: AttributeError : 'NoneType' object has no attribute 'Update'
at OnData in main.py:line 51 :: self.stopMarketTicket.Update(updateFields)
AttributeError : 'NoneType' object has no attribute 'Update' (Open Stacktrace)
Derek Melchin
Hi Lakith,
This error arises because in the algorithm above, the logic makes it possible for us to call
self.stopMarketTicket.Update(updateFields)
before we've created the ticket with
self.stopMarketTicket = self.StopMarketOrder("EURUSD", -5000, 0.9 * self.Securities["EURUSD"].Close)
To resolve this, we can change
else:
to
elif self.Portfolio["EURUSD"].Invested:
See the attached backtest for reference.
Best,
Derek Melchin
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.
Lakith Lankaputhra
Thank Derek. It worked and not getting the error anymore. But my algo does seems to close any trades.
What i had hoped it have programmed was that once the trade has been initiated the intial stop would be placed at 0.9 from the entry and the trailing stop would move up to 0.9 less the last bars close price.
But when i ran the algo it doesnt seem to close any trades and whole backtesting time would run with only one trade triggers.
Thank you,
Lakith
Derek Melchin
Hi Lakith,
The reason the algorithm above only makes 1 order is because the stop loss is placed too far away from the spread.
See the attached backtest for reference. We change the stop loss placement from 90% of the security price to 98%.
Best,
Derek Melchin
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.
Lakith Lankaputhra
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!