A week ago, I’ve determined the main idea for my ATC 2011 expert advisor. Today, it’s about time to shed some light over a very important but often overlooked concept in EA optimization — Z-Score. But before I describe my experience in applying Z-Score optimization, it’d be wise to explain a bit more about this interesting performance indicator.
What is Z-Score?
Z-Score (or Standard Score) measures the distance between the mean of some set of the statistical results and the given observation. For Forex systems, it measures the dependence between a previous position and the next position outcome. If we consider profitable positions as positive results and losing positions as negative statistical results, counting the total amount of all wins, losses, overall positions, as well as the number of win and loss streaks, we can calculate Z-Score for a given trading strategy or expert advisor. Usually, Z-Score fluctuates between -3 to +3, but sometimes can go above and below these “limits”. Z-Score value of 0 means that we are dealing with completely random results. Each Z-Score value has also a Probability of Dependence associated with it, which informs us of how probable is dependence between the trades. Values below -2 and above 2 have high (>95%) probability of dependence between trades. Positive Z-Score means that profitable position is likely to be followed by a losing one, while a losing one should probably be followed by a winning one. Negative Z-Score means that profitable positions are likely to be followed by more profitable positions, and losing positions are to be followed by more losing positions.
How To Use Z-Score in Forex?
If you know Z-Score of your expert advisor or trading system and its value is above +2 or below -2, you can “skip” a trade when a losing position is expected. Nevertheless, the profit on this “skipped” position should be tracked (virtually), to know when to start trading again.
You can see your Z-Score by loading your trading report into Forex report analyzer (beta).
My Z-Score Optimization
In my last RTATC2011 entry, I’ve mentioned that my EA works well with 2 currency pairs — EUR/GBP and EUR/AUD. I’ve tested them both on a new period — from 2011.01.01 till 2011.07.01. EUR/AUD showed Z-Score at -0.65, which isn’t a good value for optimization, so it was skipped. EUR/GBP, on the other hand, showed Z-Score at +3.02, which means that profitable and losing positions are likely to appear in an alternating order.
I’ve modified the code of my expert advisor to stop sending real orders when a profitable position is closed. The EA then enters a ”virtual mode”, where position is opened and tracked only virtually (using MQL variables). When such position is closed (also virtually), its profit/loss is considered — if it’s a loss, real trading is enabled once again, if it’s profitable, operation in virtual mode should be continued. This is how it should be done for the positive Z-Score. Of course, it can be easily modified to work with negative Z-Score.
The result was above my expectations — profit went up from $20,102.47 to $67,638.23, while maximum drawdown reduced from 51.59% to 36.59%. Of course, it’s still far from the profit usually required to win in ATC (especially, considering that it’s for 6 full months rather than less than 3 months of the contest), but it’s a great improvement over initial profit.
You can download the EA used in this test:
Reports before and after optimization:
This scheme of Z-Score optimization implies that you measure your Z-Score on a backtest and then consider that it won’t change much during the live run in future. Alternative plan would be to implement a constant measuring of Z-Score in your EA and adjust the optimization on-the-fly. The problem is that it’s quite difficult to implement this in real expert advisor and even if you do that, the EA may become to slow to participate in ATC.
When proportion of the winning and losing positions is very uneven, Z-Score optimization may be a bit tricky and it’s probably better to make it asymmetrical (favoring less rare outcomes) or skip completely, even if Z-Score is above/below +2/-2.
In the next issue of my Road to ATC 2011 journal I will create a single EA that will be able to trade EUR/AUD and EUR/GBP at the same time.
P.S.: 2 months and 21 days left to register in ATC 2011. 778 participants registered so far.
If you have any questions regarding my use of Z-Score to optimize expert advisors or if you want to suggest another idea for using Z-Score, please reply using the form below.