MultySymbolsChart
Download scriptMulti-Symbol Chart Overview
This script is designed for MetaTrader 4 to provide a centralized visual summary of multiple different financial assets (such as AUDUSD, EURUSD, etc.) on a single indicator window. Instead of forcing a trader to switch between several different charts to monitor market movements, this tool aggregates the price action of your selected symbols into one cohesive display.
How the Logic Works
1. Symbol Management and Setup The script begins by taking a list of currency pairs or assets provided by the user. It identifies each symbol individually and prepares the platform to track their specific data. When you load the script, it automatically organizes these symbols so that their price movements can be plotted side-by-side in a sequence.
2. Data Normalization (The "Median" Logic) Because different assets have vastly different prices (for example, one might trade at 1.10 and another at 150.00), the script performs a calculation to make them comparable on the same screen. It identifies the highest and lowest price points for each symbol over a specific period and calculates a "Median" value. This allows every asset—regardless of its actual price—to be scaled proportionally so that their relative movements are visible at the same time.
3. Visual Representation The script converts standard price bars into a custom histogram-style visual. For each symbol, it calculates:
- The relative High, Low, Open, and Close prices.
- The direction of the move (identifying if a candle closed higher or lower than its opening).
- A normalized position based on the "Max Range" found across all selected symbols to ensure nothing is cut off from the view.
4. Dynamic Display Features To make the chart easy to read, the script incorporates several automated visual aids:
- Labels: It places text labels on the chart to identify which section of the display belongs to which currency pair.
- Vertical Dividers: It draws gray vertical lines between different symbols to create clear "lanes," preventing the data from overlapping and becoming confusing.
- Automatic Updates: The script constantly checks if the data for each symbol is active and updated; if a symbol's data is unavailable, it adjusts the display accordingly to ensure the chart remains accurate.
Summary of User Experience
Rather than looking at six separate windows, the user sees one organized "dashboard." Each currency pair is represented as a distinct block of movement. By scaling all assets to a common range, the trader can quickly compare the volatility and trends of multiple markets simultaneously, seeing which are moving in sync and which are diverging.
//+------------------------------------------------------------------+
//| MultySymbolsChart.mq4 |
//| * |
//| * |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link "for-good-letters@yandex.ru"
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Black
#property indicator_color2 Pink
#property indicator_color3 DodgerBlue
#property indicator_color4 Black
#property indicator_color5 Pink
#property indicator_color6 DodgerBlue
#property indicator_color7 Black
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
//---- input parameters
extern string Symbols="AUDUSD,EURUSD,GBPUSD,USDCAD,USDCHF,USDJPY";
extern int TimeFrame=0;
extern int BarsOfSymbol=21;
extern int SpaceBars=5;
extern color LblColor=Yellow;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
string sa[];
bool du[];
int Size;
string sn="MSC";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void fArrayInvert_string(string & aArray[]){
int tSize=ArraySize(aArray)-1;
for(int ti=0;ti<ArraySize(aArray)/2;ti++){
string tTmp=aArray[ti];
aArray[ti]=aArray[tSize-ti];
aArray[tSize-ti]=tTmp;
}
}
int init(){
fStrSplit(Symbols,sa,",");
fArrStrTrimLR(sa);
Size=ArraySize(sa);
ArrayResize(du,Size);
fArrayInvert_string(sa);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer7);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,ExtMapBuffer1);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,ExtMapBuffer2);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3,ExtMapBuffer3);
SetIndexStyle(4,DRAW_HISTOGRAM);
SetIndexBuffer(4,ExtMapBuffer4);
SetIndexStyle(5,DRAW_HISTOGRAM);
SetIndexBuffer(5,ExtMapBuffer5);
SetIndexStyle(6,DRAW_HISTOGRAM);
SetIndexBuffer(6,ExtMapBuffer6);
SetIndexLabel(0,"");
SetIndexLabel(1,"");
SetIndexLabel(2,"");
SetIndexLabel(3,"");
SetIndexLabel(4,"");
SetIndexLabel(5,"");
SetIndexLabel(6,"");
sn=sn+" "+fTimeFrameName(TimeFrame);
IndicatorShortName(sn);
IndicatorDigits(0);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
if(UninitializeReason()!=REASON_CHARTCHANGE){
fObjDeleteByPrefix("MSC_"+TimeFrame);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start(){
for(int i=0;i<Size*(BarsOfSymbol+SpaceBars)+10;i++){
ExtMapBuffer1[i]=0;
ExtMapBuffer2[i]=0;
ExtMapBuffer3[i]=0;
ExtMapBuffer4[i]=0;
ExtMapBuffer5[i]=0;
ExtMapBuffer6[i]=0;
ExtMapBuffer7[i]=0;
}
double MaxRange=0;
for(i=0;i<Size;i++){
du[i]=fCheckDataUpdate(sa[i],TimeFrame);
if(du[i]){
int hb=iHighest(sa[i],TimeFrame,MODE_HIGH,BarsOfSymbol,0);
int lb=iLowest(sa[i],TimeFrame,MODE_LOW,BarsOfSymbol,0);
double Max=iHigh(sa[i],TimeFrame,hb);
double Min=iLow(sa[i],TimeFrame,lb);
double Range=MathRound((Max-Min)/MarketInfo(sa[i],MODE_POINT));
MaxRange=MathMax(MaxRange,Range);
}
}
double DrawMedian=MathCeil(MaxRange/2);
for(i=0;i<Size;i++){
if(du[i]){
hb=iHighest(sa[i],TimeFrame,MODE_HIGH,BarsOfSymbol,0);
lb=iLowest(sa[i],TimeFrame,MODE_LOW,BarsOfSymbol,0);
Max=iHigh(sa[i],TimeFrame,hb);
Min=iLow(sa[i],TimeFrame,lb);
double Mediana=NormalizeDouble((Max+Min)/2,MarketInfo(sa[i],MODE_DIGITS));
for(int j=0;j<BarsOfSymbol;j++){
double o=DrawMedian+(iOpen(sa[i],TimeFrame,j)-Mediana)/MarketInfo(sa[i],MODE_POINT);
double h=DrawMedian+(iHigh(sa[i],TimeFrame,j)-Mediana)/MarketInfo(sa[i],MODE_POINT);
double l=DrawMedian+(iLow(sa[i],TimeFrame,j)-Mediana)/MarketInfo(sa[i],MODE_POINT);
double c=DrawMedian+(iClose(sa[i],TimeFrame,j)-Mediana)/MarketInfo(sa[i],MODE_POINT);
if(c==o){
for(int k=j+1;k<iBars(sa[i],TimeFrame);k++){
double o2=DrawMedian+(iOpen(sa[i],TimeFrame,k)-Mediana)/MarketInfo(sa[i],MODE_POINT);
double h2=DrawMedian+(iHigh(sa[i],TimeFrame,k)-Mediana)/MarketInfo(sa[i],MODE_POINT);
double l2=DrawMedian+(iLow(sa[i],TimeFrame,k)-Mediana)/MarketInfo(sa[i],MODE_POINT);
double c2=DrawMedian+(iClose(sa[i],TimeFrame,k)-Mediana)/MarketInfo(sa[i],MODE_POINT);
if(c2>o2){
c=o+0.333;
h=MathMax(h,c);
break;
}
if(c2<o2){
c=o-0.333;
l=MathMin(l,c);
break;
}
}
}
if(c>o){
ExtMapBuffer2[j+i*(BarsOfSymbol+SpaceBars)]=c;
ExtMapBuffer3[j+i*(BarsOfSymbol+SpaceBars)]=o;
ExtMapBuffer5[j+i*(BarsOfSymbol+SpaceBars)]=h;
ExtMapBuffer6[j+i*(BarsOfSymbol+SpaceBars)]=l;
}
if(c<o){
ExtMapBuffer1[j+i*(BarsOfSymbol+SpaceBars)]=o;
ExtMapBuffer3[j+i*(BarsOfSymbol+SpaceBars)]=c;
ExtMapBuffer4[j+i*(BarsOfSymbol+SpaceBars)]=h;
ExtMapBuffer6[j+i*(BarsOfSymbol+SpaceBars)]=l;
}
}
fObjText("MSC_"+TimeFrame+"_"+sa[i],Time[i*(BarsOfSymbol+SpaceBars)+BarsOfSymbol/2],MaxRange*1.2,sa[i],LblColor,6,WindowFind(sn),"Arial",false);
}
else{
ObjectDelete("MSC_"+TimeFrame+"_"+sa[i]);
}
fObjVLine("MSC_"+TimeFrame+"_h_"+sa[i],Time[(i+1)*(BarsOfSymbol+SpaceBars)-SpaceBars/2-1],Gray,1,WindowFind(sn),0,false);
}
for(i=0;i<Size*(BarsOfSymbol+SpaceBars)+10;i++){
ExtMapBuffer7[i]=MaxRange*1.2;
}
SetLevelValue(0,0);
SetLevelValue(1,MaxRange);
return(0);
}
//+------------------------------------------------------------------+
void fObjDeleteByPrefix(string aPrefix){
for(int i=ObjectsTotal()-1;i>=0;i--){
if(StringFind(ObjectName(i),aPrefix,0)==0){
ObjectDelete(ObjectName(i));
}
}
}
void fObjVLine(
string aObjectName, // 1 èìÿ
datetime aTime_1, // 2 âðåìÿ
color aColor=Red, // 3 öâåò
int aWidth=1, // 4 òîëùèíà
int aWindowNumber=0, // 5 îêíî
int aStyle=0, // 6 0-STYLE_SOLID, 1-STYLE_DASH, 2-STYLE_DOT, 3-STYLE_DASHDOT, 4-STYLE_DASHDOTDOT
bool aBack=false // 7 ôîí
){
if(ObjectFind(aObjectName)!=aWindowNumber){
ObjectCreate(aObjectName,OBJ_VLINE,aWindowNumber,aTime_1,0);
}
ObjectSet(aObjectName,OBJPROP_TIME1,aTime_1);
ObjectSet(aObjectName,OBJPROP_COLOR,aColor);
ObjectSet(aObjectName,OBJPROP_WIDTH,aWidth);
ObjectSet(aObjectName,OBJPROP_BACK,aBack);
ObjectSet(aObjectName,OBJPROP_STYLE,aStyle);
}
string fTimeFrameName(int arg){
// fTimeFrameName();
int v;
if(arg==0){
v=Period();
}
else{
v=arg;
}
switch(v){
case 0:
return("0");
case 1:
return("M1");
case 5:
return("M5");
case 15:
return("M15");
case 30:
return("M30");
case 60:
return("H1");
case 240:
return("H4");
case 1440:
return("D1");
case 10080:
return("W1");
case 43200:
return("MN1");
default:
return("M"+arg);
}
}
void fObjText(
string aObjectName, // 1 èìÿ
datetime aTime_1, // 2 âðåìÿ
double aPrice_1, // 3 öåíà
string aText, // 4 òåêñò
color aColor=Red, // 5 öâåò
int aFontSize=8, // 6 ðàçìåð øðèôòà
int aWindowNumber=0, // 7 îêíî
string aFont="Arial", // 8 øðèôò
bool aBack=false // 9 ôîí
){
// fText("",Time[1],Close[1],"",Red,8);
// fText("",Time[1],Close[1],"",Red,8,0,"Arial",false);
if(ObjectFind(aObjectName)!=aWindowNumber){
ObjectCreate(aObjectName,OBJ_TEXT,aWindowNumber,aTime_1,aPrice_1);
}
ObjectSet(aObjectName,OBJPROP_TIME1,aTime_1);
ObjectSet(aObjectName,OBJPROP_PRICE1,aPrice_1);
ObjectSetText(aObjectName,aText,aFontSize,aFont,aColor);
ObjectSet(aObjectName,OBJPROP_BACK,aBack);
}
void fStrSplit(string aString,string & aArray[],string aDelimiter){
int tCounter=0;
int tDelimiterLength=StringLen(aDelimiter);
ArrayResize(aArray,tCounter);
int tPos1=0;
int tPos2=StringFind(aString,aDelimiter,0);
while(tPos2!=-1){
if(tPos2>tPos1){
tCounter++;
ArrayResize(aArray,tCounter);
aArray[tCounter-1]=StringSubstr(aString,tPos1,tPos2-tPos1);
}
tPos1=tPos2+tDelimiterLength;
tPos2=StringFind(aString,aDelimiter,tPos1);
}
tPos2=StringLen(aString);
if(tPos2>tPos1){
tCounter++;
ArrayResize(aArray,tCounter);
aArray[tCounter-1]=StringSubstr(aString,tPos1,tPos2-tPos1);
}
}
void fArrStrTrimLR(string & aArray[]){
for(int ti=0;ti<ArraySize(aArray);ti++){
aArray[ti]=StringTrimLeft(StringTrimRight(aArray[ti]));
}
}
bool fCheckDataUpdate(string aSymbol,int aTimeFrame){
datetime daytimes[];
if(iClose(aSymbol,aTimeFrame,0)==0){
return(false);
}
ArrayCopySeries(daytimes,MODE_TIME,aSymbol,aTimeFrame);
if(GetLastError()==4066){
return(false);
}
return(true);
}
Comments