How to use ChartFirst(), ChartID(), ChartNext( ChartID() ) ???

 

Hi I just started in debug mode in a script just this:

long    Ch01 = ChartFirst(),
        ChMe = ChartID();
long    ChNx = ChartNext(ChMe);

and get:

Ch01:130395223288765087 long
ChMe:130370193351027474 long
ChNx:-1 long

I expect s.th. like 0, 3, -1 it is the last Chart?? What is meant with ID of ChartFirst() by this huge numbers much bigger than CHARTS_MAX = 100?

Can I (my EA) find out on which chart it is running with the idea that the first chart should have either 0 or 1 and the next chart just 1 more.

Gooly

PS: I I run this script

void OnStart()  {
long    Ch01 = ChartFirst(),
        ChMe = ChartID();
long    ChNx = ChartNext(ChMe);
Print("First: ",Ch01,"  Me: ",ChMe,"  Next: ",ChNx);
}

directly on the first chart with no other chart I get ( ChNx != -1 ??)

2014.03.19 16:41:45.632 test EURUSD,H4: First: 130395223288765087  Me: 130395223288765087  Next: 130395688617648862
 
gooly:

What is meant with ID of ChartFirst() by this huge numbers much bigger than CHARTS_MAX = 100?

Ask MQ

ChartFirst returns the ChartID from the first chart

so in order to use it right:

long    Ch01 = ChartFirst(), /* the ChartID() from the first chart */
        Current = ChartID(); //the ChartID() from the Current Chart
long    ChNx = ChartNext(Ch01); //the ChartID() from the Second Chart
 
Carl Schreiber:

Hi I just started in debug mode in a script just this:

and get:

I expect s.th. like 0, 3, -1 it is the last Chart?? What is meant with ID of ChartFirst() by this huge numbers much bigger than CHARTS_MAX = 100?

Can I (my EA) find out on which chart it is running with the idea that the first chart should have either 0 or 1 and the next chart just 1 more.

Gooly

PS: I I run this script

directly on the first chart with no other chart I get ( ChNx != -1 ??)

long   chartID=ChartFirst();

 for(int i=0; i<128; i++)   // I didn't test 128 charts, but read that MT4 allows 128 opened charts
  {
    chartID=ChartNext(chartID);

  // do what you need for opened charts

 }
In other words:
The ChartID() seems to be some large number,
The ChartID()'s aren't in any specific order (we can change the order of tabs manually),
The code is not counting the charts,
The code is only returning the ChartID() for every opened chart.
 
 

ChartNext() etc returns each chartid in your collection of charts.

You need to figure out how to use the chartids to meet the needs of your EA.

The EA's chart will just be ChartID() and this code creates an array of charts on your screen.

void chartsupdate(){
 long charts[],thisid=0;
 int ct=0;

  do{
  thisid=ChartNext(thisid);
   if(thisid==-1)break;  //reached the end of chart collection
 //if(thisid==ChartID())continue; // exclude the host chart
  
  ArrayResize(charts,ct+1);
  charts[ct]=thisid;
  ct++;

 }
 while(ct<100);

string txt="";
for(int i=0;i<ArraySize(charts);i++){
 txt=StringConcatenate(txt,charts[i]," sym ",ChartSymbol(charts[i]),"\n");
 }
 
 Comment (txt);
/* returns (2 charts on my terminal)
133608982605570143 sym NZDCHF.r
133610036888496035 sym ETHEREUM
*/
}