MultySymbolsChart_v2_2
Download scriptThis script is designed for traders who want to visualize the price movement of multiple currency pairs (such as AUDUSD, EURUSD, etc.) simultaneously within a single chart window. Instead of looking at several different charts at once, it consolidates this information into a unified visual display.
Here is a breakdown of the logic in non-technical terms:
Multi-Symbol Synchronization
The script takes a list of different financial instruments and "collects" their price data. It ensures that all these symbols are updated correctly before displaying anything on your screen. If one of the symbols fails to load or has no data, the script provides a status notification to let you know which one is missing.
Dynamic Scaling & Normalization
Because different currency pairs have vastly different price values (for example, one might trade at 1.10 while another trades at 150.00), the script performs a "normalization" process. It identifies the highest and lowest price points across all selected symbols over a specific number of bars. It then calculates a shared median range. This allows the script to shrink or stretch all the different currencies so they can fit into the same visual space comfortably without overlapping or disappearing off-screen.
Visual Representation
Once the data is normalized, the script draws a series of histograms (bar-like shapes) for each currency:
- Relative Positioning: Each currency is assigned its own "lane" or section on the chart.
- Movement Tracking: The colors and heights of these bars represent the price action (Open, High, Low, Close) of each individual pair relative to the shared median.
- Visual Separation: It uses vertical lines and specific spacing to ensure that the data for one currency doesn't blend into the next, making it easy to distinguish between them at a glance.
Automated Labeling
To keep the chart organized, the script automatically places text labels above each set of data. These labels identify exactly which currency pair you are looking at, ensuring that even though everything is consolidated into one window, the information remains clear and easy to read.
Summary of Behavior
Essentially, this tool acts like a "compact dashboard." It takes a complex list of market movements, standardizes their sizes so they can be compared side-by-side, and paints them into a single organized view, allowing for a quick overview of how various global currencies are moving in relation to one another.
//+------------------------------------------------------------------+
//| MultySymbolsChart_v2.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;
extern double Header=0.15;
//---- 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(){
if(!fCheckDataUpdateFromList(sa,TimeFrame))return(0);
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.0+Header),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);i++){
ExtMapBuffer7[i]=MaxRange*(1.0+Header);
}
SetLevelValue(0,0);
SetLevelValue(1,MaxRange);
return(0);
}
//+------------------------------------------------------------------+
bool fCheckDataUpdateFromList(string aSymbolList[],int aTimeFrame){
static bool sErr=false;
for(int ti=0;ti<ArraySize(aSymbolList);ti++){
if(!fCheckDataUpdate(aSymbolList[ti],aTimeFrame)){
sErr=true;
IndicatorShortName("...æäó îáíîâëåíèÿ äàííûõ "+aSymbolList[ti]+" "+fTimeFrameName(aTimeFrame));
return(false);
}
}
if(sErr){
IndicatorShortName(sn);
ArrayInitialize(ExtMapBuffer1,0);
ArrayInitialize(ExtMapBuffer2,0);
ArrayInitialize(ExtMapBuffer3,0);
ArrayInitialize(ExtMapBuffer4,0);
ArrayInitialize(ExtMapBuffer5,0);
ArrayInitialize(ExtMapBuffer6,0);
}
return(true);
}
bool fCheckDataUpdate(string aSymbol,int aTimeFrame){
datetime daytimes[];
if(iClose(aSymbol,aTimeFrame,0)==0){
Print("Íåò äàííûõ "+aSymbol+" "+fTimeFrameName(aTimeFrame));
return(false);
}
ArrayCopySeries(daytimes,MODE_TIME,aSymbol,aTimeFrame);
if(GetLastError()==4066){
Print("Äàííûõ "+aSymbol+" "+fTimeFrameName(aTimeFrame)+" â ïðîöåññå îáíîâëåíèÿ");
return(false);
}
return(true);
}
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]));
}
}
Comments