Author: Copyright � 2005, MetaQuotes Software Corp.
Kanal_Ant

Overview of the Kanal_Ant.mq4 Indicator

The Kanal_Ant script is a technical analysis tool designed for the MetaTrader 4 platform. Its primary purpose is to provide traders with a visual representation of "Envelopes" and a "Moving Average" on a price chart. By plotting these specific boundaries, it helps users identify potential overbought or oversold conditions and observe the prevailing trend of the market.

Core Logic and Components

The indicator functions by calculating a central baseline and then projecting several proportional layers above and below that line. Here is a breakdown of how the logic works:

1. The Central Baseline (Moving Average)

At the heart of this script is a Moving Average (MA). This acts as the "spine" of the indicator. It calculates the average price over a specific number of previous candles (defined by the user). This line smooths out market noise, making it easier to see the general direction in which the price is moving.

2. The Envelope System

The script takes that central Moving Average and creates six surrounding boundaries, grouped into three distinct pairs. These are calculated based on a "Deviation" percentage provided by the user:

  • Inner Bounds (Level 1): These use the 0.382 Fibonacci ratio to create a tight corridor around the moving average. They represent very minor fluctuations in price.
  • Middle Bounds (Level 2): These utilize the 0.618 Fibonacci ratio. This creates a wider channel, often used to identify more significant pullbacks or corrections within a trend.
  • Outer Bounds (Level 3): These use the full Deviation percentage requested by the user. This provides the widest boundary, helping traders see the extremes of price movement relative to the average.

3. Visual Representation

To make these calculations easy to read on a live chart:

  • Color Coding: The indicator differentiates between "Upper" and "Lower" boundaries using contrasting colors (such as Blue and Red). This allows for immediate visual recognition of the channel's ceiling and floor.
  • Dynamic Labeling: The script automatically places text labels (U1, D1, U2, D2, U3, D3, and LB) at the current price point. This ensures the trader always knows which boundary line they are looking at in real-time.
  • Real-Time Updating: The logic is designed to constantly recalculate as new candles form, moving the labels and lines dynamically with the live market price.

Summary for Traders

Essentially, this tool creates a "trading tunnel." When the price stays within the inner bands, it suggests a stable trend. When the price pushes toward or breaks through the outer bands (the Level 3 boundaries), it signals that the asset may be stretched significantly far from its average price, potentially indicating a time to reconsider entries or exits.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Kanal_Ant
//+------------------------------------------------------------------+
//|                                                    Kanal_Ant.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//|                       red. Stajer59, http://www.stajer59.ucoz.ru |
//|                                      (orig.: Envelopes.mq4)      |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Red
#property indicator_color7 Teal
//---- indicator parameters
extern int     BarsCount = 500;
extern int MA_Period=55;
extern int MA_Shift=0;
extern int MA_Method=0;
extern int Applied_Price=0;
extern int     fontsize=7;
extern double Deviation=1;
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE,OBJPROP_WIDTH,2);
   SetIndexStyle(5,DRAW_LINE,OBJPROP_WIDTH,2);
   SetIndexStyle(6,DRAW_LINE,OBJPROP_WIDTH,2);
   SetIndexShift(0,MA_Shift);
   SetIndexShift(1,MA_Shift);
   SetIndexShift(2,MA_Shift);
   SetIndexShift(3,MA_Shift);
   SetIndexShift(4,MA_Shift);
   SetIndexShift(5,MA_Shift);
   SetIndexShift(6,MA_Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(MA_Period<2) MA_Period=14;
   draw_begin=MA_Period-1;
//---- indicator short name
   IndicatorShortName("Env("+MA_Period+")");
   SetIndexLabel(0,"Env("+MA_Period+")U1");
   SetIndexLabel(1,"Env("+MA_Period+")D1");
   SetIndexLabel(2,"Env("+MA_Period+")U2");
   SetIndexLabel(3,"Env("+MA_Period+")D2");
   SetIndexLabel(4,"Env("+MA_Period+")U3");
   SetIndexLabel(5,"Env("+MA_Period+")D3");
   SetIndexLabel(6,"MA("+MA_Period+")");
   SetIndexDrawBegin(0,draw_begin);
   SetIndexDrawBegin(1,draw_begin);
   SetIndexDrawBegin(2,draw_begin);
   SetIndexDrawBegin(3,draw_begin);
   SetIndexDrawBegin(4,draw_begin);
   SetIndexDrawBegin(5,draw_begin);
   SetIndexDrawBegin(6,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexBuffer(6,ExtMapBuffer7);
   
   ObjectCreate("l1", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("l1", "U1",fontsize,"Arial",Blue);
   ObjectCreate("l2", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("l2", "D1",fontsize,"Arial",Red);
   ObjectCreate("l3", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("l3", "U2",fontsize,"Arial",Blue);
   ObjectCreate("l4", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("l4", "D2",fontsize,"Arial",Red);
   ObjectCreate("l5", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("l5", "U3",fontsize,"Arial",Blue);
   ObjectCreate("l6", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("l6", "D3",fontsize,"Arial",Red);
   ObjectCreate("l7", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("l7", "LB",fontsize,"Arial",Teal);
   
   if(Deviation<0.1) Deviation=0.1;
   if(Deviation>100.0) Deviation=100.0;
//---- initialization done
   return(0);
  }
  
  //+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("l1");
   ObjectDelete("l2");
   ObjectDelete("l3");
   ObjectDelete("l4");
   ObjectDelete("l5");
   ObjectDelete("l6");
   ObjectDelete("l7");
   
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   if(Bars<=MA_Period) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   limit=Bars-ExtCountedBars;
//---- EnvelopesM counted in the buffers
   for(int i=0; i<limit; i++)
     { 
      ExtMapBuffer1[i] = (1+Deviation*0.382/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
      ExtMapBuffer2[i] = (1-Deviation*0.382/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
      ExtMapBuffer3[i] = (1+Deviation*0.618/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
      ExtMapBuffer4[i] = (1-Deviation*0.618/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
      ExtMapBuffer5[i] = (1+Deviation/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
      ExtMapBuffer6[i] = (1-Deviation/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
      ExtMapBuffer7[i] = iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
     }
     
   ObjectMove("l1", 0, Time[0],ExtMapBuffer1[0]);
   ObjectMove("l2", 0, Time[0],ExtMapBuffer2[0]);
   ObjectMove("l3", 0, Time[0],ExtMapBuffer3[0]);
   ObjectMove("l4", 0, Time[0],ExtMapBuffer4[0]);
   ObjectMove("l5", 0, Time[0],ExtMapBuffer5[0]);
   ObjectMove("l6", 0, Time[0],ExtMapBuffer6[0]);
   ObjectMove("l7", 0, Time[0],ExtMapBuffer7[0]);
     
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments