How does MT5 handle the Chart ID?

 

I searched everywhere in the documentation but didn't find a clear information about this:

How does Metatrader 5 exactly handle the Chart ID? Are they numbered from 0 to 999? and what happens with the ID of chart number 1 if I close the chart number 0? does the chart 1 turn in to 0?

And what is exactly the meaning of the explanation: 0 = current chart ID? is it the chart that is currently open by the user at the same moment the function is called? or is it the chart that the indicator is attached to?

The reason is very simple.. I have an indicator that calls repeatedly several functions that need the Chart ID. I used to simply use "0" which should refer to the "current chart" (where the indicator is attached to, as per my understanding). but when I switch to the tab of another chart and return back, I find that the indicator did change its appearance according to the other opened chart, which means that 0 is not always the "current" chart?

To be more precise, I think that at least one of following functions are affected in my code when I switch to another chart:

ChartGetInteger()

ObjectCreate()

ObjectGetInteger()

I know that I can use ChartID(), but calling it every time with every function call seems very heavy, and if I don't know how MT5 exactly handles the Chart IDs I even can not fix it with a variable, because I don't know if this ID changes somehow during different terminal operations, like closing a previous chart.

 
Anas Morad:

I searched everywhere in the documentation but didn't find a clear information about this:

How does Metatrader 5 exactly handle the Chart ID? Are they numbered from 0 to 999? and what happens with the ID of chart number 1 if I close the chart number 0? does the chart 1 turn in to 0?

And what is exactly the meaning of the explanation: 0 = current chart ID? is it the chart that is currently open by the user at the same moment the function is called? or is it the chart that the indicator is attached to?

The reason is very simple.. I have an indicator that calls repeatedly several functions that need the Chart ID. I used to simply use "0" which should refer to the "current chart" (where the indicator is attached to, as per my understanding). but when I switch to the tab of another chart and return back, I find that the indicator did change its appearance according to the other opened chart, which means that 0 is not always the "current" chart?

To be more precise, I think that at least one of following functions are affected in my code when I switch to another chart:

ChartGetInteger()

ObjectCreate()

ObjectGetInteger()

I know that I can use ChartID(), but calling it every time with every function call seems very heavy, and if I don't know how MT5 exactly handles the Chart IDs I even can not fix it with a variable, because I don't know if this ID changes somehow during different terminal operations, like closing a previous chart.

How chart ID are numbered doesn't matter. It's long integer value and you can easily check that yourself.

Using 0, just mean you don't have to specify the exact chart ID, but it will use the one where your code is running (as you correctly understood). 0 is ALWAYS the chart where the code is running.

 
Alain Verleyen #:

How chart ID are numbered doesn't matter. It's long integer value and you can easily check that yourself.

Using 0, just mean you don't have to specify the exact chart ID, but it will use the one where your code is running (as you correctly understood). 0 is ALWAYS the chart where the code is running.

I am using ChartGetInteger() to read the chart width in pixel. what's your explanation that when i switch to another chart and return back, the scale factor changes and the objects rescale? (i didn't change the windows size)

 
Anas Morad #:

I am using ChartGetInteger() to read the chart width in pixel. what's your explanation that when i switch to another chart and return back, the scale factor changes and the objects rescale? (i didn't change the windows size)

MT5 is using Windows API and it's MDI Window GUI. This behaviour you described comes from there, when you switch to an other child window to current window is resized.

I don't know what "scale factor" you are referring to.

Reason: