StepMA_v6.1
Download scriptThis tool is designed to help traders visualize market trends by identifying specific "steps" in price movement rather than following the constant, often jagged fluctuations of traditional moving averages. Instead of trying to predict every minor wiggle in the market, this script focuses on capturing the structural shifts between upward and downward momentum.
Core Logic and Behavior
1. Volatility-Based Step Calculation The indicator begins by analyzing market volatility over a specific period. It looks at the range of price movement (Average True Range) to determine the "Step" size.
- If you set a manual step size, the tool follows that fixed increment.
- If left to automatic calculation, it uses the historical volatility of the current timeframe to decide how large each "step" should be. This ensures the indicator remains relevant whether the market is moving calmly or experiencing high turbulence.
2. Trend Detection and Thresholds The logic operates by establishing upper and lower boundaries (thresholds). Depending on your settings, it calculates these boundaries based on either the closing price of a candle or the high/low extremes.
- Breakout Logic: The script watches for the price to break above the previous high threshold or below the previous low threshold.
- Trend Confirmation: Once a breakout occurs, the tool locks into a trend state (Upward or Downward).
3. The "Step" Movement Unlike standard moving averages that move with every new price tick, this indicator moves in distinct increments:
- In an Uptrend: The line moves upward by a set amount but refuses to drop unless the price fails significantly enough to break the lower boundary. It essentially "holds" its level until a new step is confirmed.
- In a Downtrend: The line moves downward by a set amount and stays there, only moving higher if a significant upward breakout occurs.
4. Visual Indicators The script provides three distinct visual components to help with decision-making:
- The Main Line: A continuous visual representation of the current price "step."
- Trend Arrows/Signals: Depending on your configuration, it can display specific markers or color changes to notify you when the trend switches from bullish to bearish (or vice versa).
Summary for the User
Think of this tool as a "staircase" for market trends. Instead of a smooth hill that goes up and down constantly, it treats the market like a flight of stairs. It filters out the "noise" of small price movements and only updates its position when the market makes a significant enough move to justify moving to the next step. This helps traders stay on the right side of a trend without getting distracted by minor, insignificant price fluctuations.
//+------------------------------------------------------------------+
//| StepMA_v6.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 3
#property indicator_color1 LightBlue
#property indicator_color2 Blue
#property indicator_color3 Red
//---- input parameters
extern int Length=10; // ATR Length
extern double Kv=1.0; // Sensivity Factor
extern int StepSize=0; // Constant Step Size (if need)
extern int Advance=0; // Offset
extern bool HighLow=false; // High/Low Mode Switch (more sensitive)
extern bool Color=false; // Color Mode Switch
extern int BarsNumber=0;
//---- indicator buffers
double LineBuffer[];
double UpBuffer[];
double DnBuffer[];
double smax[];
double smin[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(5);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_ARROW);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(1,159);
SetIndexArrow(2,159);
SetIndexShift(0,Advance);
SetIndexShift(1,Advance);
SetIndexShift(2,Advance);
SetIndexBuffer(0,LineBuffer);
SetIndexBuffer(1,UpBuffer);
SetIndexBuffer(2,DnBuffer);
SetIndexBuffer(3,smax);
SetIndexBuffer(4,smin);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="StepMA("+Length+","+Kv+","+StepSize+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexLabel(1,"UpTrend");
SetIndexLabel(2,"DownTrend");
//----
SetIndexDrawBegin(0,Length);
SetIndexDrawBegin(1,Length);
SetIndexDrawBegin(2,Length);
//----
return(0);
}
//+------------------------------------------------------------------+
//| StepMA_v6 |
//+------------------------------------------------------------------+
int start()
{
int i,shift,trend,Step;
double smin0,smax0,smin1,smax1,ATRmin=10000,ATRmax=0;
if(BarsNumber>0)int Nbars=BarsNumber; else Nbars=Bars;
for(shift=Nbars-1;shift>=0;shift--)
{
LineBuffer[shift]=0.0;
UpBuffer[shift]=0.0;
DnBuffer[shift]=0.0;
}
for(shift=Nbars-1-Length;shift>=0;shift--)
{
ATRmax=MathMax(iATR(NULL,0,Length,shift),ATRmax);
ATRmin=MathMin(iATR(NULL,0,Length,shift),ATRmin);
if( StepSize>0 )
{Step=Kv*StepSize;}
else
{Step=0.5*Kv*(ATRmax+ATRmin)/Point;}
Comment (" StepSize= ", Step);
if (HighLow)
{
smax[shift]=Low[shift]+2.0*Step*Point;
smin[shift]=High[shift]-2.0*Step*Point;
}
else
{
smax[shift]=Close[shift]+2.0*Step*Point;
smin[shift]=Close[shift]-2.0*Step*Point;
}
if (Close[shift]>smax[shift+1]) trend=1;
if (Close[shift]<smin[shift+1]) trend=-1;
if(trend>0)
{
if(smin[shift]<smin[shift+1]) smin[shift]=smin[shift+1];
LineBuffer[shift]=smin[shift]+Step*Point;
if(Color) {UpBuffer[shift]=LineBuffer[shift]; DnBuffer[shift]=-1.0;}
}
else
{
if(smax[shift]>smax[shift+1]) smax[shift]=smax[shift+1];
LineBuffer[shift]=smax[shift]-Step*Point;
if(Color) {DnBuffer[shift]=LineBuffer[shift]; UpBuffer[shift]=-1.0;}
}
}
return(0);
}
Comments