MultiInstrument4

Download script
Author: Copyright � 2010, Vladimir Hlystov
MultiInstrument4

The provided script is designed to allow traders to visualize the relationship between multiple financial instruments simultaneously on a single chart. Instead of looking at four different windows, this tool synchronizes them into one view so you can see how they move in relation to one another.

Core Functionality

The primary purpose of this tool is comparative analysis. It takes up to four different symbols (for example, different currency pairs like EURUSD, EURGBP, etc.) and maps their price movements onto your current chart.

To ensure that the data is readable and comparable, the script uses a "Normalization" logic. Because different assets have different price values (e.g., one pair might trade at 1.10 while another trades at 150.00), the script mathematically scales all symbols so they fit within the same visual range. This allows you to see the "shape" of the trend for every instrument regardless of its actual price point.

Key Components of the Logic:

  • Multi-Symbol Tracking: You can define four specific instruments to monitor. If left blank, the script defaults to the current chart's symbol.
  • Visual Synchronization: The script calculates a moving average for each chosen instrument. It then scales these averages based on the highest and lowest price points found over a specific period (the "Control Bars").
  • Real-Time Dashboard: On the corner of your screen, the script generates a live text dashboard. This includes:
    • Individual Deviations: It calculates the difference between the primary symbol and each of the others.
    • Dynamic Color Coding: The dashboard updates colors instantly based on the direction of movement. For instance, if a symbol is performing "better" or higher than the primary symbol, it will display in one color (e.g., Green); if it is lower, it switches to another (e.g., Red).
    • Total Summation: The tool calculates a "Total" value, which represents the combined relative strength or weakness of all symbols compared to each other.

How it benefits the user:

Instead of manually checking four different tabs to see if your trades are moving in harmony or diverging, this script provides a consolidated "heat map" of sorts. By looking at the dashboard and the synchronized lines, a trader can quickly identify which currencies are leading the market, which are lagging, and whether the overall group of assets is moving in a positive or negative correlation.

Price Data Components
Series array that contains the highest prices of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
MultiInstrument4
//+------------------------------------------------------------------+
//|                                           MultiInstrument_YK.mq4 |
//|                               Copyright © 2010, Vladimir Hlystov |
//|                                         http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Vladimir Hlystov"
#property link      "http://cmillion.narod.ru"
//plots 4 symbols on the current chart
 
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Magenta
extern string symbol_1 = "";      //if "" ,use current
extern string symbol_2 = "EURUSD";//if "" ,use current
extern string symbol_3 = "EURCHF";//if "" ,use current
extern string symbol_4 = "EURGBP";//if "" ,use current
extern int ControlBars = 200;     //number of control bars
extern int N           = 1;       //averaging N candles
extern color PlusColor = indicator_color1;
extern color MinusColor= indicator_color2;
double Buffer_1[];
double Buffer_2[];
double Buffer_3[];
double Buffer_4[];
//+------------------------------------------------------------------+
int init()
  {
   ObjectCreate("symbol_1", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_1", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_1", OBJPROP_XDISTANCE, 10 ); 
   ObjectSet   ("symbol_1", OBJPROP_YDISTANCE, 15);
   ObjectCreate("symbol_2", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_2", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_2", OBJPROP_XDISTANCE, 10 ); 
   ObjectSet   ("symbol_2", OBJPROP_YDISTANCE, 25);
   ObjectCreate("symbol_3", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_3", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_3", OBJPROP_XDISTANCE, 10 ); 
   ObjectSet   ("symbol_3", OBJPROP_YDISTANCE, 35);
   ObjectCreate("symbol_4", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_4", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_4", OBJPROP_XDISTANCE, 10 ); 
   ObjectSet   ("symbol_4", OBJPROP_YDISTANCE, 45);
   ObjectCreate("symbol_5", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_5", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_5", OBJPROP_XDISTANCE, 10 ); 
   ObjectSet   ("symbol_5", OBJPROP_YDISTANCE, 55);
   ObjectCreate("symbol_6", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_6", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_6", OBJPROP_XDISTANCE, 10 ); 
   ObjectSet   ("symbol_6", OBJPROP_YDISTANCE, 65);
   ObjectCreate("symbol_7", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_7", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_7", OBJPROP_XDISTANCE, 10 ); 
   ObjectSet   ("symbol_7", OBJPROP_YDISTANCE, 80);
 
   if (symbol_1=="") symbol_1=Symbol();
   if (symbol_2=="") symbol_2=Symbol();
   if (symbol_3=="") symbol_3=Symbol();
   if (symbol_4=="") symbol_4=Symbol();
 
   ObjectCreate("symbol_1.", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_1.", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_1.", OBJPROP_XDISTANCE, 100 ); 
   ObjectSet   ("symbol_1.", OBJPROP_YDISTANCE, 15);
   ObjectSetText("symbol_1.",symbol_1+"-",8,"Arial",indicator_color1);
   ObjectCreate("symbol_2.", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_2.", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_2.", OBJPROP_XDISTANCE, 100 ); 
   ObjectSet   ("symbol_2.", OBJPROP_YDISTANCE, 25);
   ObjectSetText("symbol_2.",symbol_1+"-",8,"Arial",indicator_color1);
   ObjectCreate("symbol_3.", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_3.", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_3.", OBJPROP_XDISTANCE, 100 ); 
   ObjectSet   ("symbol_3.", OBJPROP_YDISTANCE, 35);
   ObjectSetText("symbol_3.",symbol_1+"-",8,"Arial",indicator_color1);
   ObjectCreate("symbol_4.", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_4.", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_4.", OBJPROP_XDISTANCE, 100 ); 
   ObjectSet   ("symbol_4.", OBJPROP_YDISTANCE, 45);
   ObjectSetText("symbol_4.",symbol_2+"-",8,"Arial",indicator_color2);
   ObjectCreate("symbol_5.", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_5.", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_5.", OBJPROP_XDISTANCE, 100 ); 
   ObjectSet   ("symbol_5.", OBJPROP_YDISTANCE, 55);
   ObjectSetText("symbol_5.",symbol_2+"-",8,"Arial",indicator_color2);
   ObjectCreate("symbol_6.", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_6.", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_6.", OBJPROP_XDISTANCE, 100 ); 
   ObjectSet   ("symbol_6.", OBJPROP_YDISTANCE, 65);
   ObjectSetText("symbol_6.",symbol_3+"-",8,"Arial",indicator_color3);
 
   ObjectCreate("symbol_1..", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_1..", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_1..", OBJPROP_XDISTANCE, 50 ); 
   ObjectSet   ("symbol_1..", OBJPROP_YDISTANCE, 15);
   ObjectSetText("symbol_1..","-"+symbol_2,8,"Arial",indicator_color2);
   ObjectCreate("symbol_2..", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_2..", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_2..", OBJPROP_XDISTANCE, 50 ); 
   ObjectSet   ("symbol_2..", OBJPROP_YDISTANCE, 25);
   ObjectSetText("symbol_2..","-"+symbol_3,8,"Arial",indicator_color3);
   ObjectCreate("symbol_3..", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_3..", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_3..", OBJPROP_XDISTANCE, 50 ); 
   ObjectSet   ("symbol_3..", OBJPROP_YDISTANCE, 35);
   ObjectSetText("symbol_3..","-"+symbol_4,8,"Arial",indicator_color4);
   ObjectCreate("symbol_4..", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_4..", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_4..", OBJPROP_XDISTANCE, 50 ); 
   ObjectSet   ("symbol_4..", OBJPROP_YDISTANCE, 45);
   ObjectSetText("symbol_4..","-"+symbol_3,8,"Arial",indicator_color3);
   ObjectCreate("symbol_5..", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_5..", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_5..", OBJPROP_XDISTANCE, 50 ); 
   ObjectSet   ("symbol_5..", OBJPROP_YDISTANCE, 55);
   ObjectSetText("symbol_5..","-"+symbol_4,8,"Arial",indicator_color4);
   ObjectCreate("symbol_6..", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("symbol_6..", OBJPROP_CORNER, 1);      
   ObjectSet   ("symbol_6..", OBJPROP_XDISTANCE, 50 ); 
   ObjectSet   ("symbol_6..", OBJPROP_YDISTANCE, 65);
   ObjectSetText("symbol_6..","-"+symbol_4,8,"Arial",indicator_color4);
 
   SetIndexBuffer(0,Buffer_1);
   SetIndexBuffer(1,Buffer_2);
   SetIndexBuffer(2,Buffer_3);
   SetIndexBuffer(3,Buffer_4);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexLabel(0,symbol_1);
   SetIndexLabel(1,symbol_2);
   SetIndexLabel(2,symbol_3);
   SetIndexLabel(3,symbol_4);
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("symbol_1");
   ObjectDelete("symbol_2");
   ObjectDelete("symbol_3");
   ObjectDelete("symbol_4");
   ObjectDelete("symbol_5");
   ObjectDelete("symbol_6");
   ObjectDelete("symbol_7");
   ObjectDelete("symbol_1.");
   ObjectDelete("symbol_2.");
   ObjectDelete("symbol_3.");
   ObjectDelete("symbol_4.");
   ObjectDelete("symbol_5.");
   ObjectDelete("symbol_6.");
   ObjectDelete("symbol_7.");
   ObjectDelete("symbol_1..");
   ObjectDelete("symbol_2..");
   ObjectDelete("symbol_3..");
   ObjectDelete("symbol_4..");
   ObjectDelete("symbol_5..");
   ObjectDelete("symbol_6..");
   ObjectDelete("symbol_7..");
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int BarsWind;
   if (ControlBars!=0) BarsWind=ControlBars; else BarsWind=WindowFirstVisibleBar();
   double High_Win = High[iHighest(NULL,0,MODE_HIGH,BarsWind,0)];
   double Low_Win  = Low [iLowest (NULL,0,MODE_LOW, BarsWind,0)];
   double H_2=iHigh(symbol_2,0,iHighest(symbol_2,0,MODE_HIGH,BarsWind,0));
   double L_2=iLow (symbol_2,0,iLowest (symbol_2,0,MODE_LOW, BarsWind,0));
   double H_3=iHigh(symbol_3,0,iHighest(symbol_3,0,MODE_HIGH,BarsWind,0));
   double L_3=iLow (symbol_3,0,iLowest (symbol_3,0,MODE_LOW, BarsWind,0));
   double H_4=iHigh(symbol_4,0,iHighest(symbol_4,0,MODE_HIGH,BarsWind,0));
   double L_4=iLow (symbol_4,0,iLowest (symbol_4,0,MODE_LOW, BarsWind,0));
   color WavesColor=White;
   for(int i=BarsWind; i>=0; i--)
   {
      Buffer_1[i]=  iMA(symbol_1,0,N,0,MODE_SMA,PRICE_WEIGHTED,i);
      Buffer_2[i]= (iMA(symbol_2,0,N,0,MODE_SMA,PRICE_WEIGHTED,i) - L_2)/(H_2 - L_2)*(High_Win-Low_Win)+Low_Win;
      Buffer_3[i]= (iMA(symbol_3,0,N,0,MODE_SMA,PRICE_WEIGHTED,i) - L_3)/(H_3 - L_3)*(High_Win-Low_Win)+Low_Win;
      Buffer_4[i]= (iMA(symbol_4,0,N,0,MODE_SMA,PRICE_WEIGHTED,i) - L_4)/(H_4 - L_4)*(High_Win-Low_Win)+Low_Win;
   }
   int delta_1 = (Buffer_1[0]-Buffer_2[0])/Point;
   int delta_2 = (Buffer_1[0]-Buffer_3[0])/Point;
   int delta_3 = (Buffer_1[0]-Buffer_4[0])/Point;
   int delta_4 = (Buffer_2[0]-Buffer_3[0])/Point;
   int delta_5 = (Buffer_2[0]-Buffer_4[0])/Point;
   int delta_6 = (Buffer_3[0]-Buffer_4[0])/Point;
   if (delta_1>0) WavesColor = PlusColor; else WavesColor = MinusColor;
   ObjectSetText("symbol_1",DoubleToStr(delta_1,0),8,"Arial",WavesColor);
   if (delta_2>0) WavesColor = PlusColor; else WavesColor = MinusColor;
   ObjectSetText("symbol_2",DoubleToStr(delta_2,0),8,"Arial",WavesColor);
   if (delta_3>0) WavesColor = PlusColor; else WavesColor = MinusColor;
   ObjectSetText("symbol_3",DoubleToStr(delta_3,0),8,"Arial",WavesColor);
   if (delta_4>0) WavesColor = PlusColor; else WavesColor = MinusColor;
   ObjectSetText("symbol_4",DoubleToStr(delta_4,0),8,"Arial",WavesColor);
   if (delta_5>0) WavesColor = PlusColor; else WavesColor = MinusColor;
   ObjectSetText("symbol_5",DoubleToStr(delta_5,0),8,"Arial",WavesColor);
   if (delta_6>0) WavesColor = PlusColor; else WavesColor = MinusColor;
   ObjectSetText("symbol_6",DoubleToStr(delta_6,0),8,"Arial",WavesColor);
   int sumdelta=delta_1+delta_2+delta_3+delta_4+delta_5+delta_6;
   if (sumdelta>0) WavesColor = PlusColor; else WavesColor = MinusColor;
   ObjectSetText("symbol_7","Total  = "+sumdelta,8,"Arial",WavesColor);
   return(0);
  }
//+------------------------------------------------------------------+

Comments