StepMA_v2_v1

Download script
Author: Copyright � 2005, TrendLaboratory Ltd.
StepMA_v2_v1

This tool, known as the StepMA, is designed to provide a smoothed visual representation of market trends by identifying distinct price movements and "stepping" along them. Unlike traditional moving averages that might fluctuate smoothly with every minor price tick, this indicator focuses on capturing the structural direction of the market while filtering out insignificant noise.

How the Logic Works

The script operates through three primary phases to determine where the "step" should be drawn on your chart:

1. Volatility Measurement Before drawing any lines, the script looks back at a specific period of historical data (defined by the user). It calculates the average range of price movement during this time. This ensures that the "size" of the steps adjusts automatically to the market environment; in highly volatile markets, the steps become larger, while in calmer markets, the steps become smaller and more precise.

2. Determining Trend Direction The indicator continuously monitors whether the current price is moving upward or downward based on two possible modes:

  • High/Low Mode: It looks at the highest and lowest prices reached within a candle.
  • Close Mode: It focuses strictly on the closing price of each candle.

By comparing the current price against the calculated "Step Size" (derived from the volatility measurement), the script identifies if the market has broken out far enough to justify a change in trend direction.

3. Creating the "Step" Effect Once a trend is identified, the indicator calculates the position of the line:

  • In an Upward Trend: The line moves upward but stays anchored to the lowest points reached during that move. It only jumps higher when the price pushes significantly past the previous peak.
  • In a Downward Trend: The line moves downward but remains anchored to the highest points reached, only dropping further when the price falls significantly below the previous trough.

Summary of Behavior

The result is a "staircase" effect on your chart. Instead of a jagged, wandering line, you see a series of flat steps that only move when a significant price action occurs. This helps traders stay aligned with the primary trend by ignoring minor pullbacks and focusing on sustained shifts in market momentum.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
StepMA_v2_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                    StepMA_v2.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 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+(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