One can use the window handle of a chart to uniquely identify said chart throughout a program session.
However, MT4 throws a couple of gotchas. Maybe fixed in current versions, maybe not:
Inserted Code
int persistent_value=14; int chart_handle=WindowHandle(); if (chart_handle>0 && !IsStopped()) GlobalVariableSet(chart_handle,persistent_value);
However, MT4 throws a couple of gotchas. Maybe fixed in current versions, maybe not:
- Check for 0.
MT4 has not always got round to assigning the window handle to the chart when Init() is run so you have to check the handle and defer your assignment until later if it is 0. - Check IsStopped().
Calling WindowHandle() when an indicator/EA is being stopped by MT4 may cause MT4 to crash.