object created but moved with changing in input paramers.

 

hi

i drew a hLine in chart with ObjectCreate() function and initial parameter for hLine is set in OnInit in my indicator.

user can select the line ,move and change properties. that is ok.

but when i change input parameters in indicator and it is not related to line however the line will move to the first position because of OnInit

how i fix it?

 
ali abedi:

hi

i drew a hLine in chart with ObjectCreate() function and initial parameter for hLine is set in OnInit in my indicator.

user can select the line ,move and change properties. that is ok.

but when i change input parameters in indicator and it is not related to line however the line will move to the first position because of OnInit

how i fix it?

Every time you change any Input Parameter the indicator is re-initialized...

Remove the position of the line from OnInit() and put/create it in a, i.e., updateLine() function, so yuo can check the current position regarding your initial settings and if the user moved it around...

You can also work along with the OnChartEvent() hook...

;)

 

thanks alot Minions Labs

but i need to put the line  first time  randomly when indicator is placed  on chart and user can change position

and  if i create a function, where should i use it?

i think i should save last state in file and load in OnInit. is this true?

 

I assume that you are deleting the line in OnDeinit()?

https://www.mql5.com/en/docs/event_handlers/ondeinit

Check the reason and do not delete the line if the reason is REASON_PARAMETERS.

in OnInit() check if the line already exists, if so do not create it or set any co-ordinates for it.

Documentation on MQL5: Event Handling / OnDeinit
Documentation on MQL5: Event Handling / OnDeinit
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 |
Reason: