bool always reinitialized to false.
nb : i have declared my bool in global, then tried in local but no success.
When the timeframe changes, the Indicator is reloaded and the the OnInit() is run again.
So, don't reinitialise the variable in OnInit() and only initialise it in the declaration.
//--- display levels bool display_levels = false; int OnInit() { // display_levels=false; }
When the timeframe changes, the Indicator is reloaded and the the OnInit() is run again.
So, don't reinitialise the variable in OnInit() and only initialise it in the declaration.
Thank you.
I try it, but same result.
Maybe it's because I change the true/false value in OnChartEvent() function ?
if( id==CHARTEVENT_OBJECT_CLICK && sparam==my_btn && display_levels==false) { Print("The mouse has been clicked on the object with name '"+sparam+"'"); Print("display_levels = "+(string)display_levels); //--- display_levels=true; //--- Print("display_levels = "+(string)display_levels); }
In wich function have I to do it please? OnCalculate ?
Then save the state to an actual graphical button object and read the state from it when the timeframe changes.
Alternatively save the variable to Global Terminal Variables and restore from it when the timeframe changes.

- www.mql5.com
Then save the state to an actual graphical button object and read the state from it when the timeframe changes.
Alternatively save the variable to Global Terminal Variables and restore from it when the timeframe changes.
Already tried your 1st solution.
But my btn state is reinitialized too. I even tried with color graphical object, and the same.
I will try with your 2nd proposal.
I will let you know.
Thank you.
The 1st solution (using a button state) is guaranteed to work. So you must be doing something wrong. Show your code if you need more help.
// Get button state bool bGetState = (bool) ObjectGetInteger( 0, idButtonObject, OBJPROP_STATE ); // Set button state ObjectSetInteger( 0, idButtonObject, OBJPROP_STATE, bSetState );

- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i am writting an indicator of simple levels display. i can change the value true or false by a button.
but when i change the time frame, the bool always return false.
How i can fix it please ?
Regards.
nb : i have declared my bool in global, then tried in local but no success.