Does anyone know how to prevent your algorithm from making more than one trade per day? My algorithm (in Python) is based off a rolling window/consolidating indicator, and I am wondering if it is possible to prevent my algorithm from making more than one market order per day. I know that my Stop Loss/Profit Taking mechanism is just not working and I still don't understand why, but at the moment I would like to limit my algorithm to making one market order per day at the maximum.
Nicholas Stern
In addition, in the OnData area, I want to allow that section of the code to say, if you haven't invested today, and everything there is true, place the market order. Does anyone know how to do this?
Douglas Stridsberg
Hi Nicholas,
If I've read your code correctly, I think this is roughly what it will do on any given day once the market order condition is hit:
Â
At point #9, you have a really weird situation:
Â
What happens if the price now drops below $104.5? You only have 50 shares and you're trying to sell 100 - that's not going to work. What happens if the price goes up to $121? You will hit your limit order and sell the remaining shares, but you'll still have your 2 stop orders alive. I hope this illustrates why the algorithm is not behaving as you expect it to. There are a myriad of ways to solve these issues but you'll have to think about the best way. General tips:
Â
Â
Now onto your second question. How do you prevent the algorithm from trading more than once per day? This can be achieved in many different ways - one of the easiest ones is to simply store the date of the last trade somewhere in your code and check the current date against that saved date. If they're identical, then you don't trade.
Nicholas Stern
Thank you very much for the help Douglas. I'll be working on all that right now.
Nicholas Stern
I also would like to make it so that the algorithm only trades once when the conditions are met. For my algorithm, if I don't write self.Portfolio Not Invested, then my algorithm will trade more than 100 times a day. Any tips on how to accomplish this?
Douglas Stridsberg
Nicholas I gave you tips on that at the end of my last reply.
Nicholas Stern
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!