Moving Avg Exit EA

Posted by admin8277 on April - 19 - 2016
Spread the love

Expert Advisor

Purpose:

To manage trades based on the Moving Average Indicator and Market price

Inputs:

  • MA_ExitMode – possible values include
    • SLOPE_EXIT – use slope direction (up or down) of an MA (typically on a higher timeframe) to cause trade exits
    • MA_CROSS_EXIT – use cross of “fast” and “slow” MAs (moving averages) to cause trade exits
    • PRICE_CROSS_EXIT – use price crossing MA to cause exits
  • MovingAvgTimeFrame – selects the chart time frame used (M1, M5, M15, M30, H1, H4, D1, W1, MN1)
  • TrendMA_Period – specifies the number of price bars used to calculate the Moving Avg. of the Trend MA.  The Trend MA is the Moving Average used in the SLOPE_EXIT and PRICE_CROSS_EXIT trade exit modes (see MA_ExitMode input)
  • TrendMA_Method – specifies the type of averaging desired for the Trend MA (possible values: Simple averaging, Exponential averaging, Smoothed averaging, and Linear Weighted averaging)
  • TrendMAappldPrc – specifies the prices used in calculating the Trend MA (possible values: Close prices, Open prices, High prices, Low prices, Median prices, Typical prices, Weighted prices)
  • FastMA_Period – specifies the number of price bars used to calculate the Fast Moving Avg..  The Fast MA is used in MA_CROSS_EXIT mode
  • FastMA_Method – specifies the type of averaging desired for the Fast MA
  • FastMAappldPrc – specifies the prices used in calculating the Fast MA
  • SlowMA_Period – specifies the number of price bars used to calculate the Slow Moving Avg..  The Slow MA is used in MA_CROSS_EXIT mode
  • SlowMA_Method – specifies the type of averaging desired for the Slow MA
  • SlowMAappldPrc – specifies the prices used in calculating the Slow MA
  • WriteScreenshots – if true will save a screenshot picture whenever trades are exited.  These get stored in the MQL4 Files folder

User Notes: 
Everyone’s heard of using the moving average by itself and with other criteria to help decide when to enter trades. However, they can also be quite useful as a strategy for exiting trades. This EA can be placed on a chart and will use Moving Averages and sometimes price action in one of 3 different ways (depending on the EAs inputs) to exit trades on the chart; manual or otherwise. Regardless of the time frame of the chart the EA is running on, the Moving Avg information from any time frame may be used.
This EA can provide a safety net for active trades and limit losses, when say, a higher time frame Moving Avg., changes direction or crosses another MA, signalling a significant trend change.

Two common mistakes traders make
Mistake #1) not having an Exit strategy in place before they place their trades.
In addition to a trading Entry strategy, it’s always a good idea to have one or multiple trade Exit strategies as well.
This EA provides 3 ways for using a Moving average with or without price action or two moving averages as a basis for Exiting your trades
Through an MA Exit Mode input users may select one of 3 ways to exit their trades based on Moving Averages and price action.
Mistake #2) focusing exclusively on the current time frame for entry and exit conditions. This is somewhat akin to the saying “missing the forest for the trees”. Although a famous cliche it applies to many forms of indicator and pattern based technical trading. Looking at the higher time frames will reveal the longer term trends and patterns that are the context for the shorter term trends and patterns you may be using on the current chart.
Through the EAs timeframe inputs this EA can access the MA slope, and MA crosses occuring on the higher time frames (the current, or smaller time frames may be specified as well). In this way trades going against the direction indicated by the MAs on the higher time frames can be closed.

MA Exit modes
Slope exit – Slope exit mode allows the user to define a “trend” moving average. In slope exit mode the EA checks the recent slope of the Trend MA to determine whether it is currently sloping or turning up or down.
In Slope exit mode, if the recent slope is Up, then the EA will close any Short trades. If the slope is Down, it will close any Long trades.
(In all 3 modes available the MA characteristics can be defined include MA period, chart time frame, MA method, and MA applied price).  See following pictures:

MA Exit EA running in Slope mode on H1 time frame

MA Exit EA running in Slope mode on H1 time frame

Trend MA on H4 time frame

Trend MA on H4 time frame

Trend MA on D1 time frame

Trend MA on D1 time frame

MA Cross exit – MA Cross exit mode. In this mode, the EA uses the Fast and Slow MA inputs with the time frame input to define 2 MAs (a Fast smaller period MA and a Slow MA), to be used.
In MA Cross exit mode, if there is a fresh cross of the Fast MA Above the Slow MA, then any Short trades will be closed. If there is a new cross of the Fast Below the Slow MA, then any Long trades will be closed.  See following pictures:

MA Exit EA running in MA Cross mode on H1 time frame

Fast and Slow MAs shown on H4 time frame

Fast and Slow MAs shown on H4 time frame

Price Cross exit – Price Cross exit mode. In this mode, the EA checks the price versus the Trend MA on the timeframe specified for the Trend MA.
If the price on the last closed bar is Above the Trend MA, then any Short trades are closed. If the last closed price is Below the Trend MA, then any Long trades are closed. See following pictures:

MA Exit EA running in Price Cross mode on H1 time frame

MA Exit EA running in Price Cross mode on H1 time frame

 

System Requirements
To run Metatrader 4 you should be using Windows 2000 or later, with a 2.0 GHz or faster CPU, and at least 512 MB RAM (although 1 GB is recommended). You should have a screen resolution of 1024 x 768 or higher, and an internet connection speed of 56 kbps or faster.

 

2 Responses so far.

  1. ADRIANO STEFANI says:

    HI,
    is it possible to use both the conditions to exit?
    MA_CROSS_EXIT – use cross of “fast” and “slow” MAs (moving averages) to cause trade exits
    PRICE_CROSS_EXIT – use price crossing MA to cause exits

    Thanks

    • admin8277 says:

      Hi Adriano.

      That is currently not an option but I think if you have PRICE_CROSS_EXIT selected it would be the same as an MA And PRICE cross option. This is because a Price cross will always precede an MA cross as the MA is a lagging indicator.

      – Chris