Skip to main content
BTC / USDTCRYPTO107,400+2.19%ETH / USDTCRYPTO3,840+2.13%SOL / USDTCRYPTO182.40−1.99%BNB / USDTCRYPTO652.30+0.66%XRP / USDTCRYPTO2.2150+1.61%DOGE / USDTCRYPTO0.3850−1.79%TON / USDTCRYPTO5.240+2.34%AVAX / USDTCRYPTO42.60−2.07%LINK / USDTCRYPTO22.40+2.28%ADA / USDTCRYPTO1.0520−1.68%TRX / USDTCRYPTO0.3300+0.92%DOT / USDTCRYPTO8.420+2.93%BTC / USDTCRYPTO107,400+2.19%ETH / USDTCRYPTO3,840+2.13%SOL / USDTCRYPTO182.40−1.99%BNB / USDTCRYPTO652.30+0.66%XRP / USDTCRYPTO2.2150+1.61%DOGE / USDTCRYPTO0.3850−1.79%TON / USDTCRYPTO5.240+2.34%AVAX / USDTCRYPTO42.60−2.07%LINK / USDTCRYPTO22.40+2.28%ADA / USDTCRYPTO1.0520−1.68%TRX / USDTCRYPTO0.3300+0.92%DOT / USDTCRYPTO8.420+2.93%
Fiyatlandırma

ATR (Average True Range)

Volatility gauge for sizing stops and positions — TradeStation, MetaStock and MT5 code.

ATR averages the true range (the largest of high–low, high–prevclose and low–prevclose) over N bars. It measures how much an instrument typically moves per bar, so traders size stops and positions to current volatility instead of a fixed number of pips. Copy the version for your platform.

EasyLanguage
inputs: Length(14);
variables: MyATR(0);
MyATR = AvgTrueRange(Length);
Plot1(MyATR, "ATR");
MetaStock
{ATR - Average True Range, period 14}
atrVal := ATR(14);
atrVal
MQL5 · ATR.mq5
#property indicator_separate_window
#property indicator_buffers 1

input int ATR_Period = 14;
double AtrBuffer[];

int OnInit() {
  SetIndexBuffer(0, AtrBuffer);
  IndicatorSetString(INDICATOR_SHORTNAME, "ATR(" + IntegerToString(ATR_Period) + ")");
  return INIT_SUCCEEDED;
}

int OnCalculate(const int rates_total, const int prev_calculated,
  const datetime &time[], const double &open[], const double &high[],
  const double &low[], const double &close[], const long &tick_volume[],
  const long &volume[], const int &spread[]) {
  for (int i = prev_calculated; i < rates_total; i++)
    AtrBuffer[i] = iATR(NULL, 0, ATR_Period, i);
  return rates_total;
}

To use it inside dtcharts, paste any version into the Script Converter and it becomes a native indicator on your chart.