StepMA_v1
Download scriptThe StepMA is a specialized technical analysis tool designed to identify and visualize market trends by creating a "stepped" line on your chart. Unlike standard moving averages that create smooth, fluid curves, this indicator focuses on identifying specific price levels and holding them until a significant shift in momentum occurs.
How the Logic Works
The core functionality of this script revolves around three main components:
1. Defining the Movement Range (Step Size) The indicator uses a user-defined "Step Size" to determine how much price must move before the trend is considered officially broken. This creates a buffer zone, preventing the indicator from reacting to minor market noise or small fluctuations that don't represent a real change in direction.
2. Determining Price Reference Points The script looks at two different ways to identify the "current" price, depending on your settings:
- High/Low Basis: It calculates levels based on the highest and lowest points reached during a specific time period.
- Closing Basis: If not using High/Low, it uses the actual closing price of the candles as the baseline. By calculating a maximum and minimum boundary around these points, the script establishes a "zone" for the current trend.
3. Trend Identification and "Stepping" This is where the unique "Step" behavior happens. The indicator tracks the direction of the market:
- Upward Trend: While the price is moving up, the indicator stays at a specific level. It will only "step" higher if the price breaks above its established maximum boundary.
- Downward Trend: Conversely, while the price is moving down, it holds a steady level until the price drops below its established minimum boundary.
The Visual Result
On your chart, this logic results in a jagged, staircase-like line. Instead of constantly fluctuating with every small tick, the line remains flat (horizontal) as long as the price stays within the current trend's boundaries. When a significant price move occurs that exceeds the predefined "Step Size," the line instantly jumps to the new level.
This makes it an excellent tool for traders who want to see the "big picture" of market direction while filtering out the constant "zigzag" movements of standard indicators.
//+------------------------------------------------------------------+
//| StepMA_v1.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 Red
//---- input parameters
extern int StepSize=30;
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("+StepSize+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"StepMA");
//----
SetIndexDrawBegin(0,1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| StepMA_v1 |
//+------------------------------------------------------------------+
int start()
{
int shift,trend;
double smin0,smax0,smin1,smax1;
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