MACD_4H_v05

Download script
MACD_4H_v05

This tool is designed to help traders analyze market trends by viewing data from a larger timeframe while staying on their current, smaller chart. Instead of requiring you to constantly switch between different timeframes to see the "big picture," this script automatically pulls and displays those high-level insights directly onto your active screen.

Core Logic and Functionality

Multi-Timeframe Synchronization The primary purpose of this script is to bridge the gap between short-term movements and long-term trends. It identifies a specific larger timeframe (set by the user, such as 4 hours) and calculates technical data based on that period. It then maps that information onto your current chart so you can see how the broader market is moving while you execute trades on smaller intervals.

The MACD Calculation The script utilizes the Moving Average Convergence Divergence (MACD) indicator, which is a standard momentum tool used to identify changes in the strength, direction, and duration of a trend. It processes two types of data:

  • The Main Momentum: This shows the relationship between two different moving averages (fast and slow). When these move in opposite directions, it indicates potential shifts in market pressure.
  • The Signal Line: This acts as a smoothing agent for the main momentum, helping traders identify specific "cross-over" points where a trend might be gaining or losing significant power.

Automatic Scaling To ensure the data remains accurate regardless of which chart you are currently viewing, the script performs a background calculation to determine the ratio between your current timeframe and the target larger timeframe. It automatically scales the historical data so that every bar on your current screen corresponds correctly to the correct point in time on the larger timeframe.

Visual Output

The script produces two distinct visual elements in a separate window at the bottom of your trading platform:

  1. A Histogram: Representing the main MACD momentum, which provides a visual sense of the "velocity" of the price movement.
  2. A Signal Line: A moving line that helps identify when the momentum is reaching a peak or bottom.

By using this logic, traders can maintain awareness of long-term market cycles (like 4-hour trends) without losing focus on the immediate price action of their current trading screen.

Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
MACD_4H_v05
//+------------------------------------------------------------------+
//|                                                      MACD 4H.mq4 |
//|                                         Copyright © 2006, lukas1 |
//|                                     MACD from   old   timeframe  |
//|                                     v.05                         |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2006, lukas1"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  MediumPurple
#property  indicator_color2  Red
#property  indicator_width1  2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern int AppliedPrice = 0;   // 0=PRICE_CLOSE; 1=PRICE_OPEN; 5=PRICE_TYPICAL
extern int VarPeriod=240;     //òàéìôðåéì ñòàðøåãî ïåðèîäà
         //PERIOD_M5   5         5 ìèíóò 
         //PERIOD_M15  15        15 ìèíóò 
         //PERIOD_M30  30        30 ìèíóò 
         //PERIOD_H1   60        1 ÷àñ 
         //PERIOD_H4   240       4 ÷àñà 
         //PERIOD_D1   1440      1 äåíü 
         //PERIOD_W1   10080     1 íåäåëÿ 
         //PERIOD_MN1  43200     1 ìåñÿö 
//---- indicator buffers
double     MacdBuffer[],SignalBuffer[];
int p;  // òåêóùèé ïåðèîä
int k;  // êðàòíîñòü ïåðèîäà ââåðõ
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   //p = Period();
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, 12);
   SetIndexStyle(3, 12);   
   SetIndexDrawBegin(0, SlowEMA);
   SetIndexDrawBegin(1, SlowEMA);   
   IndicatorDigits(Digits + 1);
//---- indicator buffers mapping
   SetIndexBuffer(0, MacdBuffer);
   SetIndexBuffer(1, SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD 4H (" + FastEMA + "," + SlowEMA + "," + SignalSMA + 
                      ", " + VarPeriod + "min)");
   SetIndexLabel(0, "MACD 4H(" + VarPeriod + ")");
   SetIndexLabel(1, "Signal 4H(" + VarPeriod + ")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence (MACD) for old timeframe  |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
   //---- check for possible errors
   if(counted_bars < 0)       return(-1);
   if(counted_bars <= SlowEMA)
       limit = Bars - SlowEMA ;
   else
       limit = Bars - counted_bars;   
   p = Period();
   k = VarPeriod/p;    // êðàòíîñòü ïåðèîäà ââåðõ
   for(int i=0; i<limit; i++)
      {
       MacdBuffer[i] = iMACD(NULL, VarPeriod, FastEMA, SlowEMA, SignalSMA, 
                                 AppliedPrice, 0, i/k);
       SignalBuffer[i] = iMACD(NULL, VarPeriod, FastEMA, SlowEMA, SignalSMA, 
                                 AppliedPrice, 1, i/k);
       }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments