The Delta MA is a visual trading tool designed to help market participants identify trend directions and potential price fluctuations by analyzing the relationship between moving averages and historical price points. Instead of simply showing a single average line, this script creates a multi-layered visual system that reacts to the "momentum" or "slope" of the market.
Core Logic and Functionality
The indicator operates based on three primary logical components:
1. Trend Slope Detection The tool constantly monitors a Simple Moving Average (SMA). It looks at whether this average is currently climbing, falling, or moving sideways. This serves as the foundation for all other visual elements on the chart.
2. Dynamic Boundary Mapping Depending on the direction of the moving average, the script identifies specific price points from a set historical period:
- Uphill Movement: When the moving average is trending upwards, the tool identifies and plots a "Lower" boundary.
- Downhill Movement: When the moving average is trending downwards, it identifies and plots an "Upper" boundary.
This logic effectively creates a "ceiling" or "floor" effect based on where the price was positioned a specific number of candles ago, providing a visual cue of the market's reach relative to its current trend.
3. Pivot Point Smoothing (The Mid-Line) To ensure the visual data is cohesive and easy to read, the script includes logic to identify "inflection points"—moments where the trend changes direction (e.g., switching from upward to downward). When these shifts occur, the tool calculates a "Middle" value. This helps bridge the gaps between boundaries, resulting in a smoother, more continuous visual flow on your chart rather than disconnected data points.
Visual Representation
The indicator renders four distinct lines on the chart:
- Upper & Lower Boundaries: These show the extremes of the price action based on the trend direction.
- Middle Line: This acts as a bridge to provide continuity during trend transitions.
- Moving Average: The baseline used to determine the current market bias.
By combining these elements, the tool provides a comprehensive overview of market momentum, highlighting where the price is positioned in relation to past performance and current trends.
//+------------------------------------------------------------------+
//| Delta MA.mq4 |
//| Me |
//| |
//+------------------------------------------------------------------+
#property copyright "Me"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Yellow
#property indicator_color4 Violet
//---- input parameters
extern int period=18;
//---- buffers
double UPPER[];
double LOWER[];
double MID[];
double MA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,UPPER);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,LOWER);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,MID);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,MA);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int i,limit;
if (counted_bars<1)
limit = Bars - period;
else
limit = Bars - counted_bars + 1;
for (i=limit;i>=0;i--)
{
MA[i] = iMA(0,0,period,0,MODE_SMA,PRICE_CLOSE,i);
// if MA is sloping up, we'll need a trigger below
if (MA[i]>=MA[i+1])
{
LOWER[i] = Close[i+period];
}
if (MA[i]<=MA[i+1])
{
UPPER[i] = Close[i+period];
}
// put some yellow paint to fill the gaps, and make a smooth line
if ((MA[i]>=MA[i+1] && MA[i+1]<=MA[i+2]) ||
(MA[i]<=MA[i+1] && MA[i+1]>=MA[i+2]))
{
MID[i]=Close[i+period];
MID[i+1] = Close[i+1+period];
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments