[MQL5] Open several charts

 

Hello,

I would like to know how to open several charts in mql5 ?
I tried to do this but there is only one graph that opens

(I run the code I execute the program by doing ctrl + f5)


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ChartOpen("EURUSD", PERIOD_H1);
   ChartOpen("EURCHF", PERIOD_H1);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
 
ket314MQL4 :

Hello,

I would like to know how to open several charts in mql5 ?
I tried to do this but there is only one graph that opens

(I run the code I execute the program by doing ctrl + f5)


If there is no symbol in the "Market Watch" window, OpenChart will not work. To protect yourself, use SymbolSelect

//+------------------------------------------------------------------+
//|                                                            1.mq5 |
//|                              Copyright © 2020, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020, Vladimir Karputov"
#property version   "1.00"
//--- input parameters
input string   InpSymbol_0 = "EURUSD"; // Symbol 0
input string   InpSymbol_1 = "EURJPY"; // Symbol 1
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   SymbolSelect(InpSymbol_0,true);
   SymbolSelect(InpSymbol_1,true);
   Print(InpSymbol_0,",H1 chart ",ChartOpen("EURUSD", PERIOD_H1));
   Print(InpSymbol_0,",H1 chart ",ChartOpen("EURJPY", PERIOD_H1));
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
Documentation on MQL5: Market Info / SymbolSelect
Documentation on MQL5: Market Info / SymbolSelect
  • www.mql5.com
[in] Switch. If the value is false, a symbol should be removed from MarketWatch, otherwise a symbol should be selected in this window. A symbol can't be removed if the symbol chart is open, or there are open positions for this symbol.
Files:
1.mq5  4 kb
 

Hello,


thank for your help.