My temporary walkaround: 1) define variable for detecting switching of charts (true - switched, false - not switched), 2) detect switching and force to the initial coordinates, 3) upon manual change of the position of widget do nothing
private boolean mainChartChanged = false; // should be global
if(mainChartChanged && context.getLastActiveChart().getInstrument() == instrument){
// Put into OnTick method, make context and instrument fixed, otherwise won't work
// Force to the initial coordinates
widget.setPosX(0); // First to zero, otherwise won't work
widget.setPosX(Float.valueOf(settings[6])); // Then to the initial coordinates
mainChartChanged = false;
}
if(context.getLastActiveChart().getInstrument() != instrument){mainChartChanged = true;}
else{
if(widget.getPosX() != Float.valueOf(settings[6]) && context.getLastActiveChart().getInstrument() == instrument){
// Do nothing as the position is changed manually by user on the active chart
settings[6] = String.valueOf(widget.getPosX());
settings[7] = String.valueOf(widget.getPosY());
}
}
Still, you can't tell if the active window is a chart or a window for editing strategies. If it's the latter, the method getLastActiveChart still returns our active chart, whereas it's not active now. Otherwise if don't use anything but charts works pretty fine.