Author: Copyright � 2006, Forex-TSD.com
EMA_levels

This tool is designed to provide a visual framework for identifying market trends and potential price boundaries. By analyzing historical price data, it generates a three-line visual system that helps traders understand the "fair value" of an asset and the zones where the price might encounter resistance or support.

Core Components

The logic operates by establishing a central moving average as its foundation, from which it projects two surrounding boundaries. Here is how those components function:

1. The Trend Baseline (Moving Average) At its center is a primary line that calculates the average price of the asset over a specific period. This serves as the "anchor" for the entire tool. By following this line, you can see the overall direction of the market; when the line slopes upward, it indicates a bullish trend, and when it slopes downward, it suggests a bearish environment.

2. The Dynamic Boundaries (Upper and Lower Bands) The script automatically generates two additional lines—one above and one below the central moving average. These are calculated by adding and subtracting a specific fixed distance from the baseline.

  • The Upper Band: Represents a target zone or a level of potential overextension.
  • The Lower Band: Represents a floor or a zone where the price may find support.

How the Logic Works in Practice

The tool works by continuously scanning every candle on your chart and updating these three lines in real-time. Because the central baseline is "moving," the boundaries move with it, creating a dynamic channel rather than static horizontal lines.

For a user, this creates a visual "envelope." When the price stays within these bounds, it suggests the market is moving in a stable trend relative to its average. When the price pushes toward or outside of these bands, it signals that the asset is moving significantly away from its mean, which can help identify opportunities for entries, exits, or recognizing periods of high volatility.

Summary of Customization

The behavior of the tool is governed by three main factors:

  • The Period: Determines how much historical data is used to calculate the average (longer periods result in smoother lines; shorter periods make the tool more reactive).
  • The Calculation Mode: Dictates how the average is weighted (giving more importance to recent price action).
  • The Offset: Determines how wide the "envelope" is. By adjusting this, you can make the upper and lower bands tighter or spread them further apart to suit different market conditions.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
EMA_levels
//+------------------------------------------------------------------+
//|                                                  EMABands_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 4
#property indicator_color1 Blue
#property indicator_color2 Silver
#property indicator_color3 Silver

//---- input parameters
extern int RPeriod=25;
extern int MA_mode=1;
extern int OffSet=40;

//---- indicator buffers
double MABuffer[];
double UpBuffer[];
double DnBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);

   SetIndexBuffer(0,MABuffer);
   SetIndexBuffer(1,UpBuffer);
   SetIndexBuffer(2,DnBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="EMA_levels("+RPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"MA");
   SetIndexLabel(1,"Up");
   SetIndexLabel(2,"Dn");
//----
   SetIndexDrawBegin(0,RPeriod);
   SetIndexDrawBegin(1,RPeriod);
   SetIndexDrawBegin(2,RPeriod);
   
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| EMA_Levels                                                       |
//+------------------------------------------------------------------+
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-RPeriod-1; 
     
	for(shift=limit;shift>=0;shift--) 
   {	
   MABuffer[shift] = iMA(NULL,0,RPeriod,0,MA_mode,PRICE_CLOSE,shift);
   UpBuffer[shift] = MABuffer[shift] + OffSet*Point;
   DnBuffer[shift] = MABuffer[shift] - OffSet*Point;
	}
	return(0);	
 }

Comments