Hi guys, I'm pretty new to Algorithmic trading and I'm having some trouble with the backtest for this particular project I'm working on. I'm trying to build an algorithm that's able to identify candlestick shapes without using the LEAN built-in functions and then use those to make trade decisions, along with the MACD.
Any idea why my backtests show no data? It doesn't even get the cash right… I'm wondering if I did something wrong in my code. Any help appreciated!
Shane Vivek
This is my backtest btw
Mia Alissi
From the code you've shared, there are a few potential issues that might be causing your backtests to show no data:
In your
OnDatamethod, you're checking ifself.symbolis inself.Portfolio.Keysbefore placing any trades. However,self.symbolwill always be inself.Portfolio.Keysbecause you've added it to your algorithm in theInitializemethod. This means that your trading logic might never be executed. You might want to check if you have any open positions forself.symbolinstead. You can do this withself.Portfolio[self.symbol].Invested.In your
CheckCandlemethod, you're callingCheckBullandCheckBearwithout theselfkeyword, which will cause aNameErrorbecause Python will think thatCheckBullandCheckBearare global functions, not methods of your algorithm class. You should call these methods asself.CheckBullandself.CheckBear.Similarly, in your
CheckCandlemethod, you're callingRollCandleStateswithout theselfkeyword. You should call it asself.RollCandleStates.In your
CheckCandlemethod, you're checking if'Engulfing'is inself.candle_states[0]. However,self.candle_states[0]is a string, not a list, so this check will always returnFalseunlessself.candle_states[0]is exactly'Engulfing'. If you want to check if any of the strings inself.candle_statescontain'Engulfing', you should iterate overself.candle_statesand check each string individually.Finally, you're not doing anything with the
sizevariable in the last line of yourCheckCandlemethod. If you're not using this variable elsewhere in your code, you can remove this line.Here's how you can fix these issues:
I hope this helps! Let me know if you have any other questions.
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.
Shane Vivek
Shane Vivek
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!