chart_MACD_4

Download script
Author: Copyright � 2008, MetaQuotes Software Corp.

This script is a specialized multi-currency analysis tool designed to monitor and visualize the momentum of various major currency pairs simultaneously. Instead of looking at just one market, it aggregates data from several different currencies to provide a broader perspective on market sentiment.

Core Functionality

Multi-Currency Monitoring The tool allows you to toggle specific currencies (such as EUR, GBP, USD, etc.) on or off. Based on your selections, the script automatically calculates the momentum for these pairs. It identifies which currencies are active and organizes them into a visual list on your trading chart.

Momentum Calculation (The "Delta" Logic) For every active currency pair, the script utilizes a modified MACD (Moving Average Convergence Divergence) calculation. It takes the standard MACD value and normalizes it against the current price of the currency. This conversion turns raw movement data into a "delta"—a percentage-based representation of momentum—making it easier to compare different currencies on an equal footing.

Visual Representation The script provides several layers of visual information:

  • Trend Lines: It plots lines for each active currency pair, allowing you to see the direction and strength of their individual movements over a specific period of history.
  • Real-Time Values: The tool dynamically creates text labels on the chart that display the current momentum value for each pair. These values update in real-time as new price data arrives.
  • Opposite Signal Detection: A unique feature of this logic is how it handles the final item in your list. It treats the last selected currency as an "inverse" indicator, calculating its movement in the opposite direction to help identify contrasting market forces.

Composite Summary In addition to individual data, the script performs a cumulative calculation. It combines the momentum and closing prices of all active currencies into a single "Composite" value. This total is displayed as a primary label on the chart, providing a snapshot of the overall combined market strength or weakness based on your specific selection of currencies.

Summary for the User

Essentially, this tool acts as a dashboard. Instead of switching between different charts to see how the EUR, GBP, or USD are performing, this script gathers all that information into one window. It calculates how fast those currencies are moving, displays their individual trends clearly, and gives you a single "summary" number representing the combined weight of your chosen markets.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
chart_MACD_4
//+------------------------------------------------------------------+
//|                                                 chart_MACD_4.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        forex_@i.ua        KONDOR |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 8

#property indicator_color1 Gray
#property indicator_color2 Gray
#property indicator_color3 Gray
#property indicator_color4 CLR_NONE
#property indicator_color5 CLR_NONE
#property indicator_color6 CLR_NONE
#property indicator_color7 CLR_NONE
#property indicator_color8 CLR_NONE

extern int EUR= 1;  // ìîæíî âêëþ÷èòü(âûêëþ÷èòü) äàííóþ âàëþòó â(èç) ðàññ÷åò(à) èíäèêàòîðà
extern int GBP= 1;  // 0 - âûêëþ÷èòü
extern int AUD= 0;
extern int NZD= 0;
extern int USD= 1;
extern int CAD= 0;
extern int CHF= 0;
extern int JPY= 0;

extern int per1=25,per2=50,sign=3; // ïàðàìåòðû ìàêä
extern int History=200;           // êîëè÷åñòâî ðàññ÷åòíûõ áàðîâ äëÿ îòîáðàæåíèÿ èíäèêàòîðà

int type=MODE_MAIN;

double z0[],z1[],z2[],z3[],z4[],z5[],z6[],z7[];

int ind[8];
int n[];
double z[];
string simb[];
int sum=0;

string Val[8]={"EUR","GBP","AUD","NZD","USD","CAD","CHF","JPY"};
color  Valcol[8]={Red,Violet,Yellow,LightSeaGreen,Green,Aqua,Orange,FireBrick};

string    short_name;
string text;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   ind[0]=EUR;
   ind[1]=GBP;
   ind[2]=AUD;
   ind[3]=NZD;
   ind[4]=USD;
   ind[5]=CAD;
   ind[6]=CHF;
   ind[7]=JPY;


   sum=0;
   for(int a=0; a<8; a++)
     {
      if(ind[a]!=0)
        { sum++; ArrayResize(n,sum);  n[sum-1]=a; }
     }

   ArrayResize(z,sum);
   ArrayResize(simb,sum);
   ArraySort(n,WHOLE_ARRAY,0,MODE_ASCEND); // ñîðòèðîâêà èíäåêñîâ ïî âîçðàñòàíèþ

   for(a=0; a<sum; a++)
     {

      if(a!=sum-1) simb[a]=Val[n[a]]+Val[n[a+1]]; else
      if(a==sum-1)simb[a]=Val[n[0]]+Val[n[sum-1]];

     }

//IndicatorBuffers(sum);
   IndicatorBuffers(8);

   SetIndexBuffer(0,z0);
   SetIndexBuffer(1,z1);
   SetIndexBuffer(2,z2);
   SetIndexBuffer(3,z3);
   SetIndexBuffer(4,z4);
   SetIndexBuffer(5,z5);
   SetIndexBuffer(6,z6);
   SetIndexBuffer(7,z7);

   text="";
   for(a=0;a<sum;a++)
     {
      SetIndexStyle(a,DRAW_LINE,EMPTY,EMPTY,col(a));
      SetIndexLabel(a,simb[a]);

      if(a==sum-1) text=simb[a];
      text=StringConcatenate( text, " îòîáðàæàåòñÿ ñ ïðîòèâîïîëîæíûì çíàêîì ");
     }

   IndicatorDigits(2);

   short_name=text;
   IndicatorShortName(short_name);

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

   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit--;

   if(limit>History-1) limit=History-1;
   ArrayResize(z,ArraySize(z0));
//-------------------------------------------------------------------------------------------
   int xtot=20;   int y=5;
   for(int  i=0;i<History;i++)
     {

      for(int a=0;a<sum;a++)
        {

         z[a]= delta(simb[a], i);
         if(a==sum-1)z[a]*=-1;

        }

      if(ArraySize(z)>0) z0[i]= z[0];
      if(ArraySize(z)>1) z1[i]= z[1];
      if(ArraySize(z)>2) z2[i]= z[2];
      if(ArraySize(z)>3) z3[i]= z[3];
      if(ArraySize(z)>4) z4[i]= z[4];
      if(ArraySize(z)>5) z5[i]= z[5];
      if(ArraySize(z)>6) z6[i]= z[6];
      if(ArraySize(z)>7) z7[i]= z[7];
     }

   double cls=1;
   for(a=0; a<sum; a++)
     {

        { ObjectDelete(simb[a]+"1"); Create_Tic( simb[a]+"1",simb[a]                         ,xtot+50, y+a*15, col(a)); }
        { ObjectDelete(simb[a]+"2"); Create_Tic( simb[a]+"2",DoubleToStr(delta(simb[a], 0),2),xtot,    y+a*15, col(a)); }

      double c=iClose(simb[a],0,0);
      if(a==sum-1) c=1/c;
      cls*=c;
     }

   cls*=Close[0];

   Create_Tic("chart_MACD_4",DoubleToStr(cls,Digits+1),500,40,Black);

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

int deinit()
  {
//----

   for(int a=0;a<sum;a++)
     {
      SetIndexStyle(a,DRAW_LINE,EMPTY,EMPTY,CLR_NONE);
      SetIndexLabel(a,simb[a]);
      ObjectDelete(simb[a]+"1");
      ObjectDelete(simb[a]+"2");
     }

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

double delta(string simb,int i)
  {

   return((
          iMACD(simb,0,per1,per2,sign,PRICE_CLOSE,type,i)
          )/iClose(simb,0,i)*10000);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
color  col(int d)
  {  // ô-öèÿ îïðåäåëÿåò öâåò äëÿ ðàññ÷èòûâàåìîé ëèíèè

   if(d!=sum-1) return(Valcol[d]);
   else         return(Black);

  }
//--------------------------------------------------------

int Create_Tic(string name,string text,int x,int y,color  c)
  {
   ObjectDelete(name);
   ObjectCreate(name,OBJ_LABEL,WindowFind(short_name),0,0);
   ObjectSetText(name,text,8,"Tahoma Narrow",c);
   ObjectSet(name,OBJPROP_CORNER,1);
   ObjectSet(name,OBJPROP_XDISTANCE,x);
   ObjectSet(name,OBJPROP_YDISTANCE,y);
   return;
  }
//+------------------------------------------------------------------+

Comments