I have been live trading my algorithm through Schwab for two weeks now, and just this last Friday, the algorithm will occasionally “forget” it still holds a position. It will buy shares, then sell, but they aren't actually sold. So, while the algorithm holdings don't display any positions, my Schwab account is still holding the shares. This has resulted in some major losses, and I have no idea what's happening. It's odd to me that the algo worked great for weeks without an issue, but Friday and today it has been having problems
Mia Alissi
To help Caleb resolve the issue with his algorithm forgetting positions, we can take the following steps:
Review and Update the
OnData
Method: Ensure that theOnData
method correctly checks the portfolio's invested status before making trades. Use theself.portfolio.invested
property to determine if the algorithm currently holds any positions.Implement Logging in
OnOrderEvent
: Use theOnOrderEvent
method to log order events. This will help track when orders are placed, filled, or canceled, and can provide insights into why the algorithm might not be recognizing positions correctly.Use the
Liquidate
Method: Ensure that theLiquidate
method is used properly to close all positions when needed. This can help prevent discrepancies between the algorithm's internal state and the actual brokerage account holdings.Check for Brokerage Synchronization Issues: Investigate any potential synchronization issues between the algorithm and the Schwab brokerage account. This can include checking for latency or delays in order execution.
Manual Reconciliation: If discrepancies persist, consider stopping the algorithm temporarily to manually reconcile and adjust the Schwab account holdings to match the intended portfolio state.
Contact Support: If the issue continues, contact QuantConnect support with detailed logs and account information for further assistance.
Here's a sample implementation of logging in the
OnOrderEvent
method:This code logs each order event, which can help identify when and why the algorithm might be failing to recognize existing positions.
Sources: Charting and Logging - QuantConnect.com, Getting Started - QuantConnect.com, Logging - QuantConnect.com, Algorithm Control - QuantConnect.com, Order Events - 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.
Ginu K
I am having the same issue. My portfolio holdings are no longer matching what my tradestation account is holding, the trades were even executed from QC…
Caleb Eldredge
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!