Hey,
I am creating a hybrid framework algorithm and so far it works as expected until I try to add a limit order as a take profit.
I get trades seeemingly out of nowhere, such as this:
Where at the same candle prices of the same symbol differ 10%. And get quite a lot of these cases.
I am attaching the code. Let me know if you can spot the mistake. Thank you.
Mia Alissi
From the provided code, it seems like the issue might be related to the way limit orders are being placed for taking profit.
In the
OnInsightsGenerated
method, a limit order is placed with a price that is 10% higher than the current price:This limit order is placed immediately after a market order is placed to buy the asset. The limit order is intended to sell the asset when its price increases by 10%. However, in fast-moving markets or in case of price gaps, it's possible that the limit order gets filled at a price significantly different from the intended limit price.
Also, it's important to note that the limit order price is being converted to an integer using
int(takeProfitPrice)
. This could lead to significant rounding errors, especially for assets with high prices. It's recommended to keep the limit price as a floating-point number to maintain precision.Lastly, in the
OnOrderEvent
method, all open limit orders are cancelled when a sell order is filled:This could potentially cancel the limit orders that were intended for taking profit. You might want to add additional checks to ensure that only the intended orders are cancelled.
Please note that these are just potential issues based on the provided code. The actual issue might be different depending on the specific market conditions and the state of the algorithm at the time of order placement.
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.
Vytautas Zukauskas
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!