ADXbarsSmd[cw]

Download script
ADXbarsSmd[cw]

This tool is designed as a visual aid for traders to better understand market trends by analyzing the relationship between buying and selling pressure. It works by combining two well-known technical indicators—the ADX (Average Directional Index) and Moving Averages—to highlight the strength of price movements in real-time.

How the Logic Works

The script operates through a three-step process to filter out market "noise" and present a clearer picture of the current trend:

1. Identifying Market Sentiment The script first looks at the "Plus" and "Minus" components of the ADX indicator. These represent the strength of upward (bullish) momentum versus downward (bearish) momentum. By comparing these two values, the tool determines which direction is currently dominating the market at any given moment.

2. Dynamic High and Low Tracking Once the dominant direction is identified, the script performs a unique action: it captures the price extremes of the current candle based on that direction.

  • When the market shows stronger downward momentum, it tracks the specific high and low points associated with that movement.
  • When the market shows stronger upward momentum, it captures those points to reflect the bullish trend.

Essentially, it "labels" the price data based on which way the market is pushing, ensuring that the resulting lines prioritize the direction of the trend rather than just random price fluctuations.

3. Smoothing for Visual Clarity To prevent the visual output from being too jagged or jumpy (which can happen with raw price data), the script applies a Simple Moving Average (SMA) to the captured high and low points. This smoothing process creates two distinct lines on your chart:

  • The Main Trend Line: Represents the smoothed average of the directional highs/lows.
  • The Signal Line: A slightly adjusted version of the trend data that helps traders identify potential shifts or crossovers in momentum.

Summary for the Trader

Instead of just looking at a raw price line, this script provides a "smoothed" path of market behavior. By filtering out minor fluctuations and focusing on the directionally dominant price points, it helps you visualize whether the current trend is holding firm or beginning to lose steam.

Indicators Used
Movement directional indexMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
ADXbarsSmd[cw]
//+------------------------------------------------------------------+
//|                                              ADXBARSsmd[cw].mq4  |
//|               ADX Bars  Smoothed  [cw]    Perky Ate no turkey    |
//|                                                                  |
//+------------------------------------------------------------------+
#property  copyright "Perky"
#property  link      "Perky_z@yahoo.com"

//---- indicator settings
#property indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Red
#property  indicator_color2  Blue
//---- indicator parameters
extern int ADXPeriod = 14;
extern int ADXBARSPeriod = 5;
extern int Shift=0;
extern int slShift=0;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double HighBarBuffer[];
double LowBarBuffer[];
double b4plusdi, b4minusdi, nowplusdi, nowminusdi;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//----additional buffers are used for counting.
   IndicatorBuffers(4);
//---- indicator buffers mapping
   if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2) && 
      !SetIndexBuffer(2,HighBarBuffer) && !SetIndexBuffer(3,LowBarBuffer))
       Print("cannot set indicator buffers!");
//---- drawing settings
   SetIndexStyle(0, DRAW_LINE);
     SetIndexShift(0, Shift+slShift+1); 
   SetIndexStyle(1, DRAW_LINE);
       SetIndexShift(1, Shift);
//---- 
   IndicatorDigits(Digits + 1);  
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ADXBarsSmd[cw]");
   SetIndexLabel(0, "ADXBarsSmd[sw]("+ADXPeriod+","+ADXBARSPeriod+"s"+Shift+"sls"+slShift+")");
   SetIndexLabel(1, "SignalADXsmd[sw]("+ADXPeriod+","+ADXBARSPeriod+"s"+Shift+")");           
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|  ADX BARS                                                        |
//+------------------------------------------------------------------+
int start()
  {
    double ArOsc = 0;
    int    ArPer, limit, i; 
    int    counted_bars = IndicatorCounted();
//---- check for possible errors
    if(counted_bars < 0) 
        return(-1);
//---- last counted bar will be recounted
    if(counted_bars > 0) 
        counted_bars--;
    limit = Bars - counted_bars;
//----Calculation---------------------------
    for(i = 0; i < limit; i++)
      {
        nowplusdi = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI, i);
        nowminusdi = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, i);
        if(nowminusdi > nowplusdi) 
          {
            LowBarBuffer[i] = Low[i];
            HighBarBuffer[i] = High[i];
          }
        if(nowplusdi > nowminusdi) 
          {
            HighBarBuffer[i] = Low[i];
            LowBarBuffer[i] = High[i];
          }
      }
    for(i = limit - 1; i >=0 ; i--)
      {
        ind_buffer1[i] = iMAOnArray(HighBarBuffer, 0, ADXBARSPeriod, 0, MODE_SMA, i); 
        ind_buffer2[i] = iMAOnArray(LowBarBuffer, 0, ADXBARSPeriod, 0, MODE_SMA, i); 
      }
//---- done
    return(0);
  }

Comments