Download MetaTrader 5

Program will not close charts

To add comments, please log in or register
GrumpyDuckMan
338
GrumpyDuckMan  

Hello everyone,

I must be missing some steps in trying shutdown some charts currently opened. The code below works with MQL4.

How do I close charts by name or chart ID?

#property copyright " "
#property link      " "
#property version   "1.00"
#property strict

input int TIMEFRAME; 
string charts;       
long chartid;        
long Chart_ID;       
//+------------------------------------------------------------------+
int OnInit()
  {

   bool TimeFunction=ChartSetSymbolPeriod(chartid,charts,TIMEFRAME);

   Chart_ID=ChartOpen("EURUSD",TIMEFRAME);
   ChartDesign();                             //

   Chart_ID=ChartOpen("USDMXN",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("GBPUSD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("GBPUSD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("AUDUSD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("GOLD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("USDCHF",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("USDJPY",TIMEFRAME);
  // ChartDesign();
   CloseCharts();

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+
void ChartDesign()
  {
   ChartSetInteger(Chart_ID,CHART_MODE,CHART_CANDLES);
   ChartSetInteger(Chart_ID,CHART_SHOW_GRID,false);
   ChartSetInteger(Chart_ID,CHART_AUTOSCROLL,true);
   ChartSetInteger(Chart_ID,CHART_SCALE,4);
  }
//+------------------------------------------------------------------+ 
void CloseCharts()
  {
   bool CloseAllCharts=ChartClose(chartid=0);

  }
//+------------------------------------------------------------------+
GrumpyDuckMan
338
GrumpyDuckMan  
I have created a solution.
#property copyright " "
#property link      " "
#property version   "1.00"
#property strict

input int TIMEFRAME; 
string charts;       
long chartid;        
long Chart_ID;  
long RemoveChart;     
//+------------------------------------------------------------------+
int OnInit()
  {

   bool TimeFunction=ChartSetSymbolPeriod(chartid,charts,TIMEFRAME);

   Chart_ID=ChartOpen("EURUSD",TIMEFRAME);
   RemoveChart=Chart_ID;
   ChartDesign();                             //

   Chart_ID=ChartOpen("USDMXN",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("GBPUSD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("GBPUSD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("AUDUSD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("GOLD",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("USDCHF",TIMEFRAME);
   ChartDesign();

   Chart_ID=ChartOpen("USDJPY",TIMEFRAME);
 
   CloseChart();
  ChartDesign();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+
void ChartDesign()
  {
   ChartSetInteger(Chart_ID,CHART_MODE,CHART_CANDLES);
   ChartSetInteger(Chart_ID,CHART_SHOW_GRID,false);
   ChartSetInteger(Chart_ID,CHART_AUTOSCROLL,true);
   ChartSetInteger(Chart_ID,CHART_SCALE,4);
  }
//+------------------------------------------------------------------+ 
void CloseChart()
  {
   bool CloseAllCharts=ChartClose(RemoveChart);

  }
//+------------------------------------------------------------------+
To add comments, please log in or register