iMA_Fibs_Below

Author: Copyright � 2005, Metaquotes
iMA_Fibs_Below

This tool is designed for traders who want to combine two popular technical analysis methods into a single visual display: Moving Averages (MA) and Fibonacci-based price levels. Instead of looking at these as separate indicators, the script dynamically links them together so that the Fibonacci levels move in real-time based on the position of the moving average.

Core Functionality

The primary logic of this script is to create a "floating" price zone. By tying the Fibonacci levels to a Moving Average, the indicator automatically adjusts as market trends shift. When the Moving Average moves up or down, all seven associated Fibonacci lines follow it simultaneously, maintaining their relative distance from the average.

Key Components of the Logic

1. Customizable Moving Averages The script allows you to choose from several different types of Moving Averages, depending on how smoothly you want to track price trends:

  • SMA (Simple): The standard average of price over a period.
  • EMA (Exponential): Places more weight on recent price action.
  • SMMA (Smoothed) & LWMA (Linear Weighted): Variations that provide different levels of "smoothness" to filter out market noise.
  • LSMA (Least Squares): A more complex calculation used to identify the linear trend of the market.

2. Dynamic Fibonacci Offsets The tool calculates seven distinct levels based on specific Fibonacci values (such as 23, 38, 50, 62, 76, 100, and 127). Rather than being fixed price targets on your screen, these are calculated as "offsets" from the Moving Average.

3. Real-Time Synchronization The script processes every historical bar on your chart to ensure the lines are continuous. For every new price tick:

  • It calculates the current position of your chosen Moving Average.
  • It then subtracts the designated Fibonacci points from that average.
  • It draws all eight resulting lines (the MA itself plus the 7 Fibonacci levels) onto your chart window.

How to Use This Information

This tool is highly effective for identifying potential support and resistance zones in a trending market. Because the Fibonacci lines are tethered to the Moving Average, they act as a dynamic "map." If the price pulls back toward these lines while the Moving Average is trending, it can signal high-probability entry points or areas where the price might encounter significant selling or buying pressure.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
iMA_Fibs_Below
//+------------------------------------------------------------------+
//|                                                     iMA_Fibs.mq4 |
//|                                Copyright © 2006, Robert L Hill   |
//|                                     mailto:robydoby314@yahoo.com |
//+------------------------------------------------------------------+
// This indicator allows selection of MA type and sets levels based on Fib values
// Added MAType 4 to use LSMA
#property copyright "Copyright © 2005, Metaquotes"
#property link      "mailto:metaquotes@metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_color3 Green
#property indicator_color4 Green
#property indicator_color5 Green
#property indicator_color6 Green
#property indicator_color7 Green
#property indicator_color8 Green
#property indicator_width1  2
#property indicator_width2  1
#property indicator_width3  1
#property indicator_width4  1
#property indicator_width5  1
#property indicator_width6  1
#property indicator_width7  1
#property indicator_width8  1


//---- input parameters
extern int       MAPeriod=14;
extern int       MAType=1;
extern int fibo1 = 23;
extern int fibo2 = 38;
extern int fibo3 = 50;
extern int fibo4 = 62;
extern int fibo5 = 76;
extern int fibo6 = 100;
extern int fibo7 = 127;

//---- buffers
double LineBuffer[];
double Fib1[];
double Fib2[];
double Fib3[];
double Fib4[];
double Fib5[];
double Fib6[];
double Fib7[];


//---- variables
int    MAMode;
string strMAType;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   //---- indicators
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,LineBuffer);
   SetIndexDrawBegin(0,MAPeriod);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Fib1);
   SetIndexDrawBegin(1,MAPeriod);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Fib2);
   SetIndexDrawBegin(2,MAPeriod);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Fib3);
   SetIndexDrawBegin(3,MAPeriod);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,Fib4);
   SetIndexDrawBegin(4,MAPeriod);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,Fib5);
   SetIndexDrawBegin(5,MAPeriod);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,Fib6);
   SetIndexDrawBegin(6,MAPeriod);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,Fib7);
   SetIndexDrawBegin(7,MAPeriod);
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName( strMAType+ " (" +MAPeriod + ") ");
   
   //----
switch (MAType)
   {
      case 1: strMAType="EMA"; MAMode=MODE_EMA; break;
      case 2: strMAType="SMMA"; MAMode=MODE_SMMA; break;
      case 3: strMAType="LWMA"; MAMode=MODE_LWMA; break;
      case 4: strMAType="LSMA"; break;
      default: strMAType="SMA"; MAMode=MODE_SMA; break;
   }
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   //---- 
   
   //----
   return(0);
}

double LSMA(int Rperiod, int shift)
{
   int i;
   double sum;
   int length;
   double lengthvar;
   double tmp;
   double wt;

   length = Rperiod;
 
   sum = 0;
   for(i = length; i >= 1  ; i--)
   {
     lengthvar = length + 1;
     lengthvar /= 3;
     tmp = 0;
     tmp = ( i - lengthvar)*Close[length-i+shift];
     sum+=tmp;
    }
    wt = sum*6/(length*(length+1));
    
    return(wt);
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   double MA;
   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;

   for(int i=limit; i>=0; i--)
   {
      if (MAType == 4)
      {
        MA = LSMA(MAPeriod,i);
      }
      else
      {
        MA = iMA(NULL,0,MAPeriod,0,MAMode,PRICE_CLOSE,i);
      }
     
      
      LineBuffer[i] = MA;
      Fib1[i] = MA - fibo1*Point;
      Fib2[i] = MA - fibo2*Point;
      Fib3[i] = MA - fibo3*Point;
      Fib4[i] = MA - fibo4*Point;
      Fib5[i] = MA - fibo5*Point;
      Fib6[i] = MA - fibo6*Point;
      Fib7[i] = MA - fibo7*Point;

   }
   
   //----
   return(0);
}
//+------------------------------------------------------------------+

Comments