Chande_Kroll_Stop_v1_v1
Download scriptThis tool is designed to help traders visualize and identify the prevailing trend in a financial market by establishing dynamic "stop" levels. Instead of using fixed price points, it calculates two moving boundaries—an upper boundary and a lower boundary—that adapt to the current volatility and price action of the market.
How the Logic Works
The indicator operates by analyzing three primary components of market data:
1. Volatility Measurement The script looks at a specific period of recent price history to determine how much the market is currently "swinging." By measuring this volatility, the tool ensures that the trend lines aren't too tight during choppy markets or too loose during stable ones. It uses this measurement as a multiplier to create a buffer zone around the price.
2. High and Low Range Detection The logic identifies the highest highs and the lowest lows reached within a recent window of time.
- For the Lower Boundary: It takes the lowest point reached and adds a specific distance (based on volatility) to it.
- For the Upper Boundary: It takes the highest point reached and subtracts a specific distance from it.
3. Trend Tracking and Filtering To ensure the lines are smooth and provide reliable signals, the script performs a "look-back" over a set number of bars. Rather than just plotting the current calculation, it compares the values across this look-back period to find the most significant boundaries.
Visual Interpretation
The result is represented by two distinct lines on your chart:
- The Upper Line: Acts as a ceiling for the price. As long as the price remains below this line, the market is generally considered to be in a bearish or neutral state. If the price breaks above it, it signals a potential shift toward an upward trend.
- The Lower Line: Acts as a floor for the price. As long as the price stays above this line, the market is considered to be in a bullish or neutral state. A break below this line typically signals a shift toward a downward trend.
Summary for Traders
Essentially, this script automates the process of finding "support" and "resistance" levels that move with the market. By constantly recalculating these boundaries based on recent highs, lows, and volatility, it provides a visual guide to help you stay on the right side of the trend and identify potential reversal points more clearly.
//+------------------------------------------------------------------+
//| Chande_Kroll_Stop_v1.mq4 |
//| Copyright © 2006, Forex-TSD.com |
//| Written by IgorAD,igorad2003@yahoo.co.uk |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link "http://www.forex-tsd.com/"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int Length =20;
extern int ATRPeriod =10;
extern double Kv =3;
//---- indicator buffers
double UpTrend[];
double DnTrend[];
double smin[];
double smax[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
IndicatorBuffers(4);
SetIndexBuffer(0,UpTrend);
SetIndexBuffer(1,DnTrend);
SetIndexBuffer(2,smin);
SetIndexBuffer(3,smax);
//---- name for DataWindow and indicator subwindow label
short_name="Chande Kroll Stop("+Length+","+ATRPeriod+","+Kv+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"UpTrend");
SetIndexLabel(1,"DnTrend");
//----
SetIndexDrawBegin(0,Length);
SetIndexDrawBegin(1,Length);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Chande_Kroll_Stop_v1 |
//+------------------------------------------------------------------+
int start()
{
int shift,limit, counted_bars=IndicatorCounted();
//----
if(counted_bars > 0) limit=Bars-counted_bars;
if(counted_bars < 0) return(0);
if(counted_bars ==0) limit=Bars-Length-1;
//----
for(shift=limit;shift>=0;shift--)
{
smin[shift]=High[Highest(NULL,0,MODE_HIGH,ATRPeriod,shift)] - Kv*iATR(NULL,0,ATRPeriod,shift);
smax[shift]=Low [Lowest (NULL,0,MODE_LOW ,ATRPeriod,shift)] + Kv*iATR(NULL,0,ATRPeriod,shift);
//
UpTrend[shift]=-10000000;
DnTrend[shift]= 10000000;
//----
for(int i=Length-1;i>=0;i--)
{
UpTrend[shift]=MathMax( UpTrend[shift], smin[shift+i]);
DnTrend[shift]=MathMin( DnTrend[shift], smax[shift+i]);
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments