Keltner_Channels_v1

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
Keltner_Channels_v1

This technical script is designed to provide traders with a visual tool called Keltner Channels, which helps identify the volatility and price trends of a specific financial instrument in real-time. Instead of just showing a single price line, this indicator creates a "channel" or "envelope" around the market price, helping users visualize whether the current price is moving within its normal range or stretching toward an extreme.

How the Logic Works

The script builds three distinct lines on your trading chart:

  1. The Middle Line (The Trend Baseline): The center of the channel represents the "heart" of the price movement. It calculates a Simple Moving Average (SMA) based on a specific number of past price cycles (the period). This line smooths out minor market fluctuations to show you the overall direction—whether the trend is moving upward, downward, or sideways.

  2. The Upper and Lower Boundaries (The Volatility Envelopes): These lines define the "walls" of the channel. To determine how wide these walls should be, the script looks at the price range (the distance between the highest and lowest points) over a set timeframe. It calculates the average of these ranges and adds it to the middle line (for the top) and subtracts it from the middle line (for the bottom).

Key Functionalities for Traders

  • Volatility Awareness: By measuring the distance between the upper and lower lines, traders can see how "nervous" or calm the market is. A wider channel indicates high volatility, while a narrower channel suggests a period of consolidation.
  • Trend Identification: If the price consistently stays near or bounces off the middle line, it confirms a steady trend.
  • Overextended Markets: When the price reaches the outer boundaries (the upper or lower lines), it often signals that the market may be "overbought" or "oversold," potentially indicating that a reversal or a period of correction could be approaching.

In essence, this tool transforms raw price data into a structured visual map, allowing you to see not just where the price is currently sitting, but the "normal" boundaries in which it usually operates.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
24 Views
0 Downloads
0 Favorites
Keltner_Channels_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                             Keltner Channels.mq4 |
//|                                                  Coded by Gilani |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 White


double upper[], middle[], lower[];
extern int period = 10;


int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,0);
   SetIndexDrawBegin(0,0);
   SetIndexBuffer(0,upper);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexShift(1,0);
   SetIndexDrawBegin(1,0);
   SetIndexBuffer(1,middle);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexShift(2,0);
   SetIndexDrawBegin(2,0);
   SetIndexBuffer(2,lower);
    
return(0);
}
int deinit(){return(0);}
int start() {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   double avg;
   
   for(int x=0; x<limit; x++) {
      middle[x] = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_CLOSE, x);
      avg  = findAvg(period, x);
      upper[x] = middle[x] + avg;
      lower[x] = middle[x] - avg;
   }
   return(0);
  }
//+------------------------------------------------------------------+


   double findAvg(int period, int shift) {
      double sum=0;
      for (int x=shift;x<(shift+period);x++) {     
         sum += High[x]-Low[x];
      }
      sum = sum/period;
      return (sum);
   }

Comments