Summary
The Supertrend indicator is a popular tool among traders, based on the Average True Range (ATR). It helps identify market trends and aids in making trading decisions. It indicates when a trend is present, when it reverses, and can be used as a basis for entry and exit signals. In this article, you will learn how the Supertrend indicator works, how it is calculated, and how you can effectively use it.
Top 3 Key Takeaways
- The Supertrend indicator is based on the Average True Range (ATR) and helps identify market trends and trend reversals.
- It can be used as a signal for entry and exit points, as well as a stop-loss management tool.
- Its simplicity makes it ideal for trend-following strategies, but false signals can occur in volatile markets.
Table of contents
Click for open/close
- What is the Supertrend Indicator?
- Advantages of the Supertrend Indicator
- Application of the Supertrend Indicator
- How is the Supertrend Indicator Calculated?
- How to Read the Supertrend Indicator?
- Supertrend Indicator and Volatility
- Recommended Settings for the Supertrend
- MQL Code
- FAQs about the Supertrend Indicator
What is the Supertrend Indicator?
The Supertrend indicator displays the trend of a price movement while taking market volatility into account. It is calculated using the ATR (Average True Range) and is a useful tool for determining the direction of a trend. Unlike moving averages or trendlines, the Supertrend provides additional information by factoring in volatility.
Advantages of the Supertrend Indicator
- It reliably identifies trends in a market and helps trade in the direction of the trend.
- It can be used in trend reversal strategies to spot potential trading opportunities.
- It supports risk management by being used as a stop-loss or trailing stop tool.
Application of the Supertrend Indicator
The Supertrend indicator is particularly useful for:
- Trend-following strategies: When the trend is clear, the Supertrend can be used as an entry and exit signal.
- Trend reversal strategies: Once the trend changes, the Supertrend signals it, offering a chance to reposition.
- Risk management: The indicator can be used as a stop-loss or trailing stop to limit losses and secure profits.
How is the Supertrend Indicator Calculated?
The calculation of the Supertrend indicator is done using the following formulas:
- Upper line: (High + Low) / 2 + Multiplier × ATR
- Lower line: (High + Low) / 2 - Multiplier × ATR
The Multiplier and ATR period can be adjusted by the trader to modify the sensitivity of the indicator.
How to Read the Supertrend Indicator?
Reading the Supertrend indicator is simple:
- If the candles are above the line, it indicates an uptrend.
- If the candles are below the line, it signals a downtrend.
- A switch of the line from bottom to top or vice versa indicates a trend reversal.
Supertrend Indicator and Volatility
An important aspect of the Supertrend indicator is its reliance on volatility. Since the indicator is based on the ATR, it dynamically adjusts to market fluctuations. However, during volatile phases, false signals may occur. Therefore, it is recommended to use the Supertrend in combination with other indicators like moving averages or oscillators for better signals.
Recommended Settings for the Supertrend
The most commonly used settings for the Supertrend indicator are:
- ATR period: 10 or 14
- Multiplier: 3 or 4
Depending on the market and personal preference, these parameters can be adjusted to modify the indicator's sensitivity.
MQL Code
#property version ""
#property strict
#property indicator_chart_window
#property indicator_color1 clrBlue
#property indicator_color2 clrMagenta
#property indicator_width1 4
#property indicator_width2 4
#property indicator_buffers 3
double TrendUp, TrendDown, TrendResult;
int changeOfTrend;
input string IndicatorName="SUPERTREND"; //Objects Prefix (used to draw objects)
extern double ATRMultiplier=3.0; //ATR Multiplier
extern int ATRPeriod=20; //ATR Period
extern int ATRMaxBars=1000; //ATR Max Bars (Max 10.000)
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- indicators
IndicatorSetString( INDICATOR_SHORTNAME, IndicatorName);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, indicator_width1);
SetIndexLabel(0, "Trend Up");
SetIndexBuffer(1, TrendDown);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, indicator_width2);
SetIndexLabel(1, "Trend Down");
SetIndexBuffer(2, TrendResult);
SetIndexStyle(2, DRAW_NONE);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit( const int reason){
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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){
int limit, i, flag, flagh, trend;
double up, dn, medianPrice, atr;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
limit= Bars-counted_bars;
if( Bars < ATRMaxBars+2+ATRPeriod) ATRMaxBars= Bars-2-ATRPeriod;
if(ATRMaxBars < =0){
Print("Need more historical data to calculate the Supertrend");
return 0;
}
for (i = ATRMaxBars; i > = 0; i--) {
TrendUp = EMPTY_VALUE;
TrendDown = EMPTY_VALUE;
TrendResult = EMPTY_VALUE;
atr = iATR(NULL, 0, ATRPeriod, i);
medianPrice = (High+Low)/2;
up=medianPrice+(ATRMultiplier*atr);
dn=medianPrice-(ATRMultiplier*atr);
trend=1;
if (Close > up) {
trend=1;
if (trend == -1) changeOfTrend = 1;
}
else if (Close < dn) {
trend=-1;
if (trend == 1) changeOfTrend = 1;
}
else if (trend==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend < 0 && trend > 0) {flag=1;}
else {flag=0;}
if (trend > 0 && trend < 0) {flagh=1;}
else {flagh=0;}
if (trend > 0 && dn < dn)
dn=dn;
if (trend < 0 && up > up)
up=up;
if (flag==1)
up=medianPrice+(ATRMultiplier*atr);
if (flagh==1)
dn=medianPrice-(ATRMultiplier*atr);
if (trend==1) {
TrendUp=dn;
if (changeOfTrend == 1) {
TrendUp = TrendDown;
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=up;
if (changeOfTrend == 1) {
TrendDown = TrendUp;
changeOfTrend = 0;
}
}
TrendResult=trend;
}
ChartRedraw();
WindowRedraw();
return(0);
}
//+------------------------------------------------------------------+
FAQs about the Supertrend Indicator
The Supertrend indicator is a technical tool based on the ATR that helps identify trends and trend reversals.
The indicator displays a line on the chart. If the price is above the line, an uptrend is signaled, and below it, a downtrend is indicated.
You can adjust the ATR period and Multiplier to control the indicator's sensitivity.
Yes, in volatile markets, the indicator can produce false signals. Therefore, it's advisable to combine it with other indicators.