StepChoppyBars_v2
Download scriptThe StepChoppyBars_v2 is a technical analysis indicator designed to categorize market price action into distinct behavioral states. Rather than simply telling you if the price is going up or down, this tool attempts to identify the quality and strength of the current trend by analyzing the relationship between momentum, trend direction, and price volatility.
How the Logic Works
The script functions by synthesizing data from three primary sources to classify each candle on your chart into one of eight specific categories. It looks at the "big picture" trend, compares different speeds of momentum, and determines where the current price is moving relative to those factors.
The logic flows through these three core components:
1. Trend Identification The script first establishes the primary direction of the market. It uses a specialized trend calculation to determine if the overall momentum is bullish (positive) or bearish (negative). This serves as the foundation for all other classifications.
2. Multi-Speed Momentum Analysis To understand how aggressively the price is moving, the script compares three different layers of Relative Strength Index (RSI) data:
- Fast Momentum: How the price is reacting in the immediate short term.
- Slow Momentum: The broader trend of strength over a longer period.
- Standard Momentum: A balancing figure used to identify specific "cross-over" points.
3. Behavioral Classification By comparing these three momentum layers against the primary trend, the script sorts the market into eight distinct visual states:
- Strong Trends: Occur when all momentum indicators are aligned perfectly with the primary trend (e.g., everything is moving upward in a bullish market).
- Retracements: Occur when the primary trend remains intact, but the immediate momentum shows a slight pullback or "breathing" phase (the price is still moving up/down overall, but slowing momentarily).
- Choppy Markets: Occur when the momentum indicators are conflicting or inconsistent with each other, suggesting high volatility and less predictability.
- Trend Change Alerts: These signals identify specific "tipping points" where the relationship between fast and slow momentum suggests the current trend may be about to exhaust itself or reverse.
Visual Interpretation
The indicator renders these states as different colored bars on your chart. By looking at these colors, a trader can quickly distinguish between a "high-confidence" move (Strong Trend), a period of rest (Retrace), and a dangerous, disorganized market (Choppy). This allows for a more nuanced understanding of market structure beyond simple price movement.
//+------------------------------------------------------------------+
//| StepChoppyBars_v2.mq4 |
//| Copyright © 2007, Forex-TSD.com |
//| Written by IgorAD,igorad2003@yahoo.co.uk |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Forex-TSD.com "
#property link "http://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 MediumBlue
#property indicator_color2 Crimson
#property indicator_color3 DodgerBlue
#property indicator_color4 Tomato
#property indicator_color5 LightBlue
#property indicator_color6 Orange
#property indicator_color7 Aqua
#property indicator_color8 Yellow
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2
#property indicator_width7 2
#property indicator_width8 2
//---- input parameters
extern int Length = 10;
extern double Kv = 1.0;
extern double StepSize = 0;
extern int MA_Mode = 0;
extern bool HighLow = false;
extern double StepSizeFast = 5;
extern double StepSizeSlow = 15;
int MAPeriod =1;
int Price =0;
int Mode =2;
//---- buffers
double UpBuffer1[];
double DnBuffer1[];
double UpBuffer2[];
double DnBuffer2[];
double UpBuffer3[];
double DnBuffer3[];
double UpBuffer4[];
double DnBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,UpBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,DnBuffer1);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,UpBuffer2);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3,DnBuffer2);
SetIndexStyle(4,DRAW_HISTOGRAM);
SetIndexBuffer(4,UpBuffer3);
SetIndexStyle(5,DRAW_HISTOGRAM);
SetIndexBuffer(5,DnBuffer3);
SetIndexStyle(6,DRAW_HISTOGRAM);
SetIndexBuffer(6,UpBuffer4);
SetIndexStyle(7,DRAW_HISTOGRAM);
SetIndexBuffer(7,DnBuffer4);
//----
string short_name="StepChoppyBars_v2";
IndicatorShortName(short_name);
SetIndexLabel(0,"Strong UpTrend");
SetIndexLabel(1,"Strong DownTrend");
SetIndexLabel(2,"Retrace UpTrend");
SetIndexLabel(3,"Retrace DownTrend");
SetIndexLabel(4,"Choppy UpTrend");
SetIndexLabel(5,"Choppy DownTrend");
SetIndexLabel(6,"Be ready to change UpTrend");
SetIndexLabel(7,"Be ready to change DownTrend");
//----
SetIndexDrawBegin(0,Length);
SetIndexDrawBegin(1,Length);
SetIndexDrawBegin(2,Length);
SetIndexDrawBegin(3,Length);
SetIndexDrawBegin(4,Length);
SetIndexDrawBegin(5,Length);
SetIndexDrawBegin(6,Length);
SetIndexDrawBegin(7,Length);
//----
return(0);
}
//+------------------------------------------------------------------+
//| StepChoppyBars_v2 |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double RSI, FastRSI, SlowRSI, StepMA, Trend;
//----
if(Bars<=Length) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=Length;i++)
{
UpBuffer1[Bars-i]=0.0;
UpBuffer2[Bars-i]=0.0;
UpBuffer3[Bars-i]=0.0;
UpBuffer4[Bars-i]=0.0;
DnBuffer1[Bars-i]=0.0;
DnBuffer2[Bars-i]=0.0;
DnBuffer3[Bars-i]=0.0;
DnBuffer4[Bars-i]=0.0;
}
//----
if ( counted_bars > 0 ) int limit=Bars-counted_bars;
if ( counted_bars ==0 ) limit=Bars-Length-1;
for(i=limit;i>=0;i--)
{
Trend = iCustom(NULL,0,"StepMA_v7",Length,Kv,StepSize,MA_Mode,0,0,HighLow,2,0,5,i);
RSI=iCustom(NULL,0,"StepRSI_v5.2",Length,StepSizeFast,MAPeriod,Price,Mode,0,i);
FastRSI=iCustom(NULL,0,"StepRSI_v5.2",Length,StepSizeFast,MAPeriod,Price,Mode,1,i);
SlowRSI=iCustom(NULL,0,"StepRSI_v5.2",Length,StepSizeSlow,MAPeriod,Price,Mode,1,i);
UpBuffer1[i] =EMPTY;
UpBuffer2[i] =EMPTY;
UpBuffer3[i] =EMPTY;
UpBuffer4[i] =EMPTY;
DnBuffer1[i] =EMPTY;
DnBuffer2[i] =EMPTY;
DnBuffer3[i] =EMPTY;
DnBuffer4[i] =EMPTY;
if (FastRSI > SlowRSI && RSI > FastRSI && Trend>0)
{UpBuffer1[i] = High[i];DnBuffer1[i] = Low[i] ;}
else
if (FastRSI > SlowRSI && RSI < FastRSI && Trend>0)
{UpBuffer2[i] = High[i];DnBuffer2[i] = Low[i] ;}
else
if (FastRSI < SlowRSI && RSI > FastRSI && Trend>0)
{UpBuffer3[i] = High[i];DnBuffer3[i] = Low[i] ;}
else
if (FastRSI < SlowRSI && RSI < FastRSI && Trend>0)
{UpBuffer4[i] = High[i];DnBuffer4[i] = Low[i] ;}
else
if (FastRSI < SlowRSI && RSI < FastRSI && Trend<0)
{DnBuffer1[i] = High[i];UpBuffer1[i] = Low[i];}
else
if (FastRSI < SlowRSI && RSI > FastRSI && Trend<0)
{DnBuffer2[i] = High[i];UpBuffer2[i] = Low[i];}
else
if (FastRSI > SlowRSI && RSI < FastRSI && Trend<0)
{DnBuffer3[i] = High[i];UpBuffer3[i] = Low[i];}
else
if (FastRSI > SlowRSI && RSI > FastRSI && Trend<0)
{DnBuffer4[i] = High[i];UpBuffer4[i] = Low[i];}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments