MetaQuotes: ChartClose(chart_ID) is broken

 

First, here's the source code:

void OnStart()
  {
   int i=1;
   long chartID=ChartFirst();
   Print("First chart is:",ChartSymbol(chartID),". TF:",ChartPeriod(chartID));
   while (chartID!=-1)
   {
      if(chartID!=ChartFirst())
        {
         Print("Next chart is:",ChartSymbol(chartID),". TF:",ChartPeriod(chartID));
         //ChartClose(chartID);
        }
      chartID=ChartNext(chartID);
   }
  }

Open up a slew or charts.  Drop this script on the first chart you open up (If you're not sure, drop it on any chart w/ the code the way it is now.  It'll print out which chart is first).

Now, comment out the Print lines.  Un Comment the ChartClose(chartID) line.

Drop it on the first chart.

I usually get no charts getting close to 2 charts, random in the order, getting closed.

If it's a problem in code, let me know.  Otherwise, it's a Metatrader problem.

FYI.  What I'm trying to accomplish is simple.  Close all charts but the first one.

MT4 Build 765

 
   ChartClose(chartID);
}
chartID=ChartNext(chartID);
How do you expect to get the next chart AFTER you close chartID?
 
WHRoeder:
How do you expect to get the next chart AFTER you close chartID?

Time to find the brick wall I use to bang my head against.  This is the working code:

void OnStart()
  {
   int i=1;
   long homechartID=ChartID();
   long chartID=ChartFirst();
   long toclosechartid;
   //Print("First chart is:",ChartSymbol(chartID),". TF:",ChartPeriod(chartID));
   while (chartID!=-1)
   {
      if(chartID!=homechartID)
        {
         //Print("Next chart is:",ChartSymbol(chartID),". TF:",ChartPeriod(chartID));
         toclosechartid=chartID;
         chartID=ChartNext(chartID);
         ChartClose(toclosechartid);
        }
      else {chartID=ChartNext(chartID);}
   }
  }
Reason: