StepMA_sashken_v2

Download script
StepMA_sashken_v2

This tool is designed as a visual technical analysis indicator for trading platforms. It transforms standard moving average data into a more structured, "stepped" format to help traders identify trends and potential entry or exit points with greater clarity.

Core Logic Overview

The script operates by processing a standard Moving Average (MA) and applying specific mathematical constraints to it. Instead of allowing the average to move fluidly with every minor price fluctuation, the script enforces a "step" logic. This means the indicator only reflects a change in direction once the price movement exceeds a predetermined threshold.

Key Components of the Analysis

1. Trend Filtering (Fast and Slow Steps) The tool calculates two distinct types of moving averages simultaneously:

  • Fast Step: Responds more quickly to recent price changes.
  • Slow Step: Provides a broader, smoother view of the market direction.

By establishing "minimum" and "maximum" boundaries for both levels, the script determines whether the current trend is upward or downward. If the price stays within these boundaries, the indicator remains stable; if it breaks out, the line "steps" to the new level.

2. Dynamic Trend Recognition The logic ensures that the indicator doesn't just react to noise. It remembers the previous step level and only updates when the trend confirms a significant shift. This creates a staircase-like visual effect on your chart, making it easier to see the "true" direction of the market by filtering out minor volatility.

3. Signal Generation The script concludes by monitoring the relationship between the Fast and Slow step lines. It identifies specific moments where these two lines cross each other:

  • Upward Signals: Generated when the fast trend moves from below to above the slow trend, often interpreted as an increase in momentum.
  • Downward Signals: Generated when the fast trend drops below the slow trend, suggesting a potential shift toward bearish movement.

Visual Output

On your trading chart, this logic manifests as:

  • Trend Lines: Smoothly stepped lines representing the primary market movement.
  • Visual Markers: Specific icons (arrows) that appear on the chart automatically when the Fast and Slow step levels cross, highlighting potential points of interest for the trader.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
StepMA_sashken_v2
//+------------------------------------------------------------------+
//|                                            StepMA_sashken_v2.mq4 |
//|                                          E-mail: sashken@mail.ru |
//+------------------------------------------------------------------+

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

#property indicator_chart_window
#property indicator_buffers 5
#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.0012;  // points
extern double StepSizeSlow=0.0015;  // points
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[];
//+------------------------------------------------------------------+
//| 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);
   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);
   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) Line2Buffer[shift]=fmin0+StepSizeFast;
	  if (ftrend<0) Line2Buffer[shift]=fmax0-StepSizeFast;
	  
	  if (strend>0) Line3Buffer[shift]=smin0+StepSizeSlow;
	  if (strend<0) Line3Buffer[shift]=smax0-StepSizeSlow;
	  
	  fmin1=fmin0;
	  fmax1=fmax0;
	  smin1=smin0;
	  smax1=smax0;
	 }
	 
	 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