SmADXbars
Download scriptThis tool is designed as a visual aid for traders using the MetaTrader platform to simplify how they interpret market momentum and price structure. Instead of just looking at raw data, this script processes complex technical indicators into a clearer visual format to help identify trends more effectively.
How the Logic Works
The script operates by analyzing two primary components of market movement: the "Plus" and "Minus" directional indicators. These are used to determine which way the market is currently leaning—whether it is showing strength in an upward direction or downward momentum.
1. Directional Filtering The script constantly monitors the relationship between these two opposing forces. At every point on the chart, it checks which force is stronger:
- If the downward pressure (Minus) is stronger than the upward pressure (Plus), the script identifies the price movement as a "Low Bar" scenario.
- If the upward pressure (Plus) is stronger than the downward pressure (Minus), it identifies the movement as a "High Bar" scenario.
2. Price Re-Mapping The unique logic of this tool lies in how it handles these identifications. Rather than just marking them, it creates a specialized set of price data based on the current trend:
- During an upward trend, it captures specific price points to emphasize "highs."
- During a downward trend, it captures price points to emphasize "lows."
3. Smoothing for Clarity To prevent the resulting visual from looking jagged or erratic, the script applies a secondary smoothing layer. It takes the re-mapped data from the previous step and calculates a Simple Moving Average (SMA). This translates the raw, noisy movements of the market into two smooth, distinct lines.
Final Result
The end result is a dual-line visual indicator. By smoothing out the "highs" and "lows" based on actual directional momentum, the tool provides traders with a cleaner representation of the trend. It effectively filters out minor price fluctuations, allowing you to see the underlying flow of the market more clearly than by looking at standard price bars alone.
//+------------------------------------------------------------------+
//| ADX BARS.mq4 |
//| Perky Aint no turkey |
//| |
//+------------------------------------------------------------------+
#property copyright "Perky"
#property link "Perky_z@yahoo.com"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- indicator parameters
extern int ADXPeriod = 14;
extern int ADXBARSPeriod = 5;
//---- 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);
SetIndexStyle(1, DRAW_LINE);
//----
IndicatorDigits(Digits + 1);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("ADXBars(" + ADXPeriod + ", " + ADXBARSPeriod + ")");
SetIndexLabel(0, "ADXBars");
SetIndexLabel(1, "Signal");
//---- 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