Hey fellow traders! Today, we're diving into an essential tool that can help you sharpen your trading strategy – the Moving Average Expert Advisor (EA) for MetaTrader 4. This EA is designed to generate trade signals using a single moving average, making it a straightforward yet powerful addition to your trading arsenal.
The way this EA works is pretty nifty. It opens and closes trades based on the interaction of the moving average with the latest price bar (that's bar index 1 for you coding aficionados). The lot size for each trade is optimized using a specially designed algorithm, ensuring you’re trading smart.
How the EA Analyzes Market Conditions
- The EA checks if the moving average aligns with the market price chart using the CheckForOpen() function.
- If the moving average is above the opening price but below the closing price, it triggers a BUY order.
- Conversely, if the moving average is below the opening price but above the closing price, it triggers a SELL order.
Simple Yet Effective Money Management
This EA employs a straightforward yet effective money management strategy. It adjusts the volume of each position based on the outcomes of previous trades. This is managed through the LotsOptimized() function. The basic lot size is calculated using your maximum allowable risk:
lot = NormalizeDouble(AccountFreeMargin() * MaximumRisk / 1000.0, 1);
The MaximumRisk parameter represents the risk percentage for each transaction and is typically set between 0.01 (1%) and 1 (100%). For instance, if your free margin is $20,500 and your risk management rules call for a 2% risk, your base lot size would be:
20500 * 0.02 / 1000 = 0.41
It's crucial to ensure your lot size is accurate and normalized to acceptable values. Generally, fractional lots with a step of 0.1 are permitted, so a calculated volume of 0.41 will be rounded down to 0.4 using the NormalizeDouble() function.
Handling Unprofitable Trades
The EA features a DecreaseFactor, which determines how much the lot size will shrink after a series of losing trades. Normal values range from 2 to 5. If your previous trades haven't panned out, the EA will decrease the trade volumes by this factor to help you ride out the rough patches. Here’s how it works:
if(losses > 1) lot = NormalizeDouble(lot - lot * losses / DecreaseFactor, 1);
This mechanism effectively mitigates risks during streaks of unprofitable trades. Before executing the trade, the EA ensures that the lot size adheres to the minimum allowable threshold:
if(lot < 0.1) lot = 0.1;
Optimized for Daily Trading
This expert advisor is primarily designed for daily periods and operates on closing prices. Since it only trades at the opening of new bars, every-tick modeling isn't necessary. You can find the testing results in the report provided, which gives you a clear picture of the EA's performance.
Sample Strategy Tester Report
Strategy Tester Report
Moving Average
Symbol EURUSD (Euro vs US Dollar) Period 1 Hour (H1) 2003.01.08 00:00 - 2003.11.25 00:00 Model Every tick (based on all available least timeframes with fractal interpolation of every tick) Parameters Lots=0.1; MaximumRisk=0.01; DecreaseFactor=1; MovingPeriod=16; MovingShift=11; Bars in test 19371 Ticks modelled 656918 Modelling quality 25.00% Initial deposit 10000.00 Total net profit 1695.20 Gross profit 4293.20 Gross loss -2598.00 Profit factor 1.65 Expected payoff 10.80 Absolute drawdown 40.35 Maximal drawdown (%) 318.50 (3.0%) Total trades 157 Short positions (won %) 73 (26.03%) Long positions (won %) 84 (32.14%) Profit trades (% of total) 46 (29.30%) Loss trades (% of total) 111 (70.70%) Largest profit trade 262.55 loss trade -91.00 Average profit trade 93.33 loss trade -23.41 Maximum consecutive wins (profit in money) 2 (387.15) consecutive losses (loss in money) 7 (-287.25) Maximal consecutive profit (count of wins) 387.15 (2) consecutive loss (count of losses) -287.25 (7) Average consecutive wins 1 consecutive losses 3
Comments 0