Closing All Charts

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Closing All Charts
ÿþ//+------------------------------------------------------------------+

//|                                           Closing All Charts.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.00"

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

   long chart_id=ChartID();

//--- variables for chart ID

   long currChart,prevChart=ChartFirst();

   int i=0,limit=100;

   if(prevChart!=chart_id)

      ChartClose(prevChart);

   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)

         break;                        // Have reached the end of the chart list

      prevChart=currChart;             // let's save the current chart ID for the ChartNext()

      i++;                             // Do not forget to increase the counter

      if(currChart!=chart_id)

         ChartClose(currChart);

     }

   ChartClose(chart_id);

  }

//+------------------------------------------------------------------+

Comments