[HELP] 2 charts always same symbol MT5

 

Hi,


I searched google for a while, but i couldnt find the solution.

I have 2 charts 15m and 1H. If i change the symbol of the 15M chart, i want the 1H chart to automatically change to that symbol as well. for MT5


Does anybody know how to make this work. Script?

 
bump
 
ZenLiu:
bump
Please don't do that again. Wait for an answer...if you get one.
 
ZenLiu:

Hi,


I searched google for a while, but i couldnt find the solution.

I have 2 charts 15m and 1H. If i change the symbol of the 15M chart, i want the 1H chart to automatically change to that symbol as well. for MT5


Does anybody know how to make this work. Script?

you can use the following function to change the symbol of the current chart to the one you want to change to..

ChartSetSymbolPeriod( 0,symbolName,0); //Replace symbolName with your desired symbol
 
Lakshan Perera:

you can use the following function to change the symbol of the current chart to the one you want to change to..

Hi thank you for your help. Thing is: I want this to be automated. When 15m chart changes symbol -> 1H chart follows to same symbol. Any ideas?
 
ZenLiu:
Hi thank you for your help. Thing is: I want this to be automated. When 15m chart changes symbol -> 1H chart follows to same symbol. Any ideas?

Yes you can code that, I just gave the function to change the symbol..
A side note, that might be useful when coding is you can use the "reason" code of the OnDeinit() of the Master chart to know whether the symbol was changed or not,
if reason == REASON_CHARTCHANGE
it means the symbol or time frame was changed, then you can go from there..

 
Lakshan Perera:

Yes you can code that, I just gave the function to change the symbol..
A side note, that might be useful when coding is you can use the "reason" code of the OnDeinit() of the Master chart to know whether the symbol was changed or not,
if reason == REASON_CHARTCHANGE
it means the symbol or time frame was changed, then you can go from there..

I cant code =')
 

Save this in your indicators folder and run all charts you want to sync. 


with love, 


nicholi shen


//+------------------------------------------------------------------+
//|                                             ChartSymbolsSync.mq5 |
//|                                       Copyright 2018,nicholishen |
//|                                           https://www.google.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018,nicholishen"
#property link      "https://www.google.com"
#property version   "1.00"
#property indicator_chart_window
#define SCHANGE 103
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
   return(rates_total);
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if(id == CHARTEVENT_CUSTOM + SCHANGE)
      if(_Symbol != sparam)
         ChartSetSymbolPeriod(0, sparam, _Period);
   
   if(id == CHARTEVENT_CHART_CHANGE)
      for(long ch = ChartFirst(); ch >= 0; ch = ChartNext(ch))
         if(ch != ChartID())
            EventChartCustom(ch, SCHANGE, 0, 0.0, _Symbol);
}
//+------------------------------------------------------------------+
 
nicholi shen:

Save this in your indicators folder and run all charts you want to sync. 


with love, 


nicholi shen


it works. Thanks alot<3
 
nicholi shen:

Save this in your indicators folder and run all charts you want to sync. 


with love, 


nicholi shen


Nice!! this is a better and neat approach than mine, thanks nicholi shen

Reason: