Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 4 Expert Advisor | EMAplusWPRv1 1

ACTUAL VERSION : http://codebase.mql4.com/en/code/10413

Expert advisor that trade in the trend of EMA and buy/sell signals get from Williams %R

I have tried to create an Expert advisor that could by traded with 1000 EUR starting equity and to minimize the drawdown. Hope you like it. I appreciate every feedback.

Optimized for EURUSD 5 min

I have removed some bugs, changed position sizing, you define the % of your account you want to risk on a single trade. I added simple trailing stop, if trailingStop = 0, then it is disabled.

You use it on your own risk. I am not responsible for your loss, you have to change, test and optimize it for your purpose.

Inputs:

extern double takeProfit      = 200;      // take profit
extern double maxStopLoss     = 50;       // stop loss

extern double maxLots         = 10;       // max lots per position
extern double maxContracts    = 2;        // max open positions, 2 is optimal for smoother equity

extern double EMA             = 144;      // EMA to identify trend
extern int    iWPRPeriod      = 46;       // Williams' Percentage Range to determine buy/sell signals
       int    iWPRretracement = 30;       // retracement of Williams' Percentage to allow next trade
extern double trailingStop    = 50;       // trailing stop, use 0 to disable trailing stop
extern int    risk            = 2;        // % of account you want to risk on a trade
extern double magicNumber     = 13131;  

Strategy Tester Report

EMAplusWPRv1_1
XTrade-MT4 Demo (Build 229)

SymbolEURUSD (Euro vs US Dollar)
Period5 Minutes (M5) 2010.01.04 00:00 - 2011.02.01 23:55 (2010.01.04 - 2011.02.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterstakeProfit=200; maxStopLoss=50; maxLots=0.1; maxContracts=2; EMA=144; iWPRPeriod=46; trailingStop=50; risk=6; magicNumber=13131;
Bars in test59025Ticks modelled7365767Modelling qualityn/a
Mismatched charts errors8220
Initial deposit1000.00
Total net profit1635.88Gross profit4478.56Gross loss-2842.67
Profit factor1.58Expected payoff3.92
Absolute drawdown22.16Maximal drawdown249.69 (10.77%)Relative drawdown12.99% (188.82)
Total trades417Short positions (won %)198 (67.68%)Long positions (won %)219 (73.52%)
Profit trades (% of total)295 (70.74%)Loss trades (% of total)122 (29.26%)
Largestprofit trade67.23loss trade-39.62
Averageprofit trade15.18loss trade-23.30
Maximumconsecutive wins (profit in money)20 (273.93)consecutive losses (loss in money)6 (-142.17)
Maximalconsecutive profit (count of wins)326.42 (15)consecutive loss (count of losses)-142.17 (6)
Averageconsecutive wins4consecutive losses2

MetaTrader Experts, Indicators, Scripts and Libraries

To use my position sizing increase the maxLots size and define the risk - how many % of your account you want to risk on a single trade.

For position sizing I use the following code:

   minAllowedLot  =  MarketInfo(Symbol(), MODE_MINLOT);    //IBFX= 0.10
   lotStep        =  MarketInfo(Symbol(), MODE_LOTSTEP);   //IBFX= 0.01
   maxAllowedLot  =  MarketInfo(Symbol(), MODE_MAXLOT );   //IBFX=50.00

   balance = AccountBalance();  
   ilo   =  ((balance * risk / 100) / maxStopLoss); 
    
   lots  =  NormalizeDouble(ilo, 0) * lotStep;
   
   if (lots < minAllowedLot)  lots = minAllowedLot;
   if (lots > maxLots)        lots = maxLots;
   if (lots > maxAllowedLot)  lots = maxAllowedLot;

Strategy Tester Report

EMAplusWPRv1_1 + position sizing
XTrade-MT4 Demo (Build 229)

SymbolEURUSD (Euro vs US Dollar)
Period5 Minutes (M5) 2010.01.04 00:00 - 2011.02.01 23:55 (2010.01.04 - 2011.02.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterstakeProfit=200; maxStopLoss=50; maxLots=10; maxContracts=2; EMA=144; iWPRPeriod=46; trailingStop=50; risk=6; magicNumber=13131;
Bars in test59025Ticks modelled7365767Modelling qualityn/a
Mismatched charts errors8220
Initial deposit1000.00
Total net profit4655.80Gross profit13740.16Gross loss-9084.36
Profit factor1.51Expected payoff11.16
Absolute drawdown22.16Maximal drawdown1139.43 (28.08%)Relative drawdown28.08% (1139.43)
Total trades417Short positions (won %)198 (67.68%)Long positions (won %)219 (73.52%)
Profit trades (% of total)295 (70.74%)Loss trades (% of total)122 (29.26%)
Largestprofit trade268.93loss trade-256.75
Averageprofit trade46.58loss trade-74.46
Maximumconsecutive wins (profit in money)20 (353.21)consecutive losses (loss in money)6 (-354.36)
Maximalconsecutive profit (count of wins)1466.13 (15)consecutive loss (count of losses)-664.91 (4)
Averageconsecutive wins4consecutive losses2

MetaTrader Experts, Indicators, Scripts and Libraries

10201

Best MetaTrader Indicators + Profitable Expert Advisors