MFCS 4TF MACD SLOPE #2b

Download script
Author: Copyright � 2009, MFCS
MFCS 4TF MACD SLOPE #2b

This script is a multi-timeframe analysis tool designed to track the "momentum slope" of the MACD (Moving Average Convergence Divergence) indicator across four different timeframes simultaneously. Instead of looking at just one chart, it allows a trader to see how the market is behaving across various scales—from small ripples to large waves—all in one visual display.

Core Logic & Functionality

1. Multi-Timeframe Synchronization The primary purpose of this tool is to provide a "bird's-eye view" of the market. It automatically identifies four specific timeframes based on the chart you are currently viewing.

  • Default Mode: If you are looking at a small timeframe (like 1 minute), it will track closely related smaller periods.
  • Higher Timeframe Mode: This shifts the focus to broader, larger intervals to help identify long-term trends.

2. Slope Detection Rather than just showing the raw value of the MACD, the script calculates the slope. It compares the current MACD value with the previous one:

  • If the current value is higher than the previous one, it indicates an upward trend (bullish momentum).
  • If the current value is lower than the previous one, it indicates a downward trend (bearish momentum).

3. Visual Representation The script translates this data into clear visual cues on your chart:

  • Arrows/Icons: It uses specific symbols (Wingdings) to point in the direction of the momentum.
  • Color Coding: It employs distinct colors (such as Dodger Blue for upward trends and Orange Red for downward trends) to make it easy to identify market sentiment at a glance.
  • Layered Display: Each of the four timeframes is assigned its own "lane" or vertical position on the indicator window, separated by a customizable gap. This prevents the signals from overlapping and allows you to see if all timeframes are moving in the same direction (confluence) or if they are conflicting.

4. Dynamic Labeling To ensure the user knows exactly which signal belongs to which timeframe, the script generates text labels dynamically. It converts the underlying numerical periods into readable formats (like M15, H1, D1, etc.) and places them on the display so you can instantly recognize the data source for each set of arrows.

Summary for the User

In simple terms, this tool tells you: "Based on the current price action, is the momentum moving up or down across these four different time horizons?" It helps filter out "noise" by showing you whether a move on your current chart is supported by larger trends or if it is an isolated event.

Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
MFCS 4TF MACD SLOPE #2b
//+------------------------------------------------------------------+
//|                                          MFCS 4TF MACD SLOPE.mq4 |
//|                                           Copyright © 2009, MFCS |
//|                                     http://www.mpatidar.com/mfcs |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MFCS"
#property link      "http://www.mpatidar.com/mfcs"


#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 5
#property indicator_buffers 8

extern string info1         = "Macd Settings";
extern int    MaFastPeriod  = 12;
extern int    MaSlowPeriod  = 26;
extern int    price         = PRICE_CLOSE;

extern string info2         = "Magic Number";
extern int    UniqueNum     = 20565;

extern string info3         = "Wingdings up or down";
extern int    ArrSizeup     = 233;
extern int    ArrSizedn     = 234;

extern string info4         = "Bar Color";
extern color  BarColorUp    = DodgerBlue;
extern color  BarColorDown  = OrangeRed;
extern color  TextColor     = White;

extern string info5         = "Bar Width";
extern int    BarWidth      = 1;
extern string info6         = "Gap between the bars";
extern double Gap           = 1;

extern string info7         = "Mode";
extern string info8         = "Mode 0: Default, lower tfs";
extern string info9         = "Mode 1: Higher TimeFrames"; 
extern int    mode          = 0;
//---- buffers
double buf4_up[];
double buf4_down[];
double buf3_up[];
double buf3_down[];
double buf2_up[];
double buf2_down[];
double buf1_up[];
double buf1_down[];

double macd0;
double macd1;

string shortname = "";


int Period_1, Period_2, Period_3, Period_4;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
  
   SetIndexStyle(0,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(0,ArrSizeup);
   SetIndexBuffer(0,buf1_up);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(1,ArrSizedn);
   SetIndexBuffer(1,buf1_down);
   SetIndexEmptyValue(1,0.0);
   SetIndexStyle(2,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(2,ArrSizeup);
   SetIndexBuffer(2,buf2_up);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(3,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(3,ArrSizedn);
   SetIndexBuffer(3,buf2_down);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(4,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(4,ArrSizeup);
   SetIndexBuffer(4,buf3_up);
   SetIndexEmptyValue(4,0.0);
   SetIndexStyle(5,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(5,ArrSizedn);
   SetIndexBuffer(5,buf3_down);
   SetIndexEmptyValue(5,0.0);
   SetIndexStyle(6,DRAW_ARROW,0,BarWidth,BarColorUp);
   SetIndexArrow(6,ArrSizeup);
   SetIndexBuffer(6,buf4_up);
   SetIndexEmptyValue(6,0.0);
   SetIndexStyle(7,DRAW_ARROW,0,BarWidth,BarColorDown);
   SetIndexArrow(7,ArrSizedn);
   SetIndexBuffer(7,buf4_down);
   SetIndexEmptyValue(7,0.0);
   
   if(mode == 0)
   {
      SetIndexLabel(0, "T1");
      SetIndexLabel(1,"T1");
      SetIndexLabel(2,"T2");
      SetIndexLabel(3,"T2");
      SetIndexLabel(4,"T3");
      SetIndexLabel(5,"T3");
      SetIndexLabel(6,"T4");
      SetIndexLabel(7,"T4");
   }
   else
   {
      SetIndexLabel(0, "T5");
      SetIndexLabel(1,"T5");
      SetIndexLabel(2,"T6");
      SetIndexLabel(3,"T6");
      SetIndexLabel(4,"T7");
      SetIndexLabel(5,"T7");
      SetIndexLabel(6,"T8");
      SetIndexLabel(7,"T8");

   }
   IndicatorDigits(0);
   getPeriod();
   
   shortname = "MFCS 4TF/8TF-MACD Slope ("+ tf2txt(Period_1)+", "+tf2txt(Period_2)+", "+tf2txt(Period_3)+", "+tf2txt(Period_4)+")";
   IndicatorShortName(shortname);
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+




int start()
  {
   
   int counted_bars=IndicatorCounted();
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   //---- the last counted bar will be recounted
   
   if(counted_bars>0) 
   {
      //counted_bars -= Period_4 / Period();      
      counted_bars--;
   }
   
   int limit=Bars-counted_bars;
   int i,tf;

   
   //-------------------------------1----------------------------------------   
   double dif = Time[0] - Time[1];
   for ( i=ObjectsTotal()-1; i>-1; i--)
      {
         if (StringFind(ObjectName(i),"FF2_"+UniqueNum + "_" + mode +"_") >= 0)  ObjectDelete(ObjectName(i));
      }
      
   for ( tf=1; tf<=4; tf++)
      {  
         string txt = "??";
         double gp;
         switch (tf)
         {
            case 1: txt = tf2txt(Period_1);  gp = 1 + mode * 4; break;
            case 2: txt = tf2txt(Period_2);  gp = 1 + Gap + mode * 4; break;
            case 3: txt = tf2txt(Period_3);  gp = 1 + Gap*2 + mode * 4; break;
            case 4: txt = tf2txt(Period_4);  gp = 1 + Gap*3 + mode * 4; break;
         }
         string name = "FF2_"+UniqueNum + "_" + mode +"_"+tf+"_"+txt;
         ObjectCreate(name, OBJ_TEXT, WindowOnDropped(), iTime(NULL,0,0)+dif*3, gp + 0.7);
         ObjectSetText(name, txt,8,"Verdana", TextColor);
      }
   
   
   
   //-------------------------------2----------------------------------------
   datetime TimeArray_4[], TimeArray_3[], TimeArray_2[], TimeArray_1[];
   ArrayCopySeries(TimeArray_1,MODE_TIME,Symbol(),Period_1);
   ArrayCopySeries(TimeArray_2,MODE_TIME,Symbol(),Period_2);
   ArrayCopySeries(TimeArray_3,MODE_TIME,Symbol(),Period_3); 
   ArrayCopySeries(TimeArray_4,MODE_TIME,Symbol(),Period_4);
   
   int  i1=0, i2=0, i3=0, i4=0, yy;

  // for(i=0, i1=0,  i2=0,  i3=0,  i4=0;i<MaxBars;i++)
   for(i=0, i1=0,  i2=0,  i3=0,  i4=0;i<limit;i++)
   {
      if (Time[i]<TimeArray_1[i1]) i1++;
      if (Time[i]<TimeArray_2[i2]) i2++;
      if (Time[i]<TimeArray_3[i3]) i3++;
      if (Time[i]<TimeArray_4[i4]) i4++;

      for ( tf = 1; tf <= 4; tf++)
      {
         int prd;
         switch (tf)
         {
            case 1: prd = Period_1; yy = i1;  break;
            case 2: prd = Period_2; yy = i2;  break;
            case 3: prd = Period_3; yy = i3;   break;
            case 4: prd = Period_4; yy = i4;   break;
         }
      
         macd0 = iMACD(NULL, prd, MaFastPeriod, MaSlowPeriod, 9, price, MODE_MAIN, yy);
         macd1 = iMACD(NULL, prd, MaFastPeriod, MaSlowPeriod, 9, price, MODE_MAIN, yy+1);
         RefreshRates();
        
         switch (tf)
         {  case 1:  if (macd1>macd0)  buf1_down[i] = 1 + mode * 4;           else buf1_up[i] = 1 + mode * 4;           break;
            case 2:  if (macd1>macd0)  buf2_down[i] = 1 + mode * 4 + Gap * 1; else buf2_up[i] = 1 + mode * 4 + Gap * 1; break;
            case 3:  if (macd1>macd0)  buf3_down[i] = 1 + mode * 4 + Gap * 2; else buf3_up[i] = 1 + mode * 4 + Gap * 2; break;
            case 4:  if (macd1>macd0)  buf4_down[i] = 1 + mode * 4 + Gap * 3; else buf4_up[i] = 1 + mode * 4 + Gap * 3; break;
         }
      }
   }
   RefreshRates();
   return(0);
  }
  
  
  
//+------------------------------------------------------------------+
void getPeriod()
{
   if(mode == 1)
   {
      switch(Period()) 
         {
            case 1: 
               Period_1=60; Period_2=240; Period_3=1440; Period_4=10080;
               break;
            case 5: 
               Period_1=240; Period_2=1440; Period_3=10080; Period_4=43200;
               break;
            case 15: 
               Period_1=1440; Period_2=10080; Period_3=43200; Period_4=43200;
               break;
            case 30: 
               Period_1=10080; Period_2=43200; Period_3=43200; Period_4=43200;
               break;
            case 60: 
               Period_1=43200; Period_2=43200; Period_3=43200; Period_4=43200;
               break;
            case 240: 
               Period_1=43200; Period_2=43200; Period_3=43200; Period_4=43200;
               break;
            case 1440: 
               Period_1=43200; Period_2=43200; Period_3=43200; Period_4=43200;
               break;
            case 10080: 
               Period_1=43200; Period_2=43200; Period_3=43200; Period_4=43200;
               break;
            case 43200: 
               Period_1=43200; Period_2=43200; Period_3=43200; Period_4=43200;
               break;
         RefreshRates();
         }
   }
   else
   {
      switch(Period()) 
      {
         case 1: 
            Period_1=1; Period_2=5; Period_3=15; Period_4=30;
            break;
         case 5: 
            Period_1=5; Period_2=15; Period_3=30; Period_4=60;
            break;
         case 15: 
            Period_1=15; Period_2=30; Period_3=60; Period_4=240;
            break;
         case 30: 
            Period_1=30; Period_2=60; Period_3=240; Period_4=1440;
            break;
         case 60: 
            Period_1=60; Period_2=240; Period_3=1440; Period_4=10080;
            break;
         case 240: 
            Period_1=240; Period_2=1440; Period_3=10080; Period_4=43200;
            break;
         case 1440: 
            Period_1=1440; Period_2=10080; Period_3=43200; Period_4=43200;
            break;
         case 10080: 
            Period_1=10080; Period_2=43200; Period_3=43200; Period_4=43200;
            break;
         case 43200: 
            Period_1=43200; Period_2=43200; Period_3=43200; Period_4=43200;
            break;
      RefreshRates();   
      }
   }
}

string tf2txt(int tf)
{
   if (tf == PERIOD_M1)    return("M1");
   if (tf == PERIOD_M5)    return("M5");
   if (tf == PERIOD_M15)   return("M15");
   if (tf == PERIOD_M30)   return("M30");
   if (tf == PERIOD_H1)    return("H1");
   if (tf == PERIOD_H4)    return("H4");
   if (tf == PERIOD_D1)    return("D1");
   if (tf == PERIOD_W1)    return("W1");
   if (tf == PERIOD_MN1)   return("MN");
   
  //----  Refresh buffers ++++++++++++++++++++ upgrade by Raff  
   int TimeFrame,TimeArray[],i;
   if (TimeFrame>Period()) {
     int PerINT=TimeFrame/Period()+1;
     datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
     ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period()); 
     for(i=0;i<PerINT+1;i++) {if (TimeArr[i]>=TimeArray[0]) {
 /********************************************************  
    Refresh buffers:         buffer[i] = buffer[0];
 ********************************************************/  
buf4_up[i]  = buf4_up[0];
buf4_down[i]= buf4_down[0];
buf3_up[i]  = buf3_up[0];
buf3_down[i]= buf3_down[0];
buf2_up[i]  = buf2_up[0];
buf2_down[i]= buf2_down[0];
buf1_up[i]  = buf1_up[0];
buf1_down[i]= buf1_down[0];

//----
   } } }
//+++++++++++++++++++++++++++++++++++++++++++++++ Raff  
 
//+-------------
  
   return("??");
}


/*bool NewBar()
{
   static datetime dt = 0;
   
   if (Time[0] != dt)
   {
      dt = Time[0];
      
      return(true);
   }
   return(false);
}
*/



Comments