StepMA_sashken_v4

Download script
StepMA_sashken_v4

The StepMA_sashken_v2 is a specialized technical analysis tool designed to help traders visualize market trends and identify potential entry points by smoothing out standard price movements. Rather than simply following the raw price of an asset, this script creates "stepped" moving averages that focus on significant shifts in momentum.

Core Logic and Functionality

The indicator operates through a multi-layered process to filter out market "noise" and highlight clear directional trends:

1. Trend Detection & Stepping The tool starts by calculating a standard Moving Average (MA). However, instead of plotting this directly, it uses it as a base to create two distinct types of "Step" averages—Fast and Slow. The logic evaluates whether the price is moving enough to break out of a specific predefined range (the "Step"). If the price stays within this range, the indicator maintains its previous level; if it breaks out, the level "steps" to the new position. This creates a staircase effect on your chart, making it easier to see where the market has actually changed direction versus where it is just fluctuating slightly.

2. Dual-Layer Smoothing (Fast and Slow) The script processes two different versions of these steps simultaneously:

  • Fast Step: Reacts more quickly to price changes to capture immediate momentum.
  • Slow Step: Provides a broader view of the long-term trend, acting as a stabilizer.

To ensure these lines are fluid and easy to read, the script applies an additional layer of smoothing (an Exponential Moving Average) over the steps themselves. This removes any jagged edges, resulting in clean, flowing lines that represent the underlying "heartbeat" of the market trend.

3. Signal Generation The primary goal for a trader using this script is to identify the intersection of these two smoothed lines. The logic tracks the relationship between the Fast and Slow Step averages:

  • Upward Signals: When the Fast line crosses above the Slow line (indicating that short-term momentum is accelerating faster than the long-term trend), an arrow is placed on the chart to signal a potential bullish move.
  • Downward Signals: When the Fast line crosses below the Slow line (indicating that short-term momentum is dropping relative to the long-term trend), an arrow is placed to signal a potential bearish move.

Summary for Traders

Instead of looking at a messy web of price candles, this indicator simplifies your view into two main components:

  1. Trend Visualization: Clean, stepped lines that show you exactly which way the "weight" of the market is moving.
  2. Actionable Alerts: Visual arrows that pinpoint the exact moment the short-term trend breaks away from the long-term trend, providing a clearer roadmap for potential trades.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
StepMA_sashken_v4
//+------------------------------------------------------------------+
//|                                            StepMA_sashken_v2.mq4 |
//|                                          E-mail: sashken@mail.ru |
//+------------------------------------------------------------------+

#property link      "E-mail: sashken@mail.ru"

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Aqua
#property indicator_color2 Gold
#property indicator_color3 Red
#property indicator_color4 Lime
#property indicator_color5 Magenta

//---- input parameters
extern int MA=5;                    // ma period
extern int MAmode=MODE_EMA;         // ma mode
extern int MAprice=PRICE_CLOSE;     // ma price
extern double StepSizeFast=0.0015;  // points
extern double StepSizeSlow=0.0015;  // points
extern int FastSdvig=3;  //
extern int SlowSdvig=3;  //
extern int StepSmooth=1;  //

extern double StepSize=2.0;         // 2.0
extern int TotalBar=5000;           
//extern int HighLow=0;
//---- indicator buffers
double Line1Buffer[];
double Line2Buffer[];
double Line3Buffer[];
double Line4Buffer[];
double Line5Buffer[];
double Line6Buffer[];
double Line7Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,2);
   SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID,2);
   SetIndexStyle(5,DRAW_NONE);
   SetIndexStyle(6,DRAW_NONE);
   SetIndexEmptyValue(3,0);
   SetIndexArrow(3,233);
   SetIndexEmptyValue(4,0);
   SetIndexArrow(4,234);
   SetIndexBuffer(0,Line1Buffer);
   SetIndexBuffer(1,Line2Buffer);
   SetIndexBuffer(2,Line3Buffer);
   SetIndexBuffer(3,Line4Buffer);
   SetIndexBuffer(4,Line5Buffer);
   SetIndexBuffer(5,Line6Buffer);
   SetIndexBuffer(6,Line7Buffer);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   short_name="StepMA_sashken(Period:"+MA+", Fast:"+StepSizeFast+", Slow:"+StepSizeSlow+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"MA");
   SetIndexLabel(1,"StepMA fast");
   SetIndexLabel(2,"StepMA slow");
   SetIndexLabel(3,"UP signal");
   SetIndexLabel(4,"DOWN signal");
//----
   SetIndexDrawBegin(0,1);
   SetIndexDrawBegin(1,1);
   SetIndexDrawBegin(2,1);
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| StepMA_sashken_v1                                                |
//+------------------------------------------------------------------+
int start()
  {
   int shift,ftrend,strend;
   double fmin0,fmax0,fmin1,fmax1,smin0,smax0,smin1,smax1,MA0;
   if (TotalBar==0) {TotalBar=Bars-1;}
   
   for(shift=TotalBar;shift>=0;shift--)
   {	
   MA0=iMA(NULL,0,MA,0,MAmode,MAprice,shift);
   
	  fmax0=MA0+StepSize*StepSizeFast;
	  fmin0=MA0-StepSize*StepSizeFast;
	  	    
	  if (MA0>fmax1)  ftrend=1; 
	  if (MA0<fmin1)  ftrend=-1;

	  if(ftrend>0 && fmin0<fmin1) fmin0=fmin1;
	  if(ftrend<0 && fmax0>fmax1) fmax0=fmax1;
	  
	  smax0=MA0+StepSize*StepSizeSlow;
	  smin0=MA0-StepSize*StepSizeSlow;
		
	  if (MA0>smax1)  strend=1; 
	  if (MA0<smin1)  strend=-1;

	  if(strend>0 && smin0<smin1) smin0=smin1;
	  if(strend<0 && smax0>smax1) smax0=smax1;
	    
	  
	  Line1Buffer[shift]=MA0;
	  
	  if (ftrend>0) Line6Buffer[shift-FastSdvig]=fmin0+StepSizeFast;
	  if (ftrend<0) Line6Buffer[shift-FastSdvig]=fmax0-StepSizeFast;
	  
	  if (strend>0) Line7Buffer[shift-SlowSdvig]=smin0+StepSizeSlow;
	  if (strend<0) Line7Buffer[shift-SlowSdvig]=smax0-StepSizeSlow;
	  
	  fmin1=fmin0;
	  fmax1=fmax0;
	  smin1=smin0;
	  smax1=smax0;
	 }
	 
	 
	 
	 	for(shift=TotalBar;shift>=0;shift--)
      {	
      Line2Buffer[shift]= iMAOnArray(Line6Buffer,0,StepSmooth,0,MODE_EMA,shift);
      Line3Buffer[shift]= iMAOnArray(Line7Buffer,0,StepSmooth,0,MODE_EMA,shift);
      }
	 
	 
	 
	 
	 
	 
	 
	 
	 for(shift=TotalBar;shift>=0;shift--)
   {	
	  if (Line2Buffer[shift+1]>Line3Buffer[shift+1] && Line2Buffer[shift+2]<=Line3Buffer[shift+2])
	     {
	     Line4Buffer[shift] = Line3Buffer[shift+1]-StepSizeFast;
	     }
	  if (Line2Buffer[shift+1]<Line3Buffer[shift+1] && Line2Buffer[shift+2]>=Line3Buffer[shift+2])
	     {
	     Line5Buffer[shift] = Line3Buffer[shift+1]+StepSizeFast;
	     }
	  
	 }
	 
	return(0);	
 }

Comments