All_usd_pair2

Download script
Author: kukan
All_usd_pair2

This script is designed as a specialized technical analysis tool for the MetaTrader platform. Its primary purpose is to synchronize and visualize multiple currency pairs on a single chart, allowing a trader to observe the movement of various assets relative to one another in a unified visual space.

Core Logic and Functionality

Multi-Asset Tracking The script simultaneously monitors six specific currency pairs: EURUSD, GBPUSD, AUDUSD, USDCHF, USDJPY, and USDCAD. Instead of looking at these on separate windows, the tool brings their data into one place.

Dynamic Normalization (The "Central Line") Because different currency pairs have vastly different price points (for example, USDJPY might trade at 140.00 while EURUSD trades at 1.08), they cannot be overlaid on a standard chart without looking cluttered or unreadable. To solve this, the script uses a mathematical "normalization" process:

  • It calculates a moving average (a "center") for all six currency pairs based on a user-defined number of bars.
  • It then calculates a conversion coefficient for each pair. This essentially "stretches" or "shrinks" the price data of each currency so that they appear to move in proportion to one another.

Correlation Adjustment The script includes a specific logic toggle for each currency pair (Direct or Inverse). This allows the user to flip the visual direction of certain pairs. For instance, if two currencies usually move in opposite directions, the user can set the script to invert that data so that all lines on the chart move in the same visual direction, making it easier to spot correlations.

Visual Representation The script generates eight distinct data buffers, which are displayed as colored lines on your chart. Each line represents a different currency pair, color-coded for clarity (e.g., Brown, Red, Green, Blue, Magenta, etc.).

Real-Time Data Overlay In addition to the moving lines, the script provides a live text update. On the most recent bar of the chart, it generates floating text labels that display the current price of each currency pair alongside its respective color. This allows you to see both the historical "path" of the currencies and their current exact values simultaneously.

Safety Checks The logic includes a built-in data integrity check. It ensures that there are enough historical bars available on your chart to perform the necessary calculations. If the history is too short, it will display an alert on the screen rather than attempting to calculate incorrect data.

Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
All_usd_pair2
//+------------------------------------------------------------------+
//|                                                 All_usd_pair.mq4 |
//|                                                            kukan |
//|                                                     www.kukan.ru |
//+------------------------------------------------------------------+
#property copyright "kukan"
#property link      "www.kukan.ru"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Brown
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Blue
#property indicator_color5 Magenta
#property indicator_color6 Tan
#property indicator_color7 CadetBlue
#property indicator_color8 DarkOrchid

extern   int line_centre = 400;  //óñðåäíåíèå êîëëè÷åñòâî áàðîâ
extern   int dir_EurUsd = 1;  //ôëàãè êîððåëÿöèé âàëþò 1 ïðÿìàÿ 0 îáðàòíàÿ
extern   int dir_GbpUsd = 1;
extern   int dir_AudUsd = 1;
extern   int dir_UsdChf = 0;  //ïî óìîë÷àíèþ ê äîëëàðó íàñòðîåíî
extern   int dir_UsdJpy = 0;
extern   int dir_UsdCad = 0;


int   ia, ib, ic, id, ie = 0;
int   cnt1, cnt2, temp0, temp1 = 0;
double   centre_EurUsd, centre_UsdChf, centre_GbpUsd, centre_UsdJpy; 
double   centre_AudUsd, centre_UsdCad, centre_curent;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];

double EurUsd[], UsdChf[], GbpUsd[], UsdJpy[], AudUsd[], UsdCad[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,ExtMapBuffer8);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("EurUsd");
   ObjectDelete("GbpUsd");
   ObjectDelete("AudUsd");
   ObjectDelete("UsdChf");
   ObjectDelete("UsdJpy");
   ObjectDelete("UsdCad");  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted();
//---- 
   ArrayCopySeries(EurUsd, MODE_CLOSE, "EURUSD", Period());
   ArrayCopySeries(GbpUsd, MODE_CLOSE, "GBPUSD", Period());
   ArrayCopySeries(AudUsd, MODE_CLOSE, "AUDUSD", Period());
   ArrayCopySeries(UsdChf, MODE_CLOSE, "USDCHF", Period());
   ArrayCopySeries(UsdJpy, MODE_CLOSE, "USDJPY", Period());
   ArrayCopySeries(UsdCad, MODE_CLOSE, "USDCAD", Period());
   //íàõîäèì ðàçìåð íàèìåíüøåãî ìàññèâà
   temp0 = Bars - 1;
   if(ArraySize(EurUsd) < temp0 + 1)  
     {
       temp0 = ArraySize(EurUsd) - 1;
       Comment("ìàëî äàííûõ íà EurUsd " + Period() + " " + ArraySize(EurUsd));
     }
   if(ArraySize(GbpUsd) < temp0 + 1)  
     {
       temp0 = ArraySize(GbpUsd) - 1;
       Comment("ìàëî äàííûõ íà GbpUsd " + Period() + " " + ArraySize(GbpUsd));
     }
   if(ArraySize(AudUsd) < temp0 + 1 )  
     {
       temp0 = ArraySize(AudUsd) - 1;
       Comment("ìàëî äàííûõ íà AudUsd " + Period() + " " + ArraySize(AudUsd)); 
     }
   if(ArraySize(UsdChf) < temp0 + 1)  
     {
       temp0 = ArraySize(UsdChf) - 1;
       Comment("ìàëî äàííûõ íà UsdChf " + Period() + " " + ArraySize(UsdChf));
     }
   if(ArraySize(UsdJpy) < temp0 + 1)  
     {
       temp0 = ArraySize(UsdJpy) - 1;
       Comment("ìàëî äàííûõ íà UsdJpy " + Period() + " " + ArraySize(UsdJpy));
     }
   if(ArraySize(UsdCad) < temp0 + 1)  
     {
       temp0 = ArraySize(UsdCad) - 1;
       Comment("ìàëî äàííûõ íà UsdCad " + Period() + " " + ArraySize(UsdCad));
     }
   //åñëè íà ãðàôèêå áàðîâ ìåíüøå ÷åì ëèíèÿ óñðåäíåíèÿ, òî âûõîä
   if(line_centre >= temp0) 
     {
       Comment("ÍÅÕÂÀÒÀÅÒ ÄÀÍÍÛÕ Â ÀÐÕÈÂÀÕ.... ");
       return(0);
     }
   //ñìîòðèì ñêîëüêî ñ÷èòàòü
   if(temp0 - line_centre < Bars - counted_bars)  
       temp1 = temp0 - line_centre;
   else  
       temp1 = Bars - counted_bars;
//----
   for(ia = temp1; ia >= 0; ia--) 
     {
       //âû÷èñëÿåì ñðåäíèå çíà÷åíèÿ âûëþò
       centre_EurUsd = 0;
       centre_GbpUsd = 0;
       centre_AudUsd = 0;
       centre_UsdChf = 0;
       centre_UsdJpy = 0;
       centre_UsdCad = 0;
       centre_curent = 0;
       //----
       for(ic = line_centre - 1; ic >= 0; ic--) 
         {
           centre_EurUsd = centre_EurUsd + EurUsd[ia+ic]; 
           centre_GbpUsd = centre_GbpUsd + GbpUsd[ia+ic]; 
           centre_AudUsd = centre_AudUsd + AudUsd[ia+ic]; 
           centre_UsdChf = centre_UsdChf + UsdChf[ia+ic]; 
           centre_UsdJpy = centre_UsdJpy + UsdJpy[ia+ic]; 
           centre_UsdCad = centre_UsdCad + UsdCad[ia+ic]; 
           centre_curent = centre_curent + Close[ia+ic]; 
         }
       centre_EurUsd = centre_EurUsd / line_centre;
       centre_GbpUsd = centre_GbpUsd / line_centre;
       centre_AudUsd = centre_AudUsd / line_centre;
       centre_UsdChf = centre_UsdChf / line_centre;
       centre_UsdJpy = centre_UsdJpy / line_centre;
       centre_UsdCad = centre_UsdCad / line_centre;
       centre_curent = centre_curent / line_centre;
       //ïðèâîäèì ê åäèíîé öåíòðàëüíîé ëèíèè, ò.å. âû÷èñëÿåì êîîôèöèåíò ïåðåñ÷åòà
       ExtMapBuffer1[ia] = (dir_EurUsd*EurUsd[ia] + (1 - dir_EurUsd) / 
                            EurUsd[ia])*centre_curent / (dir_EurUsd*centre_EurUsd + 
                            (1 - dir_EurUsd) / centre_EurUsd);
       ExtMapBuffer2[ia] = (dir_GbpUsd*GbpUsd[ia] + (1 - dir_GbpUsd) / 
                            GbpUsd[ia])*centre_curent / (dir_GbpUsd*centre_GbpUsd + 
                            (1 - dir_GbpUsd) / centre_GbpUsd);
       ExtMapBuffer3[ia] = (dir_AudUsd*AudUsd[ia] + (1 - dir_AudUsd) / 
                            AudUsd[ia])*centre_curent / (dir_AudUsd*centre_AudUsd + 
                            (1 - dir_AudUsd) / centre_AudUsd);
       ExtMapBuffer4[ia] = (dir_UsdChf*UsdChf[ia] + (1 - dir_UsdChf) / 
                            UsdChf[ia])*centre_curent / (dir_UsdChf*centre_UsdChf + 
                            (1 - dir_UsdChf) / centre_UsdChf);
       ExtMapBuffer5[ia] = (dir_UsdJpy*UsdJpy[ia] + (1 - dir_UsdJpy) / 
                            UsdJpy[ia])*centre_curent / (dir_UsdJpy*centre_UsdJpy + 
                            (1 - dir_UsdJpy) / centre_UsdJpy);
       ExtMapBuffer6[ia]= (dir_UsdCad*UsdCad[ia] + (1 - dir_UsdCad) / 
                           UsdCad[ia])*centre_curent / (dir_UsdCad*centre_UsdCad + 
                           (1 - dir_UsdCad) / centre_UsdCad);
       /*
       Comment("îòíîñèòåëüíûå èçìåíåíèÿ âàëþòíûõ ïàð "+Period()
          +"\nGBPUSD  -"+GbpUsd[0]
          +"\nUSDJPY  -"+UsdJpy[0]
          );
       */
       if((Bars-counted_bars) == 1)   
         {
           //ïîäïèñûâàíèå êîòèðîâîê ðàçíûõ âàëþò
           ObjectDelete("EurUsd");
           ObjectCreate("EurUsd", OBJ_TEXT, 0, Time[0] + Period()*11*60, ExtMapBuffer1[0]);
           ObjectSet("EurUsd", OBJPROP_COLOR, Brown);
           ObjectSetText("EurUsd", "EurUsd " + DoubleToStr(EurUsd[0], 4), 8, "arial");
           //----
           ObjectDelete("GbpUsd");
           ObjectCreate("GbpUsd", OBJ_TEXT, 0, Time[0] + Period()*11*60, ExtMapBuffer2[0]);
           ObjectSet("GbpUsd", OBJPROP_COLOR, Red);
           ObjectSetText("GbpUsd", "GbpUsd " + DoubleToStr(GbpUsd[0], 4), 8, "arial");
           //----
           ObjectDelete("AudUsd");
           ObjectCreate("AudUsd", OBJ_TEXT, 0, Time[0] + Period()*11*60, ExtMapBuffer3[0]);
           ObjectSet("AudUsd", OBJPROP_COLOR, Green);
           ObjectSetText("AudUsd", "AudUsd " + DoubleToStr(AudUsd[0], 4), 8, "arial");
           //----
           ObjectDelete("UsdChf");
           ObjectCreate("UsdChf", OBJ_TEXT, 0, Time[0] + Period()*11*60, ExtMapBuffer4[0]);
           ObjectSet("UsdChf", OBJPROP_COLOR, Blue);
           ObjectSetText("UsdChf", "UsdChf " + DoubleToStr(UsdChf[0], 4), 8, "arial");
           //----
           ObjectDelete("UsdJpy");
           ObjectCreate("UsdJpy", OBJ_TEXT, 0, Time[0] + Period()*11*60, ExtMapBuffer5[0]);
           ObjectSet("UsdJpy", OBJPROP_COLOR, Magenta);
           ObjectSetText("UsdJpy", "UsdJpy " + DoubleToStr(UsdJpy[0], 2), 8, "arial");
           //----
           ObjectDelete("UsdCad");
           ObjectCreate("UsdCad", OBJ_TEXT, 0, Time[0] + Period()*11*60, ExtMapBuffer6[0]);
           ObjectSet("UsdCad", OBJPROP_COLOR, Tan);
           ObjectSetText("UsdCad", "UsdCad " + DoubleToStr(UsdCad[0], 4), 8, "arial");
         }

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

Comments