Get Current Window Handle

 

I know that the function "WindowHandle" exists. But what if I have multiple same Currency-Period charts? It will return one of these, but I would like to get the one were my EA is running from.

How could I achieve that?

 

Thanks! 

 

I would suggest your EA writes (Comment() or test-lable) the no. of its chart (not ChartID) on the screen and sets a global-variable with a informative name and sets the value to the no. of its chart

(Not tested!)

int findChart(){
   long myChart = ChartID(),
        nxChart = ChartFirst();
   if (nxChart == myChart) return(1);
   int ret = 2;
   while(nxChart!=-1) {//beyond last chart
      nxChart = ChartNext(nxChart);
      if (myChart == nxChart) return(ret);
      ret++;
   }
   return(-1); // not found
}


Don't set the value to the Chart-ID! Its a long value which will be converted to a double and if you re-convert it back to a long value again this value will differ from the original ChartID!!

 

This will not work 100%, but it gave me the idea: Use CHART_WINDOW_HANDLE combined with looping of the charts!

Thanks! 

 
svaningelgem:

I know that the function "WindowHandle" exists. But what if I have multiple same Currency-Period charts? It will return one of these, but I would like to get the one were my EA is running from.

How could I achieve that?

 

Thanks! 

ChartGetInteger(0,CHART_WINDOW_HANDLE);
 
Alain Verleyen:

Thank You. This code was very good to me.