# ATR Envelope tfmt4

The Average True Range Envelope system has an entry based on the price breaking out of an upper or lower envelope created by an ATR multiple around a simple moving average. As the price breaks out of the envelope, this EA opens a new position to catch a trend if the price continues to move. The SMA in the middle of the envelopes is used as a trailing exit when the price reaches it. Use our free ATR Envelope indicator on your chart to find the best ATR values when creating the ATR envelopes.

**Note:** The default input values are not optimized. Demo the EA and 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.

### Entries and Pyramiding

Entries occur when the price exceeds the upper or lower envelopes. The EA adds the position as soon as the price goes above the upper envelope or below the lower envelope and does not wait until the following bar. If you set the Max_Units input above 1, additional entries will occur and pyramid in ATR increments specified by the ATR_between_Pyramids input.

### Exits

Exits are trailing with the simple moving average in the middle of the ATR Envelopes. For long positions, the EA exits when the price reaches or goes below the moving average. For short positions, the EA exits when the price reaches or goes above the moving average.

### Position Sizing and Stops

This EA calculates the position sizing using the Percent Volatility method which is directly tied to the stop. The stop uses the ATR_Periods and Stop_Range_ATR inputs to calculate the ATR and then multiply the two values to set the stop distance from the entry price. Stops are not coded into the position but this EA closes out the position if the price reaches the stop value. As additional units are added through pyramiding, the stop moves to correspond to the latest entry price. Using the stop value, the Risk_Percent input, and your account information (tick size, lot size, digits, etc.), the position sizing uses the monetary value of the distance from entry to stop and keeps the number of lots limited to the percentage you specify. This allows every symbol, price, volatility to be treated equally. As your account size changes through profits or drawdowns, the position sizing will account for the change.

### Inputs

**MA_Periods**—The number of bars used to create the simple moving average in the middle of the ATR envelopes.**ATR_Env_Periods**—The number of bars used to create the average true range used for the ATR envelopes.**ATR_Multiples_Env**—The number of ATR multiples (ATR multiplied by this number) to create the upper and lower ATR envelopes/bands.**Risk_Percent**—The percent risked per position if the price reaches the stop. Example: If you want 2% of your equity to be risked per position, enter 2 to this input.**ATR_Periods**—The number of bars to use in the ATR calculation.**Stop_Range_ATR**—This value will be multiplied by the ATR to determine where the stop will be from the entry price. Example: If you want your stop to be set at 2* ATR from the price, enter 2 to this input.**Max_Units**—The maximum number of entries (including the initial entry) as the position gains profits and the EA adds pyramid positions.**ATR_between_Pyramids**—This value will be multiplied by the 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 position sizing calculation would treat your equity as 80% of what it really is to lower your risk until the drawdown is over.