This script is a custom technical analysis tool designed to help traders visualize market volatility and price trends simultaneously. It functions by creating a "channel" on the trading chart, which serves as a visual guide for identifying potential overextended prices or trend shifts.
Core Logic and Methodology
The indicator operates by calculating two distinct boundary lines based on three primary mathematical components:
1. The Trend Baseline (EMA) The foundation of the tool is an Exponential Moving Average (EMA). Unlike a simple average, this method gives more weight to recent price data, allowing the indicator to react more quickly to new market movements while still smoothing out minor "noise."
2. The Volatility Measurement (ATR) To determine how wide the trading channel should be, the script uses an Average True Range (ATR). This measure calculates the typical range of price Bewegung over a specific period. By incorporating this, the tool ensures that the boundaries expand during periods of high market activity and contract when the market is relatively calm.
3. The Multiplier (Factor) The "Factor" acts as a sensitivity toggle. It determines how many units of volatility are added to or subtracted from the baseline. A higher factor creates a wider channel, which is useful for identifying significant structural shifts, while a lower factor creates a tighter channel for more sensitive analysis.
How it Appears on the Chart
The script generates two separate red lines plotted on your main chart:
- The Upper Boundary: This is created by taking the Trend Baseline and adding the volatility measurement (multiplied by your chosen factor). It represents a resistance level or an "overbought" ceiling.
- The Lower Boundary: This is created by taking the Trend Baseline and subtracting the volatility measurement (multiplied by your chosen factor). It represents a support level or an "oversold" floor.
Summary for Traders
In practical terms, this tool creates a dynamic corridor. When the price stays within these two lines, it suggests the market is following its current trend. When the price breaks significantly outside of these boundaries, it may signal that the market is entering a period of extreme movement or that a trend reversal might be underway.
//+------------------------------------------------------------------+
//| KC.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- Matsu
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
//---- indicator parameters
extern int EMA=20;
extern int ATR=20;
extern double Factor=1.5;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexDrawBegin(0,EMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer2))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("KC("+EMA+","+ATR+","+Factor+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- KC counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ind_buffer1[i]=iMA(NULL,0,EMA,0,MODE_EMA,PRICE_CLOSE,i) + iATR(NULL,0,ATR,0)*Factor;
//---- signal line counted in the 2-nd additional buffer
for(i=0; i<limit; i++)
ind_buffer2[i]=iMA(NULL,0,EMA,0,MODE_EMA,PRICE_CLOSE,i) - iATR(NULL,0,ATR,0)*Factor;
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments