chart_delta_MACD

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

This script is a specialized financial analysis tool designed for the MetaTrader platform. Its primary purpose is to aggregate and visualize the collective momentum of various global currencies into a single, unified chart. Instead of looking at individual currency pairs in isolation, it calculates a "delta" or a net movement force based on the Moving Average Convergence Divergence (MACD) indicator across a broad spectrum of market data.

Core Functionality

The tool operates by scanning 28 different major currency pairs simultaneously. It analyzes how various currencies (such as EUR, GBP, USD, etc.) are performing relative to one another. By processing these relationships all at once, the script identifies which currencies are showing strength and which are showing weakness within the global market context.

How the Logic Works

  1. Multi-Pair Scanning: The script looks at 28 different pairs (e.g., EURUSD, GBPJPY, AUDNZD). For every candle on your chart, it retrieves data for all of these pairs simultaneously.
  2. Momentum Calculation: It uses the MACD logic—a standard momentum indicator—but applies it to four different price points: Open, High, Low, and Close. By averaging these four points, the script gets a more comprehensive view of the price action than a standard indicator would provide.
  3. Currency Weighting: The tool is designed to be customizable. You can choose which specific currencies you want to track (the "active" currencies). The script then calculates how much each currency is contributing to the overall market movement.
  4. Delta Aggregation: This is the core of the logic. It adds up the momentum values for each currency. If a currency is appearing as the base (first part) of a pair, its momentum is added; if it appears as the quote (second part), its momentum is subtracted. This allows the script to determine the "net" force of that specific currency across all active pairs.
  5. Normalization: To ensure the data is readable and consistent regardless of the price of the asset, the script divides the results by the closing price and scales them. This produces a normalized value that represents the relative strength or weakness of the currencies.

Visual Output

The result is displayed as a series of lines in a separate window on your chart. Each line corresponds to one of the major currencies.

  • Positive Movement: Shows where the currency is gaining strength relative to others.
  • Negative Movement: Shows where the currency is losing strength.
  • Customization: The user can toggle specific currencies on or off via the settings, allowing for a personalized view of the market (for example, focusing only on European currencies or only on Asian markets).

In essence, this tool acts as a "market pulse" monitor, showing you at a glance which major currencies are leading the market and which are lagging, based on the combined momentum of dozens of different trading pairs.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
chart_delta_MACD
//+------------------------------------------------------------------+
//|                                             chart_delta_MACD.mq4 |
//|                      Copyright © 2010, 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 CLR_NONE
#property indicator_color4 CLR_NONE
#property indicator_color5 Gray
#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;

int type=MODE_MAIN;

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


 string simb[28]={
 "EURGBP","EURAUD","EURNZD","EURUSD","EURCAD","EURCHF","EURJPY",
 "GBPAUD","GBPNZD","GBPUSD","GBPCAD","GBPCHF","GBPJPY","AUDNZD",
 "AUDUSD","AUDCAD","AUDCHF","AUDJPY","NZDUSD","NZDCAD","NZDCHF",
 "NZDJPY","USDCAD","USDCHF","USDJPY","CADCHF","CADJPY","CHFJPY"};
 
string Val[8] ={"EUR","GBP","AUD","NZD","USD","CAD","CHF","JPY"};
color  Valcol[8]={Red,Violet,Yellow,LightSeaGreen,Green,Aqua,Orange,FireBrick};

int n[];
int sum=0;

double z[8],z0[],z1[],z2[],z3[],z4[],z5[],z6[],z7[];
int ind[8];

//+------------------------------------------------------------------+
//| 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;  }
                               }

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);

string text="";
for(a=0;a<8;a++) {
   SetIndexStyle(a,line(a),EMPTY,EMPTY,col(a));
   SetIndexDrawBegin(a,100);
   if(ind[a]!=0) { SetIndexLabel(a,Val[a]); text=StringConcatenate(Val[a],"  ", text);}
   
                 }
                 
IndicatorDigits(2);
   
string    short_name="chart_delta_MACD ( "+ 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) counted_bars--;
   int limit=Bars-counted_bars;
   if (limit>History-1)   limit=History-1; 
   
               
//-------------------------------------------------------------------------------------------
for(int  i=0;i<History;i++){ double z[8]={0,0,0,0,0,0,0,0};

  for(int  g=0;g<28;g++){ 
  
     string V1=StringSubstr(simb[g],0,3);  
     string V2=StringSubstr(simb[g],3,3);
          
    for(int  a=0;a<8;a++) {
     
         if(V1==Val[a]) int k1=a;                
         if(V2==Val[a]) int k2=a;                   
                           
                          }
      
    
    for(  a=0;a<8;a++) {  
     
        if(StringFind(simb[g],Val[a],0)==0 && ind[k1]!=0 && ind[k2]!=0) z[a]+=delta(simb[g], i);
        if(StringFind(simb[g],Val[a],0)==3 && ind[k1]!=0 && ind[k2]!=0) z[a]-=delta(simb[g], i);
                
                       }  
                    
        z0[i]= z[0]; 
        z1[i]= z[1];
        z2[i]= z[2];
        z3[i]= z[3];
        z4[i]= z[4];
        z5[i]= z[5];
        z6[i]= z[6];
        z7[i]= z[7];
           
           } 
             
  }                   

  
//----
   return(0);
  }
//+------------------------------------------------------------------+
   
 int deinit()
  {
//----
for (int a=0;a<sum;a++) {
   SetIndexStyle(a,DRAW_LINE,EMPTY,EMPTY,CLR_NONE);
   SetIndexLabel(a,Val[a]);
                         }
//----
   return(0);
  }
  
//+------------------------------------------------------------------+ 

   double delta(string simb, int i) {   
   
   return((
   iMACD(simb,0,per1,per2,sign,PRICE_OPEN,type,i)+
   iMACD(simb,0,per1,per2,sign,PRICE_HIGH,type,i)+
   iMACD(simb,0,per1,per2,sign,PRICE_LOW,type,i) +
   iMACD(simb,0,per1,per2,sign,PRICE_CLOSE,type,i)
   )/4/(EUR+GBP+AUD+NZD+USD+CAD+CHF+JPY)/iClose(simb,0,i)*10000 );
  } 

//----------------------------------
  int line (int d) { // ô-öèÿ îïðåäåëÿåò âèä îòîáðàæåíèÿ äëÿ ðàññ÷èòûâàåìîãî ìàññèâà

   if(ind[d]!=0) return(DRAW_LINE);
   else          return(DRAW_NONE);
  
                   }
                   
//----------------------------------                   
  
  color  col(int d) { // ô-öèÿ îïðåäåëÿåò öâåò äëÿ ðàññ÷èòûâàåìîé ëèíèè

   if(ind[d]!=0) return(Valcol[d]);
   else          return(0xFFFFFFFF);
  
                   }
                  

Comments