Hist_StepMA_Stoch_KV1_Ex_02_with_Filterlevels
Download scriptThis indicator is designed to analyze market trends and volatility to provide a visual representation of price momentum. It works by calculating the "range" of price movements over a specific period and creating a dynamic, step-like structure that reacts to changes in the market's direction.
Core Logic Overview
1. Volatility Analysis The tool begins by measuring market volatility (the difference between highs and lows). It doesn't just look at a single candle; it calculates a weighted average of price movement over a set number of bars. This allows the indicator to understand whether the market is currently experiencing high turbulence or relative calm.
2. Dynamic Step Calculation Based on that volatility, the script defines three distinct "step sizes." Think of these as different levels of sensitivity:
- Minimum: A tight range for low-volatility environments.
- Maximum: A wide range for high-volatility environments.
- Mid: A balanced middle ground.
3. Trend Detection and "Step" Movement The indicator tracks the price relative to these step sizes. It looks for "breakouts"—moments where the price closes above or below a calculated boundary.
- When the price breaks a boundary, the indicator shifts its position (like a staircase).
- It captures these movements and locks them into a "Step Moving Average" style behavior. This means that rather than a smooth, curving line, it moves in discrete increments, staying flat until a significant enough price move forces it to "step" up or down.
4. Momentum Mapping (Stochastic Conversion) Once the step levels are established, the script compares the positions of these steps against each other. It normalizes this data into a scale (similar to how a Stochastic Oscillator works).
- It calculates the distance between the "Minimum" step and the "Maximum" step to create a reference zone.
- It then determines where the "Mid" step sits within that zone.
5. Visual Output The final result is displayed as a histogram in a separate window.
- The logic compares the relative strength of the "Minimum" trend against the "Mid" trend.
- If the Minimum trend is showing more strength (positive value), it highlights one side of the histogram.
- If the Mid trend is showing more strength (negative value), it highlights the other.
Summary for the User
In simple terms, this indicator filters out market noise by only reacting to significant price shifts that exceed a volatility-adjusted "step." It then measures where the current price action sits relative to those steps to show you which trend—the aggressive one or the moderate one—is currently dominating the market.
//+------------------------------------------------------------------+
//| StepMA_Stoch_KV1.mq4 |
//| Copyright © 2005, TrendLaboratory Ltd. |
//| E-mail: igorad2004@list.ru |
//| modified by Kalenzo -> simone@konto.pl |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link "E-mail: igorad2004@list.ru"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_level1 0.04
#property indicator_level2 -0.04
//#property indicator_minimum -1
//#property indicator_maximum 1
//---- input parameters
extern int PeriodWATR=10;
extern double Kwatr=1.0000;
extern int HighLow=0;
extern int NumberOfBarsToCalculate = 2000;
//---- indicator buffers
double LineMinBuffer[];
double LineMidBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
Comment("");
//---- indicator line
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexBuffer(0,LineMinBuffer);
SetIndexBuffer(1,LineMidBuffer);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
//short_name="StepMA Stoch("+PeriodWATR+","+Kwatr+","+HighLow+")";
SetIndexLabel(0,"StepMA Stoch 1");
SetIndexLabel(1,"StepMA Stoch 2");
//----
SetIndexDrawBegin(0,PeriodWATR);
SetIndexDrawBegin(1,PeriodWATR);
ArrayInitialize(LineMinBuffer,0);
ArrayInitialize(LineMidBuffer,0);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| StepMA_3D_v1 |
//+------------------------------------------------------------------+
int start()
{
string short_name;
short_name = "Max bars to count: |"+(Bars-1)+"| ";
IndicatorShortName(short_name);
int i,shift,TrendMin,TrendMax,TrendMid;
double SminMin0,SmaxMin0,SminMin1,SmaxMin1,SumRange,dK,WATR0,WATRmax,WATRmin,WATRmid;
double SminMax0,SmaxMax0,SminMax1,SmaxMax1,SminMid0,SmaxMid0,SminMid1,SmaxMid1;
double linemin,linemax,linemid,Stoch1,Stoch2,bsmin,bsmax;
double prev_y = 0,prev_b = 0;
for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--)
{
SumRange=0;
for (i=PeriodWATR-1;i>=0;i--)
{
dK = 1+1.0*(PeriodWATR-i)/PeriodWATR;
SumRange+= dK*MathAbs(High[i+shift]-Low[i+shift]);
}
WATR0 = SumRange/PeriodWATR;
WATRmax=MathMax(WATR0,WATRmax);
if (shift==NumberOfBarsToCalculate-1-PeriodWATR) WATRmin=WATR0;
WATRmin=MathMin(WATR0,WATRmin);
int StepSizeMin=MathRound(Kwatr*WATRmin/Point);
int StepSizeMax=MathRound(Kwatr*WATRmax/Point);
int StepSizeMid=MathRound(Kwatr*0.5*(WATRmax+WATRmin)/Point);
if (HighLow>0)
{
SmaxMin0=Low[shift]+2*StepSizeMin*Point;
SminMin0=High[shift]-2*StepSizeMin*Point;
SmaxMax0=Low[shift]+2*StepSizeMax*Point;
SminMax0=High[shift]-2*StepSizeMax*Point;
SmaxMid0=Low[shift]+2*StepSizeMid*Point;
SminMid0=High[shift]-2*StepSizeMid*Point;
if(Close[shift]>SmaxMin1) TrendMin=1;
if(Close[shift]<SminMin1) TrendMin=-1;
if(Close[shift]>SmaxMax1) TrendMax=1;
if(Close[shift]<SminMax1) TrendMax=-1;
if(Close[shift]>SmaxMid1) TrendMid=1;
if(Close[shift]<SminMid1) TrendMid=-1;
}
if (HighLow == 0)
{
SmaxMin0=Close[shift]+2*StepSizeMin*Point;
SminMin0=Close[shift]-2*StepSizeMin*Point;
SmaxMax0=Close[shift]+2*StepSizeMax*Point;
SminMax0=Close[shift]-2*StepSizeMax*Point;
SmaxMid0=Close[shift]+2*StepSizeMid*Point;
SminMid0=Close[shift]-2*StepSizeMid*Point;
if(Close[shift]>SmaxMin1) TrendMin=1;
if(Close[shift]<SminMin1) TrendMin=-1;
if(Close[shift]>SmaxMax1) TrendMax=1;
if(Close[shift]<SminMax1) TrendMax=-1;
if(Close[shift]>SmaxMid1) TrendMid=1;
if(Close[shift]<SminMid1) TrendMid=-1;
}
if(TrendMin>0 && SminMin0<SminMin1) SminMin0=SminMin1;
if(TrendMin<0 && SmaxMin0>SmaxMin1) SmaxMin0=SmaxMin1;
if(TrendMax>0 && SminMax0<SminMax1) SminMax0=SminMax1;
if(TrendMax<0 && SmaxMax0>SmaxMax1) SmaxMax0=SmaxMax1;
if(TrendMid>0 && SminMid0<SminMid1) SminMid0=SminMid1;
if(TrendMid<0 && SmaxMid0>SmaxMid1) SmaxMid0=SmaxMid1;
if (TrendMin>0) linemin=SminMin0+StepSizeMin*Point;
if (TrendMin<0) linemin=SmaxMin0-StepSizeMin*Point;
if (TrendMax>0) linemax=SminMax0+StepSizeMax*Point;
if (TrendMax<0) linemax=SmaxMax0-StepSizeMax*Point;
if (TrendMid>0) linemid=SminMid0+StepSizeMid*Point;
if (TrendMid<0) linemid=SmaxMid0-StepSizeMid*Point;
bsmin=linemax-StepSizeMax*Point;
bsmax=linemax+StepSizeMax*Point;
Stoch1=NormalizeDouble((linemin-bsmin)/(bsmax-bsmin),6);
Stoch2=NormalizeDouble((linemid-bsmin)/(bsmax-bsmin),6);
prev_y = (Stoch1 - Stoch2);
if(prev_y<0.0){
LineMinBuffer[shift] = prev_y;
LineMidBuffer[shift] = 0;
}
else if(prev_y>0.0){
LineMidBuffer[shift] = prev_y;
LineMinBuffer[shift] = 0;
}
//prev_y = Stoch1;
//prev_b = Stoch2;
SminMin1=SminMin0;
SmaxMin1=SmaxMin0;
SminMax1=SminMax0;
SmaxMax1=SmaxMax0;
SminMid1=SminMid0;
SmaxMid1=SmaxMid0;
}
return(0);
}
Comments