Prevent closing terminal with open order

 
Is there any way to check some open order when the user clicks the button to close the terminal and prevent the terminal from closing until the order is closed?

I tried doing it in the OnDeinit event but it didn't work:

 void OnDeinit(const int reason)
 {
   if(PositionSelect(_Symbol)) { //Position opened
     Alert("Close positions!");
     return;
   }

}

Improperly formatted code edited by moderator.

thanks!

 

Please, always use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Murilo Junqueira: Is there any way to check some open order when the user clicks the button to close the terminal and prevent the terminal from closing until the order is closed?

No! The OnDeinit handler will be forcefully exited after 2.5 seconds and the EA terminated.

Deinit

Before global variables are deinitialized and the program (Expert Advisor or custom indicator) is unloaded, the client terminal sends the Deinit event to the program. Deinit is also generated when the client terminal is closed, when a chart is closed, right before the security and/or timeframe is changed, at a successful program re-compilation, when input parameters are changed, and when account is changed.

The deinitialization reason can be obtained from the parameter, passed to the OnDeinit() function. The OnDeinit() function run is restricted to 2.5 seconds. If during this time the function hasn't been completed, then it is forcibly terminated. The Deinit event is not generated for scripts.