How to keep information in my indicator when I switch symbols

 

Hi everyone!

I'm coding an indicator and I'm encountering a problem. My idea is to have this indicator attached to a chart in a separate monitor just to use it to manage the open trades in each forex pair but I'm having trouble when I switch symbols. I know that the function ChartSetSymbolPeriod call the OnDeInit function in the current chart and call the function OnInit in the next chart (when I switch symbols).

//+------------------------------------------------------------------+
//| Event handler                                                    |
//+------------------------------------------------------------------+
void CPanelDialog::OnClickButton1(void)
{
//   m_edit1.Text("AUDCAD");
   m_button1.ColorBackground(clrGray);
   ChartSetSymbolPeriod(0, "AUDCAD", 0);
}

I'd like to keep some information such as what symbol is selected by using a background property of the button (panel.PNG attached as an example).

I already found in this forum some people with almost the same problem and someone recommended to save the information to a file, so in the function OnInit I will check if the file exists, if yes, I'll read the parameters saved there to load my indicator and in the OnDeInit, I'll save the parameters that I want to be load in the next chart when I switch symbol. Or I could create global variables but honestly I don't think I should use global variables in this case.

What do you guys recommend?

Thanks in advance! 

Files:
panel.PNG  27 kb
 

I think you are overthinking the problem. Set up the chart the way you want. Save as the default template (Default.tpl)

When the  button is pressed, change the chart. Deinit doesn't have to do anything. When the new chart starts, the template sets everything.

Done.

 
William Roeder:

I think you are overthinking the problem. Set up the chart the way you want. Save as the default template (Default.tpl)

When the  button is pressed, change the chart. Deinit doesn't have to do anything. When the new chart starts, the template sets everything.

Done.

Hi William, thank you so much for your answer.

I think that I didn't make myself clear. My bad. I'd like to keep the forex pair open in the chart and modify the button of the pair selected with a strong background in the button. The same with the timeframe selected (example1.png and example2.png are attached).

Every time I change the pair using the button of my indicator, the background color of those buttons are reset.

Files:
example1.PNG  173 kb
example2.PNG  155 kb
Reason: