Sunday, November 9, 2014

Trade duration analysis with QuantSense

One of the fundamental trading problems are the following two.

1. When to open a position?
2. How big the position should be?
3. When to close it?

According to statistics for the most people (including me) "never" is the answer to the first question. But the most people (including me) ignore the statistics. And the most crazy of us use a statistics to beat the statistics we ignore :).

Even if you have an exact strategy which gives you precise answers on all three questions the strategy itself has to be adjusted to follow the market changing conditions. To help you a bit with the third question QuantSense has a special chart. It shows a relation between the trade duration (x-axis) and its profit (y-axis). It is pretty straightforward to see if your timing of closing positions is right or wrong from this chart. Let us see an example:


Here in this chart you see that as an 'age' of my positions goes higher they get more profitable. On the other hand those positions closed after less than 8-10 hours are roughly speaking equally likely loosing and profitable. See the next picture where I marked the interesting time limit by a yellow line.




For the sample of the trades displayed in this chart we can say that an interesting time limit is around 8-10 hours. All positions which were able to survive in the market longer than 10 hours finished with a profit. This is especially good to know if you define a take profit and a stop loss for your positions even if they are not the same for all your positions. It is better to know what will your profit be in the time of opening your position. If you do so and your chart looks as mine what should you do to optimize your future profit? 

Well, the first idea is to simply buy or sell more if your current position in the market passes the time limit. According to this analysis it is highly probable (if you stick with your current way of trading of course), that this position was a good guess and that it will finish with a profit. So open another one in the same direction, depending on how far from the take profit level is the first one. Or the other, less risky approach, would be to start with a smaller position than usually and open the next one in the same direction as soon as the first one passes the time limit. You can see that most of my positions which I have closed before the time limit are distributed around the zero line with sum of profits somewhere around the zero (just a guess). It simply means that if I will follow my current way of trading and if I will close every position before the time limit I will probably finish with a profit around the zero. Therefore it is better to start with a smaller position and as it gets older and passes the time limit just open the next one in the same direction. Remember, that if for example 80% of your positions passing the time limit will be the winning ones you still have 20% of loosing positions. So if you will increase the volume of your positions which pass the time limit you have to remember that there is still a 20% chance that you will loose. So you need to do some additional computations or estimations on how much you can afford to increase the volume in order to be more profitable that you are now. You should also keep the original stop loss for the new positions so your risk will get higher. If this type of analysis shows you that it will be too risky to buy the next position you can think a bit differently. If you are in a position which is already behind the time limit and it looks good (you are in a trend, or over the support for example) just wait for some technical signal for buying the next one otherwise just keep one position and close it as usually.

Take both approaches just as a rough ideas. You have to figure out the details by yourself as they mostly depend on your way of trading.

Now let us see another example. I guess this would be the common one :).



Here you can see that as the 'age' of the positions goes higher more and more of them finish with a loss. This is a typical example of being stuck in the loosing position and hoping that it will possibly turn to profit some day. Well, here in my case, it obviously did not work. So how can I do better?

Similarly, as in previous example, I should try to find some time limit beyond which the most of the positions are the loosing ones. In the next picture I marked one with a yellow line.



Then I know that if I am in a position, no matter if winning or loosing, after this time limit there is a high chance that it will finish with a loss. So the conclusion is to close such a position or at least decrease its volume. Decreasing the volume of the position is probably a good way to go in case that you can not find some precise time limit. If you kinda 'have a feeling' from the chart that the older positions are more likely to loose you can gradually decrease the volume of the position in a few steps in order to minimize the loss as the risk of loosing goes higher with the age of the position.

Let me remind you that QuantSense, since version 1.2.0, supports one click import of results from Meta Trader 4's strategy tester. So if you are working on a strategy just let it run in strategy tester, save the results as a report, import it into QuantSense and check this chart. If you see similar distribution of trades as in my second (loosing) example you can improve your strategy by implementing a time stop loss. It simply means that your algorithm will close the position after the time limit which you have identified in this chart. This kind of optimization is not that easy to do in strategy tester. You have to code your own time analysis in your algorithm. 

Now you do not have to. I did it in QuantSense. Give it a try. It is free and without any ads. To do this type of analysis you do not need to buy any special upgrades. Thanks for reading and happy gambling!

2 comments:

  1. It wasn't a problem to read. "Happy gambling";-), apart from being a thinking person you have a good seance of humor, particularly "No 1".
    Thank you for the Quant Sense alert. I could give it a try, I have tried every thing else;-)
    Have a good one
    P.

    ReplyDelete
  2. Thank you. Looking forward to seeing any feedback from you. I am continuously improving the software so if you have any ideas which might help you in analysis of your trading let me know I can at least try to implement them :). The import of strategy tester results was a user request for example and I am not even sure if there is another application out there which can handle it. So the feedback is important to me. Lubo

    ReplyDelete