problem with OnInit function in mql4

 

Hi  i have Custom Indicator with to many button and line on chart. everything if work correctly when the indicator drag on chart but when the user change the time frame OnInit function restart all the variable, button state and all of the other thing to the default, so use should change everything each time timeframe change. I try read the reason state in OnDeinit and set the value on the global variable. then when the OnInit run and the reason equals 3 OnInit body not run. but each time after the OnDeinit finished and OnInit, reason and my variable restart too, and the OnInit change everything again.

for another example even when my user hide or delete the buttons on chart, after time frame  change and OnInit run, all of the button show again.

how can i manage OnInit to not restart everything each time timeframe change?

 
justlink:

Hi  i have Custom Indicator with to many button and line on chart. everything if work correctly when the indicator drag on chart but when the user change the time frame OnInit function restart all the variable, button state and all of the other thing to the default, so use should change everything each time timeframe change. I try read the reason state in OnDeinit and set the value on the global variable. then when the OnInit run and the reason equals 3 OnInit body not run. but each time after the OnDeinit finished and OnInit, reason and my variable restart too, and the OnInit change everything again.

for another example even when my user hide or delete the buttons on chart, after time frame  change and OnInit run, all of the button show again.

how can i manage OnInit to not restart everything each time timeframe change?

Do not delete the buttons in OnDeinit().

When the indicator restarts, check if the button exists. If it exists do not do anything that will re-set the button state.

 
Keith Watford:

Do not delete the buttons in OnDeinit().

When the indicator restarts, check if the button exists. If it exists do not do anything that will re-set the button state.

My  OnDeinit code only delete button when the indicator close
void OnDeinit(const int reason)
  {
   if(reason == 1)
     {
      ObjectsDeleteAll(0,"Btn",0,-1);
      ObjectDelete(0,"BtnHiddenShow");
     }
   ChartRedraw(0);
  }

and not only button, even the Indicator line restart. some of my indicator line is Draw_None By default, and user decided if this line should show or hide with the button. But after user set them to show and then time frame change, all of the that line set to Draw_none again and user should chose and change them from the beginning.

////// like this 
SetIndexStyle(2,DRAW_NONE);
      SetIndexStyle(3,DRAW_NONE);
      SetIndexStyle(5,DRAW_NONE);
      SetIndexStyle(7,DRAW_NONE);
 
justlink:
My  OnDeinit code only delete button when the indicator close
Keith Watford:

Do not delete the buttons in OnDeinit().

When the indicator restarts, check if the button exists. If it exists do not do anything that will re-set the button state.

 
Keith Watford:

thank you my buttons not restarts when the time frame change now.

but still my indicator line back to default shift, style, type and width. how can fix this too?

 
justlink:

thank you my buttons not restarts when the time frame change now.

but still my indicator line back to default shift, style, type and width. how can fix this too?

Think about it.

Didn't you say that the state of the button dictates this?

 
Keith Watford:

Think about it.

Didn't you say that the state of the button dictates this?

thank you again.

i do not think about it from that view.

my problems solved and i only need check every button state. then define each line again depend of them. :)

with this solution noting back to default after time frame changed.

 

All of my problem almost solved, but i have another related problem now.

I have to many global int and color variables and each time timeframe changed the value of this parameters restart and back to default too. how can prevent this?

Reason: