Hi all,
I've been attempting to produce the Expert Exits systems discussed in the book Trading Systems and Money Management (found here https://books.mec.biz/tmp/books/n9unrfvy3wsqby9tsj1otkpp3r98kq.pdf).
The system rules are:
I've been having a few issues with the system.
- I've found that the stop market order, upon being triggered, is sometimes duplicated to create a short order when the system only should trade longs.
- When I changed the def OnOrderEvent to logic, found in the backtest, that seemed to make more sense than the original, which I'll attach in the proceeding post, turns the system from a marginally profitable one into a steaming pile of garbage. The only real change I made was for the system to check that the order event is indeed the market order and to save the fill price from this.
- I am not sure exactly which value from the rolling windows to use as not all values are available at the same time. For example, yesterdays high and the preceeding days high. Since the high for the current day isn't available yet, will yesterdays high still be found at self.highWindow[0]? Or will the system take the current days available high and add it to the rolling window at index[0] when they update in OnData? For clarity, the system runs on minutely data consolidated into a daily bar so that positions can be monitored intraday.
If anyone can assist me with these issues, that would be amazing.
Thanks,
Nick
Nicholas Fitzgerald
The original version of the order management logic.
Cole S
Hi Nick,
Some issues i see after running this.
1. You are using a StopMarketOrder for your profit taker. This is causing it to fill in the next minute every time. Switch it to a LimitOrder.
2. You have incorrect indentation causing logic issues starting below. That whole block and the one below it need to unindent.
This will get you on your way, but I think your exit signal is liquidating too much as well, so probably an issue there.
-Cole
Cole S
Backtest with a couple of those issues fixed.
Nicholas Fitzgerald
Hi Cole,
Thank you for that! I thought at some point I'd changed it to a limit order, but it mustn't of saved. I completely missed that.
It's now performing better but still needs plenty of work! I don't suppose you know the answer to my rolling window issue by any chance?
Regards,
Nick
Nicholas Fitzgerald
Hi again Cole,
I'm also curious as to why self.limitMarketTicket = None needs to be declared at Initialise? Why does the code not run with it only appearing in OnData?
Regards,
Nick
Cole S
Hey Nick,
Regarding the self.limitMarketTicket if you don't declare it you will get an attribute does not exist error when you try to check if it is None. Without setting that field in the initialize or somewhere else before you reference it you will get that error because the field does not exist on the object.
As for the window, my experience is that the daily consolidator will not fire until 9:31 AM the next day so that's when you will be setting your rolling window values for the next day. Those values will be the values for the prior day as you are setting them on that consolidator.
-Cole
Nicholas Fitzgerald
Hi Cole,
Makes sense, thank you!
So that means that the current days open will not be available as part of the rolling window?
Regards,
Nick
Cole S
That’s correct Nick. If you want today’s open you would want to grab the open from the first minute bar of the day in OnData.
Nicholas Fitzgerald
Hi Cole,
Thanks for clearing that up!
Is there a way to save that open price to a variable for the day without it updating on each subsequent bar?
Regards,
Nick
Cole S
Hey Nick,
What you could do is put an if statement in on data and check the time is 9:31 (check minute = 31 and hour = 9). In that block you can capture the open price of that bar which is the open price of the day. Then of course you would not want to capture the open in your consolidator since you would now be capturing it in OnData.
Hope that helps.
-Cole
Nicholas Fitzgerald
Hi Cole,
Thank you for that. That seems a much better way than trying to use a scheduled event. Is it then possible to prevent the days trading from beginning before this information has been saved? To prevent trading on the previous days open price?
Would a simple if time is less than or equal to 9:31: return work?
Regards,
Nick
Cole S
Hey Nick,
Yes, you could do it a couple of different ways. You could have a flag you toggle on and off based on whether the data is ready or not or you can just use an if statement based on time as you've said.
Nicholas Fitzgerald
Hi Cole,
Thank you, I went with the if statement for simplicity. As an update, when I changed the logic to match that found in the expert exits system, it performed quite poorly on IBM (backtest below). Experimenting with a few different markets improved the results but not to a trade-able state. I'll attach a backtest on KSS which shows some potential although I'm not sure how to optimise the system further.
Thanks for all your help,
Nick
Nicholas Fitzgerald
KCC Backtest:
Cole S
Hey Nick,
Glad to help. Here are some things to consider:
-Cole
Nicholas Fitzgerald
Hi Cole,
Thank you for the suggestions, I'll try implement a universe of stocks for this strategy to trade on and see how we go from there.
I'm considering implementing a standard deviation volatility stop. I've attempted a simple ATR stop previously, but found it often is worse or only as good as a fixed % stop. Do you have any useful links to how to go about this in quantconnect, or some suggestions for taking this forward? Or perhaps advice as to not go down this route?
Much Appreciated,
Nick
Cole S
Hey Nick,
This is a great article about the theory of it. You'll have to download the Wolfram Alpha CDF player to see his workbook, but it's pretty cool. He basically maps the volatility to a 3d plane so you can visualize the results. From what I recall the rule should be on high volatility we want a tight stop loss and high profit taker and the inverse with low volatility.
Nicholas Fitzgerald
Hi Cole,
Awesome, thats a great resource. I'm currently working on a universe of stocks, as you suggested, looking for increasing revenue over a certain period of time as an indicator of momentum.
Thanks for your continued help!
Regards,
Nick
Nicholas Fitzgerald
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!