📕The Advanced

ADX (Average Directional Index)

Understanding the Average Directional Index (ADX)

The Average Directional Index (ADX) is a cornerstone technical analysis tool that aids traders in quantifying the strength of a trend. Unlike many indicators, the ADX is unique because it doesn’t evaluate the direction (upward or downward) of the trend but rather focuses on how strong or weak the trend is. This characteristic makes the ADX an invaluable component in a trader's toolkit for assessing market conditions.

How the ADX Works

The ADX is derived from a sequence of calculations based on the Directional Movement Indicators (DMI), which consist of two primary components: the Positive Directional Indicator (+DI) and the Negative Directional Indicator (-DI). These indicators are pivotal in understanding the dynamics of the ADX.

  • +DI helps in identifying when the current high is significantly higher than the previous high, suggesting a positive trend.

  • -DI, conversely, indicates when the current low is significantly lower than the previous low, implying a negative trend.

The strength of the trend—regardless of its direction—is then calculated to form the ADX value. Traders often consider:

  • ADX Value above 25: This typically signals a strong trend, meaning the market is moving in a clear direction.

  • ADX Value below 20: This often suggests a weak trend or that the market is trading within a range, indicating a lack of a clear trend.

Application in Trading

The ADX shines in distinguishing between trending and range-bound markets, enabling traders to adapt their strategies accordingly. For example, in a strong trending market (high ADX value), a trader might favor strategies that capitalize on sustained movements, such as trend-following strategies. Conversely, in a market characterized by a low ADX value, a trader might employ strategies suited to range-bound markets, like "buy low, sell high" within the range or channel trading.

Conclusion

In sum, the Average Directional Index (ADX) serves as a robust tool for assessing trend strength. By integrating the ADX into their analysis, traders can make more informed decisions about whether to employ trend-following strategies or to brace for potential sideways market movement. Understanding and applying the ADX can significantly enhance one's trading approach by ensuring strategies are aligned with the prevailing market conditions.

Calculating True Range (TR)

Plus Directional Movement (+DM), and Minus Directional Movement (-DM) for ADX

True Range (TR): The True Range indicator is a measure of volatility. It is calculated as the maximum of the following three values for each period:

  • The difference between the current High and the current Low ((High - Low))

  • The absolute difference between the current High and the previous Close ((|High - Previous Close|))

  • The absolute difference between the current Low and the previous Close ((|Low - Previous Close|))

In formula form:

[TR = \max[(High - Low), |(High - Previous Close)|, |(Low - Previous Close)|]]

Plus Directional Movement (+DM) and Minus Directional Movement (-DM): The Directional Movement system helps determine if a security is trending. It consists of two components:

  1. Plus Directional Movement (+DM): Occurs when the current High is higher than the previous High, and the difference is larger than the difference between the two recent Lows, if any. It's calculated as:

[+DM = High - Previous High] if ((High - Previous High) > (Previous Low - Low)), else (+DM = 0).

  1. Minus Directional Movement (-DM): Occurs when the current Low is lower than the previous Low, and this difference is larger than the difference between the two recent Highs, if any. It's calculated as:

[-DM = Previous Low - Low] if ((Previous Low - Low) > (High - Previous High)), else (-DM = 0).

These calculations will feed into the calculation of the ADX (Average Directional Index), which is a smoothed average of the ratio of +DM, -DM, and TR over a specified period, typically 14 days. The ADX indicates the strength of a trend but not its direction.

Sample Dart Code

// Dart function to calculate ADX - Average Directional Movement Index

double calculateADX(List<double> highs, List<double> lows, int period) {
  if (highs.length != lows.length || highs.length < period) {
    throw Exception("Invalid input length.");
  }

  List<double> dmPlus = [];
  List<double> dmMinus = [];
  List<double> trs = [];  // True ranges

  for (int i = 1; i < highs.length; i++) {
    double high = highs[i];
    double low = lows[i];
    double previousHigh = highs[i - 1];
    double previousLow = lows[i - 1];

    // Calculate +DM and -DM
    double plusDM = ((high - previousHigh) > (previousLow - low)) ? high - previousHigh : 0;
    double minusDM = ((previousLow - low) > (high - previousHigh)) ? previousLow - low : 0;

    dmPlus.add(plusDM);
    dmMinus.add(minusDM);

    // Calculate True Range (TR)
    double tr = [high - low, (high - previousLow).abs(), (low - previousHigh).abs()].reduce((a, b) => a > b ? a : b);
    trs.add(tr);
  }

  // Calculate the smoothed values of +DM, -DM, and TR using Wilder's Smoothing Technique
  List<double> smoothedPlusDM = _smooth(dmPlus, period);
  List<double> smoothedMinusDM = _smooth(dmMinus, period);
  List<double> smoothedTRs = _smooth(trs, period);

  // Calculate the Directional Indicators (+DI and -DI)
  List<double> diPlus = [];
  List<double> diMinus = [];
  for (int i = 0; i < smoothedPlusDM.length; i++) {
    diPlus.add(100 * (smoothedPlusDM[i] / smoothedTRs[i]));
    diMinus.add(100 * (smoothedMinusDM[i] / smoothedTRs[i]));
  }

  // Calculate the DX and ADX
  List<double> dx = [];
  for (int i = 0; i < diPlus.length; i++) {
    dx.add((diPlus[i] - diMinus[i]).abs() / (diPlus[i] + diMinus[i]) * 100);
  }
  double adx = _smooth(dx, period).reduce((a, b) => a + b) / period;

  return adx;
}

List<double> _smooth(List<double> values, int period) {
  List<double> smoothedValues = [];
  // Initial smoothing
  smoothedValues.add(values.take(period).reduce((a, b) => a + b));

  // Subsequent smoothing
  for (int i = period; i < values.length; i++) {
    smoothedValues.add(values[i] + smoothedValues.last - smoothedValues.last / period);
  }
  return smoothedValues;
}

Please note that this is a simplified and direct algorithm to calculate ADX. For efficiency and performance optimizations, especially with large datasets, consider incremental updates and optimized data structures.

Parabolic SAR (Stop and Reverse)

Understanding the Parabolic SAR Indicator

The Parabolic SAR (Stop and Reverse) indicator is an invaluable tool in the arsenal of technical traders and analysts. Developed by the renowned technical analyst Welles Wilder, the Parabolic SAR is designed to help assess the momentum of a financial asset and signal potential reversals in price direction. This makes it a critical component for those looking to make informed trading decisions based on price movements and trends.

How It Works

The Parabolic SAR operates on a relatively simple principle yet offers profound insights. It is represented on charts as a series of dots placed either above or below the price bars or candlesticks. The positioning of these dots is significant:

  • Dots below the price: Indicate an uptrend, signaling traders it might be a good time to consider entering a long position or holding onto existing positions in anticipation of future price increases.

  • Dots above the price: Suggest a downtrend, warning traders that it might be time to consider selling or shorting the asset in anticipation of future declines in price.

The "Stop and Reverse" element of the Parabolic SAR's name suggests that when the price crosses over the indicator, it could be time to "stop" and potentially "reverse" one's trading position. This feature of the Parabolic SAR makes it a dynamic tool that adapts to changing market conditions, signaling when trends might be starting to wane or shift direction.

Calculation

Understanding the calculation method behind the Parabolic SAR can provide insightful perspectives into its behavior and functionality. The indicator is calculated with a focus on acceleration factor (AF), which increases as the trend continues, indicating an increase in momentum. However, this article won't delve into the formula in depth, as it involves complex mathematical computations.

Applications in Trading

Traders use the Parabolic SAR in several ways:

  • Identifying Entry and Exit Points: The indicator provides clear signals on when might be an opportune time to enter or exit a trade based on the positioning of the dots in relation to the price.

  • Trailing Stop Losses: The dots can serve as dynamic stop-loss points, moving as the price trend progresses. This helps in protecting profits or minimizing losses.

  • Trend Confirmation: When used in conjunction with other indicators, the Parabolic SAR can help confirm the strength and direction of market trends.

Tips for Effective Use

While the Parabolic SAR can be a powerful tool, traders should consider the following to maximize its effectiveness:

  • Indicator Confirmation: Use the Parabolic SAR with other indicators (such as moving averages or MACD) to confirm signals before making trading decisions.

  • Understanding Market Conditions: The indicator tends to work best in markets that are trending strongly in one direction. Its effectiveness can be reduced during periods of market consolidation or sideways movement.

  • Adjusting Settings: Experienced traders might adjust the settings of the Parabolic SAR to make it more or less sensitive to price changes, depending on their trading strategy and the market conditions.

Conclusion

The Parabolic SAR is a versatile and dynamic indicator that can add value to a trader's technical analysis toolkit. By providing clear signals on potential price reversals and trend strength, it helps in making informed decisions in both entering and exiting trades. However, as with any trading tool, it is crucial to use the Parabolic SAR alongside other indicators and within the context of a well-thought-out trading strategy. Understanding its limitations and best practices can greatly enhance its utility in market analysis and trading.

Key Components

  • EP (Extreme Point): The highest high in an uptrend or the lowest low in a downtrend.

  • AF (Acceleration Factor): Begins at 0.02 and increases by 0.02 for each new high or low, with a ceiling of 0.2.

  • SAR_(n-1)_: The Parabolic SAR value of the previous period.

  • SAR_(n)_: The current Parabolic SAR value.

Calculation Formula

The Parabolic SAR is calculated as follows, allowing it to adjust over time based on the price movement:

SAR_(n) = SAR_(n-1) + AF × (EP - SAR_(n-1))

By understanding and applying the Parabolic SAR, traders can better anticipate market trends and reversal points, making more informed trading decisions.

Sample Dart Code

class ParabolicSAR {
  double ep; // Extreme Point
  double af = 0.02; // Acceleration Factor
  double maxAf = 0.2;
  double? sar; // Current SAR value
  
  ParabolicSAR({required this.ep, this.sar});
  
  double calculate(double high, double low, bool isUptrend) {
    if (sar == null) {
      sar = isUptrend ? low : high; // Initialize SAR if not set
    }
    
    // Adjust EP and AF if there's a new high or low
    if ((isUptrend && high > ep) || (!isUptrend && low < ep)) {
      ep = isUptrend ? high : low;
      if (af < maxAf) {
        af += 0.02;
      }
    }
    
    // Calculate SAR for the current period
    double sarCurrent = sar! + af * (ep - sar!);
    
    // Adjust SAR if it crosses current period high or low
    if(isUptrend) {
      sarCurrent = min(sarCurrent, low);
    } else {
      sarCurrent = max(sarCurrent, high);
    }
    
    // Update SAR for the next period
    sar = sarCurrent;
    return sarCurrent;
  }
}

Last updated