Quadruple Moving Average Expert Advisor
.mq5 file for $99
This Expert Advisor in .mq5 format has fully commented code to let you test, customize, and automate a four moving average (MA) trading system in MetaTrader 5. Using four moving averages to confirm direction, entries occur when the fastest MA is outside the 2nd fastest MA, the 2nd fastest MA is outside the 2nd slowest MA, and the 2nd slowest MA is outside of the slowest MA. Exits occur when the fastest MA crosses back over the 2nd fastest MA.
A quick visual example to show approximate entry and exit areas (arrows manually added):
Note: The default input values are not optimized. Demo the EA for free or buy a compiled version (.ex5 file - cannot see or modify the EA code) at the MQL Market. Adjust the inputs to find the optimized combination for your risk tolerance and to maximize profitability. Trend Following systems are designed around long term probabilities. Although Trend Following systems have lower win rates, profitability comes from large trends as Trend Following cuts losses short and lets winners run. Test on a portfolio of symbols as profits from trending symbols will offset the small losses and provide profits when other symbols are not trending.
- Shortest_MA - Set the timeframe of the shortest (least bars/candles) moving average. Example: For the 5/12/20/40 setup, enter 5 to this input to use the 5 bar moving average.
- Short_Mid_MA - Set the timeframe of the shorter (less bars/candles) moving average that is more bars than the shortest but less bars than the Long_Mid_MA variable. Example: For the 5/12/20/40 setup, enter 12 to this input to use the 12 bar moving average.
- Long_Mid_MA - Set the timeframe of the longer (more bars/candles) moving average that is less bars than the longest but more bars than the Short_Mid_MA variable. Example: For the 5/12/20/40 setup, enter 20 to this input to use the 20 bar moving average.
- Longest_MA - Set the timeframe of the longest (most bars/candles) moving average. Example: For the 5/12/20/40 setup, enter 40 to this input to use the 40 bar moving average.
- Risk Percent - The percent risked per position if stop is hit. Example: If you want 2% of your equity to be risked per position, enter 2 to this input.
- ATR Periods - Periods to use to calculate Average True Range. Example: If you want a 14 day ATR, enter 14. 10 day ATR, enter 10.
- Stop Range ATR - Multiples of ATR to use for calculating the stop. Example: If you want your stop to be set at 2* ATR from the price, enter 2 to this input.
- Max Units - Max number of positions to have at one time. Example: If you only want to pyramid to 5 positions, enter 5 to this input. If you do not want to pyramid positions, enter 1 to this input.
- ATR between Pyramids - Multiples of ATR to use for calculating when to add the next position through pyramiding. Example: Set this to 1.5 and the next pyramid position would be added when the price reaches your entry plus ( 1.5 * ATR ) for long positions or entry minus ( 1.5 * ATR ) for short positions.
- Slippage - Amount of allowable slippage when entering position.
- Reduction Percent - Enter an amount by which to reduce your equity for the position sizing calculation. Example: If you are in a drawdown period you can enter 20 to this input and the position size will be 20% less than without the reduction. The calculation would treat your equity as 80% of what it really is to lower your risk.
Trade on any pair and any timeframe. Place the expert advisor on a chart and it will use the currency pair and timeframe of the chart. Choppy and sideways markets will cause more whipsaws while markets that trend will produce more profitable trades.
Long positions are entered when the fastest/shortest MA is above the 2nd fastest/shortest MA, the 2nd fastest/shortest MA is above the 2nd slowest/longest MA, and the 2nd slowest/longest MA is above the slowest/longest MA. Short positions are entered when the fastest/shortest MA is below the 2nd fastest/shortest MA, the 2nd fastest/shortest MA is below the 2nd slowest/longest MA, and the 2nd slowest/longest MA is below the slowest/longest MA. Both long and short use the closed MA of the previous bar. If you set the Max Unit variable above 1, additional entries will occur and pyramid in ATR increments specified by the ATR between Pyramids variable.
This expert advisor uses Percent Volatility position sizing. Verify the tick value, minimum and maximum lot sizes, size of lot increments, etc to confirm each position will not exceed your set risk percentage. Using the stop level, if the position is stopped out, the position size is calculated to only lose the amount risked through the Risk Percent variable. The calculation looks at how many dollars are at risk, how many pips are in the distance from the entry to the stop and the value of that distance.
The stop is set using multiples of the ATR. Basing the stop on the ATR allows the stop to be placed out of the normal price range and account for volatility. If you choose 2 times the 14 day ATR, the stop on long positions would happen if the price touches or goes below the entry price minus ( 2 * ATR ). The stop on short positions would occur if the price touches or goes above the entry price plus ( 2 * ATR ). The stop is set when the position is entered. The stop accounts for gaps in price and is not set as a pending order. A position is only stopped out if the price reaches or exceeds the stop level. If you use the pyramiding option, the stop will change to be in line with the latest entry price when a new position is added.
Positions are closed when the fastest MA closes across the 2nd fastest MA or in other words, the fastest MA crosses the 2nd fastest MA. Using the 5/12/20/40 example, long positions exit when the 5 bar MA closes below the 12 bar MA and short positions exit when the 5 bar MA closes above the 12 bar MA. The exit uses the closed MA of the previous bar.
Once you complete checkout through Paypal, you will receive an automated email with the download link. The email will go to the email address that is on file with Paypal - make sure Paypal has your current and correct email address. The download link will be active for 24 hours so please download as soon as you get the link. The expert advisor comes as the MQL5 code so you will have to save it in the correct folder, read through the notes in the code, and compile it. After compiling it, start testing and finding your profitable variables. Use the installation tips page to get the file saved and compiled so you can start testing today.