StepMA_v3_v1
Download scriptThis tool is designed to provide a visual representation of market trends by creating a "stepping" moving average. Unlike standard moving averages that flow in smooth, continuous curves, this indicator prioritizes price movement stability by moving in discrete levels, making it easier to identify the current direction of the market at a glance.
Core Logic and Methodology
The logic behind the StepMA (Step Moving Average) can be broken down into three primary stages:
1. Volatility Measurement Before drawing any lines, the script calculates the "Step Size." It looks back at a specific number of previous candles (defined by the user) to analyze the range between the high and low prices. By weighting these ranges, it determines the average volatility of the current market environment. This ensures that the "steps" in the indicator adjust automatically: during periods of high volatility, the steps are larger; during quieter markets, the steps become smaller and more precise.
2. Trend Identification The indicator evaluates the price action to determine if the market is in an upward or downward trend. It does this by establishing a "buffer zone" around the current price. Depending on your settings, it looks at either the extreme highs and lows of the candles or just the closing prices.
- If the price breaks above the upper threshold of this buffer, an upward trend is established.
- If the price breaks below the lower threshold, a downward trend is identified.
3. The "Stepping" Mechanism Once a trend is identified, the indicator draws a line that follows that direction. However, instead of moving with every tiny tick of price, it only moves forward when the price makes a significant enough push to overcome the previously established level.
- In an uptrend, the line stays flat until the price pushes high enough to create a new "step" upward.
- In a downtrend, the line stays flat until the price drops low enough to create a new "step" downward.
Key Benefits for the User
By utilizing this logic, the indicator filters out "market noise"—the minor fluctuations that often trigger false signals in standard moving averages. It provides a clearer visual path of the prevailing trend, helping traders see where the market is structurally moving rather than reacting to every small price twitch.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| StepMA_v3.mq4 |
//| Copyright © 2005, TrendLaboratory Ltd. |
//| E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link "E-mail: igorad2004@list.ru"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- input parameters
extern int PeriodWATR=100;
extern double Kwatr=1.0000;
extern int Advance=0;
extern int HighLow=0;
//---- indicator buffers
double LineBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexShift(0,Advance);
SetIndexBuffer(0,LineBuffer);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="StepMA("+PeriodWATR+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"StepMA");
//----
SetIndexDrawBegin(0,PeriodWATR);
//----
return(0);
}
//+------------------------------------------------------------------+
//| StepMA_v2 |
//+------------------------------------------------------------------+
int start()
{
int i,shift,trend;
double smin0,smax0,smin1,smax1,AvgRange,dK,WATR;
AvgRange=0;
for (i=PeriodWATR-1;i>=0;i--)
{
dK = 1+1.0*(PeriodWATR-i)/PeriodWATR;
AvgRange=AvgRange+ dK*MathAbs(High[i]-Low[i]);
}
WATR = AvgRange/PeriodWATR;
int StepSize=Kwatr*WATR/Point;
Comment(" StepSize = ", StepSize);
for(shift=Bars-1;shift>=0;shift--)
{
if (HighLow>0)
{
smax0=Low[shift]+2*StepSize*Point;
smin0=High[shift]-2*StepSize*Point;
if(Close[shift]>smax1) trend=1;
if(Close[shift]<smin1) trend=-1;
}
if (HighLow == 0)
{
smax0=Close[shift]+2*StepSize*Point;
smin0=Close[shift]-2*StepSize*Point;
if (Close[shift]>smax1) trend=1;
if (Close[shift]<smin1) trend=-1;
}
if(trend>0 && smin0<smin1) smin0=smin1;
if(trend<0 && smax0>smax1) smax0=smax1;
if (trend>0) LineBuffer[shift]=smin0+StepSize*Point;
if (trend<0) LineBuffer[shift]=smax0-StepSize*Point;
smin1=smin0;
smax1=smax0;
}
return(0);
}
Comments