How to increase profit and decrease risc with trade filtering

To add comments, please log in or register
lutade
17
lutade  

This is a follow up to the recent article Be In-Phase by Mikhail Korolyuk. As my comments would be too extensive to add there and the topic is (as I think) of general interest, I decided to start a new thread here. This is to be seen also as a attempt to contribut something to the MQL4 community, as I am grateful for the software and all the articles and I would like to "give something back".

Mikhail Korolyuk writes in his article

"There is a whole group of methods that ... allow us on the basis of this analysis to filter some trades, the risk for which exceeds the limits determined by the trader. Applying filters on the basis of capital curve analysis allows us to reduce the trading risk. However, the reverse of this medal is decreasing in return of the system, because its trades have, all in all, a positive expected payoff, and the group of riskier trades selected using filters usually has a positive expected payoff, as well."

Maybe the folowing will be natural for the professional trader, but I hope for some of you this may be an unknown method.

Assume you have an EA, which gives you a reasonable number of trades with a reasonable profit. Most EAs will have some condition similar to the following, which is from the code of my sample EA:

MA1=NormalizeDouble(iMA(NULL, PERIOD_M5, 3, 0, MODE_SMA, PRICE_CLOSE, 1),Digits);
MA2=NormalizeDouble(iMA(NULL, PERIOD_M5, 3, 0, MODE_SMA, PRICE_CLOSE, 2),Digits);
if (MA2>MA1)
{ LS=GetLotSize();
  if (LS>0) OrderSend(Symbol(),OP_SELL,LS,Bid,3,Bid+SL_Sell*Point,Bid-TP_Sell*Point,"",0,0,Red);
}

A reasonable assumption is that the greater the difference between MA1 and MA2, the greater is the probability that the trade will make profit. In order to open only positions when there is a higher probability of winning, a filter could be applied:

MA1=NormalizeDouble(iMA(NULL, PERIOD_M5, 3, 0, MODE_SMA, PRICE_CLOSE, 1),Digits);
MA2=NormalizeDouble(iMA(NULL, PERIOD_M5, 3, 0, MODE_SMA, PRICE_CLOSE, 2),Digits);
if (MA2-MA1>Filter*Point)
{ LS=GetLotSize();  
  if (LS>0) OrderSend(Symbol(),OP_SELL,LS,Bid,3,Bid+SL_Sell*Point,Bid-TP_Sell*Point,"",0,0,Red);
}

This will increase the profit factor, but unfortunatelly will also decrease the number of trades and the overall profit, because the filtered trades would have been profitable too, on average:

The solution should be to use for the trades with a higher probability of winning a higher lotsize and for the trades with a smaller probability of winning a smaller lotsize. The code would be similar to the following:

MA1=NormalizeDouble(iMA(NULL, PERIOD_M5, 3, 0, MODE_SMA, PRICE_CLOSE, 1),Digits);
MA2=NormalizeDouble(iMA(NULL, PERIOD_M5, 3, 0, MODE_SMA, PRICE_CLOSE, 2),Digits);
if (MA2>MA1)
{ if (MA2-MA1>Filter*Point)
  { LS=GetLotSize(1.0);
    if (LS>0) OrderSend(Symbol(),OP_SELL,LS,Bid,3,Bid+SL_Sell*Point,Bid-TP_Sell*Point,"",0,0,Red);
  }
  else
  { LS=GetLotSize(Factor);
    if (LS>0) OrderSend(Symbol(),OP_SELL,LS,Bid,3,Bid+SL_Sell*Point,Bid-TP_Sell*Point,"",0,0,Red);
  }
}
// ...
double GetLotSize(double f)                                           
{ double s=NormalizeDouble((AccountEquity())*f*Perc/100/1000,1);
  //...
}

The variable Factor should have a value between 0 and 1 and can be used as an extern variable for better optimization. For my sample EA I found the best results when using a value of Filter=2 and Factor between 0.4 and 0.5:

Note, that the best results with applied filter have less drawdown and more profit than the best unfiltered results (rows at the end of the list with Filter=0 or Factor=1). It is also possible to estimate the "best" Factor value by using the Kelly formula. From the filtered and unfiltered trades I get the following data:

Trades PT LT %PT GP GL AP AL PF
Unfiltered 167 109 58 65.27% 37321 21697.9 342.39 374.10 1.72
"good" trades 80 56 24 70.00% 19665.8 8982.3 351.18 374.26 2.19
"bad" trades 87 53 34 60.92% 17665.2 12715.6 333.31 373.99 1.39

Using the data in my online simulator I get as optimal Lotsize-ratio 4.56:10.16 = 0.45:1, i.e. the Factor should be 0.45, which is in accordance with the result of the optimizer. Now due to the smaller lotsize the overall profit is reduced, however it is possible to increase the Perc -value for the lotsize calculation. Using the online simulator again (here with other parameters in the url string) gives an estimation that for the same risk the Perc value can be increased by (10.16-7.3)/7.3*100%=39.2%. The following table shows, that using the EA with filtered and lotsize-adjusted trades results in more profit with less drawdown:

Filter-Perc Total net profit Absolute DD Maximal DD Relative DD PF
Unfiltered-5% 11304.46 1184.44 14.14% 14.14% 1.83
Filtered-7% 14283.60 455.37 6.53% 10.42% 2.00
Unfiltered-20% 137998.93 4444.64 22.17% 49.28% 1.95
Filtered-24% 152176.22 1894.80 21.20% 32.56% 2.04

Here is a picture of the balance curve from January 2008 until now when using the EA with filtered trades and Perc=7% (backtest):

The parameters of the sample EA had been optimized for the period from April 2008 until now (July). Later it was tested, if and how it works for the time before April, and as can be seen, it would have made small losses there. This is what I also expect for the future, when someday the parameters don't fit anymore to the market conditions. Then it is important, that the losses will be small, before the EA can be disabled or the parameters adjusted. The data here suggest, that the unavoidable losses will be smaller when using the filter method.

I hope I had something new for some of you fellow traders. Please excuse possible grammar or spelling errors, english is not my native language.

JMB9922
28
JMB9922  
lutade wrote >>

This is a follow up to the recent article Be In-Phase by Mikhail Korolyuk. As my comments would be too extensive to add there and the topic is (as I think) of general interest, I decided to start a new thread here. This is to be seen also as a attempt to contribut something to the MQL4 community, as I am grateful for the software and all the articles and I would like to "give something back".

Mikhail Korolyuk writes in his article

"There is a whole group of methods that ... allow us on the basis of this analysis to filter some trades, the risk for which exceeds the limits determined by the trader. Applying filters on the basis of capital curve analysis allows us to reduce the trading risk. However, the reverse of this medal is decreasing in return of the system, because its trades have, all in all, a positive expected payoff, and the group of riskier trades selected using filters usually has a positive expected payoff, as well."

Maybe the folowing will be natural for the professional trader, but I hope for some of you this may be an unknown method.

Assume you have an EA, which gives you a reasonable number of trades with a reasonable profit. Most EAs will have some condition similar to the following, which is from the code of my sample EA:

A reasonable assumption is that the greater the difference between MA1 and MA2, the greater is the probability that the trade will make profit. In order to open only positions when there is a higher probability of winning, a filter could be applied:

This will increase the profit factor, but unfortunatelly will also decrease the number of trades and the overall profit, because the filtered trades would have been profitable too, on average:

The solution should be to use for the trades with a higher probability of winning a higher lotsize and for the trades with a smaller probability of winning a smaller lotsize. The code would be similar to the following:

The variable Factor should have a value between 0 and 1 and can be used as an extern variable for better optimization. For my sample EA I found the best results when using a value of Filter=2 and Factor between 0.4 and 0.5:

Note, that the best results with applied filter have less drawdown and more profit than the best unfiltered results (rows at the end of the list with Filter=0 or Factor=1). It is also possible to estimate the "best" Factor value by using the Kelly formula. From the filtered and unfiltered trades I get the following data:

Trades PT LT %PT GP GL AP AL PF
Unfiltered 167 109 58 65.27% 37321 21697.9 342.39 374.10 1.72
"good" trades 80 56 24 70.00% 19665.8 8982.3 351.18 374.26 2.19
"bad" trades 87 53 34 60.92% 17665.2 12715.6 333.31 373.99 1.39

Using the data in my online simulator I get as optimal Lotsize-ratio 4.56:10.16 = 0.45:1, i.e. the Factor should be 0.45, which is in accordance with the result of the optimizer. Now due to the smaller lotsize the overall profit is reduced, however it is possible to increase the Perc -value for the lotsize calculation. Using the online simulator again (here with other parameters in the url string) gives an estimation that for the same risk the Perc value can be increased by (10.16-7.3)/7.3*100%=39.2%. The following table shows, that using the EA with filtered and lotsize-adjusted trades results in more profit with less drawdown:

Filter-Perc Total net profit Absolute DD Maximal DD Relative DD PF
Unfiltered-5% 11304.46 1184.44 14.14% 14.14% 1.83
Filtered-7% 14283.60 455.37 6.53% 10.42% 2.00
Unfiltered-20% 137998.93 4444.64 22.17% 49.28% 1.95
Filtered-24% 152176.22 1894.80 21.20% 32.56% 2.04

Here is a picture of the balance curve from January 2008 until now when using the EA with filtered trades and Perc=7% (backtest):

The parameters of the sample EA had been optimized for the period from April 2008 until now (July). Later it was tested, if and how it works for the time before April, and as can be seen, it would have made small losses there. This is what I also expect for the future, when someday the parameters don't fit anymore to the market conditions. Then it is important, that the losses will be small, before the EA can be disabled or the parameters adjusted. The data here suggest, that the unavoidable losses will be smaller when using the filter method.

I hope I had something new for some of you fellow traders. Please excuse possible grammar or spelling errors, english is not my native language.

Can I get a Copy of the EA Please

JMB9922@yahoo.com

thanks

Zeus Consulting Group LLC
132
James Malwitz  
IM A NOOBIE WHEN IT COMES TO TRADING AND I AM TRYING MY BEST AT CODING, THIS SEEMS TO BE A SOUND METHOD OF LOTSIZE CALCULATION, NOW IM CURIOUS AS TO HOW TO MAKE IT FIT WITH A MM PRINCIPLE. THANKS GOOD LUCK
Brian Dee - Random Trader
1759
Brian Dee - Random Trader  

This is a very useful general method

I use a variation of this on several EA's

These are trend-followers that place orders with larger lots when the trend is stronger

FWIW

-BB-

Beto
11
Beto  


I'm fairly new to Forex (as well as to EA development), and I promised myself I was only going to open a live account and start trading Forex when I could develop my own EA, at least a reasonable one.


So I was struggling (for about a month) with PFs of less than 2.0... I was about to go crazy... Till I found this article... Due to all the awesome tips provided, I am now able to finally open a live account and start trading with confidence.


Lutade, thank you so much for sharing such brilliant (yet simple) strategy !!! =) I wish you all the best. Thanks, once again.


Helmut
411
Helmut  
lutade:

This is a follow up to the recent article Be In-Phase by Mikhail Korolyuk.

In the article Mikhail Korolyuk says...

“Knowing the value of %Win for the last 20 trades, we can use the above formula to find the value of Avg.Win/Avg.Loss that would correspond with it on the safety curve. We will determine the ratio between the real value of Avg.Win/Avg.Loss for the last 20 trades and this "safe" Avg.Win/Avg.Loss value as trading system safety factor (TSSF).”

Call the values AvgWin/AvgLoss Zero_W, Safe_W and Real_W respectively. so that:

Zero_W = (100% - %Win) / %Win

Safe_W = (100% -( %Win-10%)) / (%Win-10%) + 1

Real_W = actualAvgWin/actualAvgLoss

Then TSSF = Real_W/Safe_W is correct by the definition of a safety factor.

However, it doesn’t tell us when Real_W is so close to the Zero_W line as to discourage us from taking a position. This information is given by what I would call the Trade Encouragement Factor, TEF:

TEF = (Real_W-Zero_W)/(Safe_W-Zero_W)

Clearly, when TEF is negative or a very small positive value, trading would be discouraged.

The TEF could be used in a money management regime by multiplying the percentage of risk we are willing to take when TEF = 1 with the actual TEF and plugging the result into the MM formula that calculates lot size from risk percentage, available account balance and stop loss.

Anthony Garot
4285
Anthony Garot  

I realize this post is many years old, but I was wondering if anyone still has access to the original "Be In-Phase" article by Mikhail Korolyuk. I am curious to read it.

Fernando Carreiro
5066
Fernando Carreiro  
Anthony Garot: I realize this post is many years old, but I was wondering if anyone still has access to the original "Be In-Phase" article by Mikhail Korolyuk. I am curious to read it.

Yes! No matter the site (well, almost all the sites), you can use "WayBackMachine" (a Website Archive), to search for archives of old websites or pages.

In this case: https://web.archive.org/web/20140210034343/http://championship.mql4.com/2008/news/366

News - Automated Trading Championship 2008
  • web.archive.org
Great article, but please post again the formula for the
Anthony Garot
4285
Anthony Garot  
Fernando Carreiro:

Yes! No matter the site (well, almost all the sites), you can use "WayBackMachine" (a Website Archive), to search for archives of old websites or pages.

In this case: https://web.archive.org/web/20140210034343/http://championship.mql4.com/2008/news/366

Perfect! Thank you Fernando.
Fernando Carreiro
5066
Fernando Carreiro  
Anthony Garot: Perfect! Thank you Fernando.
You are welcome!
To add comments, please log in or register