All_usd_pair_v1

Download script
Author: kukan
All_usd_pair_v1

Technical Logic Overview

This script is designed to provide a multi-currency visual analysis on a single trading chart. Its primary purpose is to "normalize" the price action of several different currency pairs simultaneously, allowing a trader to see how they relate to a central moving average or reference point.

Core Functionality

The logic operates by gathering real-time data from six specific currency pairs: EURUSD, GBPUSD, AUDUSD, USDCHF, USDJPY, and USDCAD. Instead of looking at these pairs in isolation, the script brings them into a unified visual space.

Key Processes

  • Data Collection & Synchronization: The script continuously pulls the closing prices for all six currency pairs. It checks to ensure that there is enough historical data available for all pairs; if one pair has less data than the required calculation window, it will notify the user via an on-screen comment.

  • Moving Average Calculation: The tool uses a user-defined "center line" (the number of bars to look back). It calculates a simple average for every currency pair over this specific timeframe. This establishes a baseline for each pair's recent price movement.

  • Mathematical Normalization (The "Scaling" Logic): This is the most important part of the script. Because different currencies have different values (e.g., USDJPY might be 150.00 while EURUSD is 1.08), they cannot normally be plotted on the same chart together. The script applies a mathematical formula to "re-scale" each currency pair. It calculates a conversion coefficient based on the current price relative to its moving average and compares it to the primary chart's own moving average. This allows all six pairs to be drawn as lines that move in proportion to one another on a single scale.

  • Directional Flexibility: The logic includes "Direction" settings for each pair. This allows the user to choose whether a pair should be displayed normally (direct correlation) or flipped upside down (inverse correlation). For example, if two currencies move in opposite directions, the script can flip one of them visually so that their trends appear synchronized on your screen.

  • Real-Time Labeling: On the most recent price candle, the script dynamically generates text labels for each currency. These labels display the current price of each pair, helping the trader keep track of the exact values across all six assets without having to switch between different tabs or charts.

Summary for the User

Essentially, this script acts as a multi-currency dashboard. It takes various currency pairs with different price magnitudes, scales them down (or up) so they "fit" on one chart together, and plots them as colored lines. This allows you to see at a glance how multiple markets are reacting to global economic shifts simultaneously.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
All_usd_pair_v1
//+------------------------------------------------------------------+
//|                                                 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 Yellow
#property indicator_color2 OrangeRed
#property indicator_color3 PaleGreen
#property indicator_color4 Blue
#property indicator_color5 ForestGreen
#property indicator_color6 Tan
#property indicator_color7 SpringGreen
#property indicator_color8 Aqua
//---- buffers
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,centre_AudUsd,centre_UsdCad;
double   centre_curent;
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);
//----
   ArrayInitialize(ExtMapBuffer1,EMPTY_VALUE);
   ArrayInitialize(ExtMapBuffer2,EMPTY_VALUE);
   ArrayInitialize(ExtMapBuffer3,EMPTY_VALUE);
   ArrayInitialize(ExtMapBuffer4,EMPTY_VALUE);
   ArrayInitialize(ExtMapBuffer5,EMPTY_VALUE);
   ArrayInitialize(ExtMapBuffer6,EMPTY_VALUE);
   ArrayInitialize(ExtMapBuffer7,EMPTY_VALUE);
   ArrayInitialize(ExtMapBuffer8,EMPTY_VALUE);
   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,Yellow);
         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,OrangeRed);
         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,PaleGreen);
         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,ForestGreen);
         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