StepMA_Color_v2
Download scriptThe StepMA_Color_v2 tool is designed to provide traders with a visual representation of market trends by identifying distinct "steps" in price movement. Unlike standard moving averages that create smooth, flowing lines, this indicator focuses on capturing the structural shifts in price, making it easier to see when the market is moving decisively in one direction or remaining stagnant.
How the Logic Works
The script operates through a three-step process to determine these movements:
1. Calculating Volatility (The "Step" Size) Before drawing any lines, the tool analyzes a specific period of historical data (defined by the user) to measure market volatility. It looks at the difference between the high and low prices over this timeframe. It then calculates an average range, which determines the "StepSize." This ensures that the size of the steps reacts to the current market environment—large steps appear during volatile periods, while smaller steps appear during calmer markets.
2. Identifying Trend Direction The indicator constantly monitors whether the price is breaking above or below specific thresholds based on the calculated StepSize.
- If the price moves significantly upward beyond a calculated ceiling, the script registers an UpTrend.
- If the price drops significantly below a calculated floor, it registers a DownTrend.
The logic includes a specific rule to ensure "momentum" is maintained: once a trend is established, the indicator resists moving backward unless the price makes a significant enough move to break the established boundary of that trend. This helps filter out minor market noise and small fluctuations that might otherwise trigger false signals.
3. Visual Representation Finally, the script translates these calculations into visual markers on your chart:
- UpTrend: When an upward move is confirmed, it plots a specific signal (colored Blue by default) representing the support level of that step.
- DownTrend: When a downward move is confirmed, it plots a signal (colored Red by default) representing the resistance level of that step.
Summary for Traders
Essentially, this tool "smooths" out the market's behavior into a series of staircase-like movements. By ignoring small, insignificant price wobbles and only highlighting significant shifts in direction, it helps traders visualize the underlying trend structure and identify potential areas of support and resistance more clearly.
//+------------------------------------------------------------------+
//| StepMA_Color_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 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int PeriodWATR=100;
extern double Kwatr=1.0000;
extern int Advance=0;
extern int HighLow=0;
//---- indicator buffers
double UpBuffer[];
double DownBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(0,159);
SetIndexArrow(1,159);
SetIndexShift(0,Advance);
SetIndexShift(1,Advance);
SetIndexBuffer(0,UpBuffer);
SetIndexBuffer(1,DownBuffer);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="StepMAColor("+PeriodWATR+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"UpTrendStepMA");
SetIndexLabel(1,"DownTrendStepMA");
//----
SetIndexDrawBegin(0,PeriodWATR);
SetIndexDrawBegin(1,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)
{
UpBuffer[shift]=smin0+StepSize*Point;
DownBuffer[shift]=-1.0;
}
if (trend<0)
{
DownBuffer[shift]=smax0-StepSize*Point;
UpBuffer[shift]=-1.0;
}
smin1=smin0;
smax1=smax0;
}
return(0);
}
Comments