MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Source code library - Expert Advisors, Indicators and Scripts

Forget Outdated Indicators and Buy Latest Ones in MetaTrader Market
To post a new code, please log in or register

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2012.01.20 11:21

Break_Lag_ATR - indicator for MetaTrader 5

| English Russian Chinese Spanish Portuguese

votes: 11


A bit enhanced volatility indicator (ATR) for a specified period.

A breakout is deemed to be genuine, if the body of a formed bar exceeds average true range (ATR). ABS (Close-Open) candlesticks body size is displayed as a histogram. Histogram green columns show volatility breakout as a histogram and can serve as signals for market entry/exit/position reversal or position volume increasing.



Translated from Russian by MetaQuotes Software Corp.
Original code:

Last comments | Go to discussion (2)
Sergey Golubev
newdigital | 3 Dec 2013 at 10:58


Indicators: Average True Range (ATR)

newdigital, 2013.08.29 09:18

Average True Range (ATR) Technical Indicator

Developed by J. Welles Wilder

The Average True Range (ATR) indicator is a measure of volatility. The ATR indicator measures the range of price movement for a particular price period. The ATR is a directionless indicator and it does not indicate the direction of the Forex trend.

High ATR values 

High ATR values indicated market bottoms after a sell off.

Low ATR values

Low ATR values indicated extended periods of sideways price movement- Price Range, such as those found at market tops and consolidation periods. Low ATR values are typical for the periods of sideways movement of long duration which happen at the top of the market and during consolidation. 


The ATR is calculated using the following: 

  • Difference between the current high and the current low
  • Difference between the previous closing price and the current high 
  • Difference between the previous closing price and the current low

The final Average is calculated by adding these values and calculating the average. 

The indicator of Average True Range is a moving average of values of the true range

Technical Analysis of True Average  Range (ATR)

True Average Range can be interpreted using the same principles as other volatility indicators.

Possible trend change signal - The higher the value of the ATR indicator, the higher the probability of a trend change;

Measure of trend momentum - The lower the indicator’s value, the weaker the trend movement.

Sergey Golubev
newdigital | 3 Dec 2013 at 10:58


Indicators: ATR_MA_Oscillator

newdigital, 2013.10.23 18:52

An Easy and Advanced Way to Set Stops

Talking Points:

  • Stops are a necessity because no trading strategy wins 100% of the time
  • Traders can use ATR to calculate stop distances based on recent price activity
  • Price Action can be used to set stops in trending, or ranging market environments
As traders, we know we need them, but it’s much like the advice of ‘get your annual checkup with a Doctor,’ where most of us simply don’t want to do it.

But in the field of trading, risk management isn’t just a preference; it’s a necessity.
And the reason for this is simple: Because you cannot tell the future. And this means that no matter how hard you try, or how great a trader you become, you will simply never be able to avoid losing entirely. And as a natural extension of that fact, since you will lose on some trades, having sloppy risk management means that one or two losers can wipe away the gains of many small winners.

I know this may sound too simplistic; but this is exactly what was found to be The Number One Mistake that Forex Traders Make: They often win more frequently than they lose - but they lose so much when they are wrong that it wipes away all of the gains from their winners and then some.

Average losses (in red) far outpace average wins (in blue) :

The first step to avoiding The Number One Mistake Forex Traders Make is to set a stop. This allows you to cap the risk on any one trade, so that if it doesn’t go in your direction, you can stem the bleeding before it becomes too unbearable.

Below, we’re going to look at two popular, yet different ways of setting stops. One easy way that is often employed by professional traders for the sake of simplicity; and another more advanced method that may suit certain trading styles more adequately.

The Easy Way

First off, just because this is an easier way of setting a stop does not make it any less valid. This is classified as ‘the easy way’ simply because most traders can pick this up right now, and begin using it instantly with a minimum of instruction.

Average True Range is a favorite indicator of many professional traders, and one of the great things about it is that it’s rather simple in its design. While many indicators wear multiple hats and try to do a few different things at once, ATR is just a measure of price movements over a specific period of time.

If those movements increase in value, ATR goes up. If those movements decrease, ATR goes down (see below).

ATR measures volatility, and this allows traders to set stops based actual market behavior :

There are a few nuances of ATR that traders need to know before applying. We cover these, in depth in the article Managing Risk with ATR. The first is the format with which the indicator displays values. While it looks like an oscillator like RSI, and moves similar to an indicator like ADX; the real value of ATR is in its value. It will measure the ‘Average True Range’ of the last x periods, where x is the input you choose. The default, and most common input for ATR is 14 periods. The value of ATR will read in the price format of the currency pair being analyzed. So, for instance; if a value of .00760 is shown on EURUSD, that means 76 pips (4th place to the right of the decimal is a single pip in the quote).

ATR displays values in the format of the currency pair’s price :

There is a slightly easier option, and for traders that are using short-term techniques this can be extremely helpful. There is a custom indicator available for Trading Station desktop that automatically calculates, and displays ATR on the chart in a very easy-to-read format. This is completely free, and can be downloaded from the FXCM App Store at this link (link). As you can see below, not only does it display ATR, but it even rounds the ‘.6’ fractional pip as appropriate.

The ‘ATR_Pips’ Indicator displays Average True Range in an easy-to-read format :

The Advanced Way

Price Action can have a huge impact on a trader’s performance. Inclusion of price action into an approach will often take place regardless of the trader or type of trading being done. Price action can help traders read trends, find support and resistance, and perhaps most importantly - manage risks.

Because, after all - if prices are trending higher, and we’re seeing continuous higher-highs, and higher-lows, wouldn’t it be reasonable to consider closing the trade if the trend reversed?
Remember, this is the number one mistake traders make, and this is the reason stops are so important. If the trend reverses, the trader’s best advice is often to close the trade and look for greener pasture elsewhere... because if the reversal continues against the trader, one loss can wipe away a lot of gains.

If traders are trading a trend, they can look to the previous opposing-side swing for stop placement. So, if an up-trend is being traded, we should be able to see higher-highs, and higher-lows. If we are buying to take part in the up-trend, we can look to place our stop below the prior swing-low (see picture).

During an up-trend, stops can be placed below the previous swing-low :

On the other hand, if we’re selling in a down-trend, we would want to look to place our stop above the prior swing-high.

During down-trend, stops can be placed above the previous swing-high

In How to Analyze and Trade Ranges with Price Action, we look at stop placement in
range-bound markets. If a range is being traded, the ‘peak-high’ and ‘peak-low’ should be identified (see below).

Traders can look to place their stop just outside of the peak of the opposing side of their position. So, if buying, traders would look to place their stop just below the peak-low; and if selling just above the peak-high. This way, if the range turns into a breakout against the trader, the bleeding can be stopped before one loser wipes away the gains from a lot of winners.
If you’d like to become a better Price Action trader, we’ve put together the basics into a Brainshark curriculum. The link below will take you directly to the lesson, and after filling in a few pieces of information into the guestbook the session will begin.