MA ribbon filled mtf

Download script
Author: mladen
MA ribbon filled mtf

This tool is designed as a visual market analysis indicator that helps traders identify trends by calculating and displaying the relationship between two different moving averages. By comparing a shorter-term trend with a longer-term trend, it provides a clear visual representation of price momentum and direction.

How the Logic Works

Core Calculations The script operates by tracking two distinct types of Moving Averages (MAs). Each average is calculated based on specific parameters provided by the user, such as:

  • Period: How far back in time the indicator looks to calculate the average.
  • Method: The mathematical way the average is weighted (Linear Weighted).
  • Price Type: The specific price point used for the calculation (Closing Price).

By processing these two sets of data, the script creates a "ribbon" effect. One line represents the immediate market movement (short-term), while the other represents the broader market trend (long-term).

Multi-Timeframe Analysis One of the primary features of this logic is its ability to perform Multi-Timeframe (MTF) analysis. This means that even if you are looking at a small, fast-moving chart (like a 1-minute chart), the indicator can be configured to pull and display data from much larger timeframes (such as Hourly, Daily, or Weekly charts). It automatically synchronizes this higher-level data so that you can see the "big picture" trends directly on your current screen.

Visual Representation The script organizes these calculations into four different visual buffers:

  1. Trend Lines: The first two buffers plot the actual values of the moving averages.
  2. Histogram Elements: The remaining two buffers are designed to display as a histogram, which helps in visualizing the gap or relationship between the short-term and long-term trends.

Summary for Traders

In practical terms, this script allows you to see where the price is heading by comparing different speeds of market movement. It highlights whether the current price action is following the dominant trend or if there is a divergence occurring. Because it supports multi-timeframe data, it helps ensure that short-term trades are aligned with the broader market direction, reducing the risk of trading against the primary trend.

10 Views
0 Downloads
0 Favorites
MA ribbon filled mtf
//+------------------------------------------------------------------+
//|                                                    MA ribbon.mq4 |
//|                                               mladenfx@gmail.com |
//|                                                                  |
//| original idea by Jose Silva                                      |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 C'0,70,0'
#property indicator_color2 C'70,0,0'
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 2
#property indicator_width4 2

//
//
//
//
//

extern int       MA1Period        = 13;
extern int       MA1Method        = MODE_LWMA;
extern int       MA1Price         = PRICE_CLOSE;
extern int       MA2Period        = 26;
extern int       MA2Method        = MODE_LWMA;
extern int       MA2Price         = PRICE_CLOSE;
extern int       TimeFrame        = 0;
extern string    note_TimeFrames_ = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-currentTF";

//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
string IndicatorFileName;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   string short_name;
   SetIndexBuffer(0,buffer3); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,buffer4); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,buffer1);
   SetIndexBuffer(3,buffer2);
   switch(TimeFrame)
   {
   case 1: string TimeFrameStr = "M1" ;  break;
   case 5     :   TimeFrameStr = "M5" ;  break;
   case 15    :   TimeFrameStr = "M15";  break;
   case 30    :   TimeFrameStr = "M30";  break;
   case 60    :   TimeFrameStr = "H1" ;  break;
   case 240   :   TimeFrameStr = "H4" ;  break;
   case 1440  :   TimeFrameStr = "D1" ;  break;
   case 10080 :   TimeFrameStr = "W1" ;  break;
   case 43200 :   TimeFrameStr = "MN1";  break;
   default :      TimeFrameStr = "TF0";
   }

   TimeFrame         = MathMax(TimeFrame,Period());
   IndicatorFileName = WindowExpertName();
   short_name=("Ma Ribbon Filled("+TimeFrameStr+")") ;
   IndicatorShortName(short_name);
   return(0);
}
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
   int limit,i;
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
           limit=Bars-counted_bars;
           
   if (TimeFrame != Period())
   {
      limit = MathMax(limit,TimeFrame/Period());
      for(i=0; i<limit; i++)
      {
         int y = iBarShift(NULL,TimeFrame,Time[i]);
            buffer1[i]  = iCustom(NULL,TimeFrame,IndicatorFileName,MA1Period,MA1Method,MA1Price,MA2Period,MA2Method,MA2Price,0,y);  
            buffer2[i]  = iCustom(NULL,TimeFrame,IndicatorFileName,MA1Period,MA1Method,MA1Price,MA2Period,MA2Method,MA2Price,1,y); 
            buffer3[i]  = iCustom(NULL,TimeFrame,IndicatorFileName,MA1Period,MA1Method,MA1Price,MA2Period,MA2Method,MA2Price,2,y);
            buffer4[i]  = iCustom(NULL,TimeFrame,IndicatorFileName,MA1Period,MA1Method,MA1Price,MA2Period,MA2Method,MA2Price,3,y); 
      }
   return(0);         
  }       

   //
   //
   //
   //
   //

   for(i=limit; i>=0; i--)
   {
      buffer1[i] = iMA(NULL,0,MA1Period,0,MA1Method,MA1Price,i);
      buffer2[i] = iMA(NULL,0,MA2Period,0,MA2Method,MA2Price,i);
      buffer3[i] = buffer1[i];
      buffer4[i] = buffer2[i];
   }
   return(0);
}

Comments