Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 185

 
GygaByte:

Good afternoon.

I need the EA to quit after a certain event.

I understand this is the deinit() function , I need to call it somehow. This is a quote from the tutorial:

"The special function deinit() is also called for execution by the client terminal when the client terminal is shut down, when the financial instrument window is closed, just before changing a financial instrument and/or chart period, when the program is successfully recompiled in the MetaEditor, when the input parameters are changed, and when the account is changed. "

So I have to close the terminal manually, for example, for this function to be called?

I tried to call this function when a condition triggered, it was executed, but a new tick came and the start function was started again.

How do I still terminate the program?

Thank you.

To close the terminal programmatically, insert at the very beginning of the code before the start() function:

//----
#import "user32.dll"
int GetParent(int hWnd);  // вызов API
#import
//----

In the start() function, when you need to close the terminal, call ExitMT4(), which you declare outside the start() function

//+----------------------------------------------------------------------------+
void ExitMT4() {  // выгрузить MT4 из памяти

   int hwnd=WindowHandle(Symbol(),Period());
   int hwnd_parent=0;
//----
   while(!IsStopped()) {
      hwnd=GetParent(hwnd);
      if(hwnd==0) break;
      hwnd_parent=hwnd;
      }
   if(hwnd_parent!=0) PostMessageA(hwnd_parent,WM_CLOSE,0,0);
}
//+----------------------------------------------------------------------------+
 
artmedia70:

To close the terminal programmatically, insert at the very beginning of the code before the start() function:

In the start() function, when you need to close the terminal, call ExitMT4(), which you declare outside the start() function



Thank you very much for detailed reply.

Basically, it would be enough for me just to terminate the EA, I don't need to close the terminal. Isn't there an easy way to do it?

I think deinit() should somehow solve this issue, but I must be doing something wrong...

 

I can't remove Terminal.exe from Alpari Limited, build 509.

When using the control panel to uninstall, a "You do not have sufficient rights to uninstall. Contact your system administrator!".

When using Uninstall.exe it displays "Server has returned the link".

Alpari technical support is unable to say anything comprehensible. They just suggested that I should delete the entire folder and install the terminal in another directory.

I have Win 7, Ultimate. Administrator rights activated, I ran Uninstall.exe as Administrator.

I would be very grateful for any help in solving this problem.

 
GygaByte:


Thank you very much for the detailed reply.

In principle it would be sufficient for me to simply terminate the EA, there is no need to close the terminal. Isn't there an easy way?

I think deinit() should somehow solve this issue, but I must be doing something wrong...

Not deinit(), but return(0);
 
artmedia70:
Not deinit() but return(0);


If I am not mistaken, return(0) will simply end the current function start() and wait for the next tick, while I need the EA to end its work, as if I had manually detached it from the chart.

I checked it in practice and it keeps displaying "0 open orders" alert with every tick.

I didn't wait for the cherished "Bye".

int start()
  {
  if (OrdersTotal()==0) 
   {
   Alert("Открытых ордеров - ", OrdersTotal());
   return(0);
   }  
  }
//+------------------------------------------------------------------+
int deinit()
  {
 Alert("Пока");  
   return(0);
  }
 
polycomp:

Can't uninstall Terminal.exe from Alpari Limited, build 509.

When using the control panel to uninstall, a "You do not have sufficient rights to uninstall. Contact your system administrator!".

When using Uninstall.exe it displays "Server has returned the link".

Alpari technical support is unable to say anything comprehensible. They just suggested that I should delete the entire folder and install the terminal in another directory.

I have Win 7, Ultimate. Administrator rights activated, uninstall.exe run as administrator.

Will be very grateful for any advice to solve this problem

Some malicious programs (mail.ru, I had it) redistribute access rights, so you with administrator privileges have no access to their removal.

The problem was solved by the method of scientific poke in the redistribution of rights (click on the folder, properties, security, change, add, optional, types of objects, search.......)

But then I got acquainted with "Revo uninstaller" and all the hassle of deleting something disappeared + the certainty that the registry was cleaned of their activities.

 
GygaByte:


If I am not mistaken, return(0) will simply finish the current function start() and wait for the next tick. I need the EA to finish its work as if I had manually detached it from the chart.

I checked in practice - endlessly with every tick it gives the alert "Open orders - 0".

I have not waited for the cherished "Bye".

Your wish is reminiscent of the "checkers" joke. If you want the EA to stop trading, then by activating the (global) flag (after some conditions), interrupting the start() function (exit via return) will give the expected result.
 
ALXIMIKS:

Some malicious programs (mail.ru I had) redistribute access rights and make it so that you with administrator rights do not have access to their deletion.

The problem was solved by the scientific method of redistributing permissions ( PCM on the folder, properties, security, change, add, optional, types of objects, search.......)

But then I got acquainted with "Revo uninstaller" and all the hassle of deleting something disappeared, + the certainty that the registry was cleaned FROM their activities.

Thank you very much! I will get acquainted with Revo uninstaller.
 
TarasBY:
Your wish is reminiscent of the "draughtsman" joke. If you want advisor to stop trading, then by activation of (global) flag (after some conditions), interrupting function start() (exit via return) will give the expected result.

This is roughly what it looks like:

bool GlobalFlag;
int init()
{
   GlobalFlag = true;
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   if ( GlobalFlag )
      if (OrdersTotal() == 0) 
      {
         GlobalFlag = false;
         Alert("Открытых ордеров - ", OrdersTotal());
         Alert("Пока");  
      }  
   return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}
//+------------------------------------------------------------------+
 
Mislaid:

This is roughly what it looks like:

Only it is better to make the flag a global variable of the terminal. Otherwise, after the restart, this flag will be reset to its initial state and the EA will work as it did during the first run. And at the first start, the number of orders may also be zero.