StepMA_v1_v1

Author: Copyright � 2005, TrendLaboratory Ltd.
StepMA_v1_v1

This script creates a specialized technical analysis tool called the Step Moving Average (StepMA). Unlike standard moving averages that create smooth, flowing curves, this indicator is designed to move in distinct "steps," making it easier to identify structural price trends and significant shifts in market direction.

How the Logic Works

The core logic of the StepMA relies on three main components:

1. Dynamic Trend Detection The script constantly analyzes the relationship between the current market price and a calculated "buffer zone" around the previous price level. It determines whether the market is in an upward or downward trend based on these boundaries.

  • If the price breaks above the upper boundary, the script identifies an upward trend.
  • If the price drops below the lower boundary, it identifies a downward trend.

2. Price Reference Selection Depending on how you configure the tool, the script decides which part of the price candle to use as its primary reference point:

  • It can look at the High and Low points of each candle (the extremes).
  • Or, it can focus purely on the Closing price (the final price at the end of a period).

3. The "Step" Mechanism This is what gives the indicator its unique look. Instead of moving every time the price changes by a tiny amount, the indicator only updates its position when the price movement is significant enough to clear a specific "Step Size."

  • When the trend is upward, the indicator stays at a fixed level until the price breaks high enough to create a new "step" upward.
  • When the trend is downward, it remains at a fixed level until the price drops low enough to create a new "step" downward.

Summary for Traders

Essentially, this tool acts as a visual filter for market noise. By using "steps," it ignores minor fluctuations and only redraws its line when there is a confirmed move in price. This helps traders visualize the prevailing trend more clearly, providing a visual anchor that highlights whether the market is currently pushing higher or lower with significant momentum.

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

//+------------------------------------------------------------------+
//|                                                    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