Download MetaTrader 5

...problem with closing of opened chart windows

To add comments, please log in or register
MQL5.community allows users to store their source codes in MQL5 Storage. Try it!
andrew_256
11
andrew_256 2011.07.29 17:36 
Hello everybody,

I would like to ask if somebody could help me with next problem. Firstly, I attach my short completed script:


#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
     int number_of_opened_windows(){
               long currChart=ChartFirst();
               long prevChart=ChartFirst();
               int i=1;
               int limit=100;

     while(i<limit)// We have certainly not more than 100 open charts
           {
            currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID
            if(currChart<0) {return(i);}          // Have reached the end of the chart list
            else {
            prevChart=currChart;// let's save the current chart ID for the ChartNext()
            i++;}// Do not forget to increase the counter
           }
  return(i);
  }
  void remove_the_second_opened_window(){

              long index_the_first_window=ChartFirst();
              long currChart=ChartNext(index_the_first_window);
              bool window_is_closed=ChartClose(currChart);
              if(!window_is_closed) {Alert("Error.");}
              else {Alert("OK, window was closed.");}
  }
 
void OnStart()
  {
//---
     Alert("Number of closed windows is "+number_of_opened_windows());
     remove_the_second_opened_window();
     Alert("Number of closed windows is "+number_of_opened_windows());

  }
//+------------------------------------------------------------------+


//Script is written for deleting of the second opened chart window in Metatrader 5.


//I have opened e.g. 6 chart windows in Metatrader 5. Why get I next output?
// Number of closed windows is 6.
//OK, windows was closed.
//Number of closed windows is 6.

//for 6 opened chart windows I should get next messages:

// Number of closed windows is 6.
//OK, windows was closed.

//Number of closed windows is 5.

I think problem can be in no updating of opened windows. Does somebody know how it can be solved? Thank you. Andrew

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Language Basics / Preprocessor / Program Properties (#property) - Documentation on MQL5
Karlis Balcers
6663
Karlis Balcers 2011.07.29 19:51  

I guess, it's not refreshed. Maybe it collects the count of charts at startup and then it does not update the list of charts till next call of OnStart(). Maybe it would work better on OnTick (with ExpertAdvisor). It's just my guess.

Try to delete all and see if number of total charts does not change. If so, try to close windows that are already closed and see how it likes it.

/tsaktuo 

goryl
3
goryl 2012.08.02 19:04  

Tsaktuo,

 Where can i find the file for your TickSpeed v1.0 indicator?  I looked at https://www.mql5.com/en/market/product/48  but there's not link to it.  Thanks 

Technical Indicator TickSpeed
  • 10.00 USD
  • Karlis Balcers
  • www.mql5.com
Indicator to measure market activity and to show speed of price in pips/sec. Have you been wondering, what is current speed of the market?   I see the ticks jumping up and down, can I measure their speed? All these...
To add comments, please log in or register