Download MetaTrader 5

Not Alerting if Account was changed

To add comments, please log in or register
bunnycat
75
bunnycat  

Hey, so I call a function on order close, but I want the alert to not be triggered if I change accounts.  So for instance, I have an order open in an account, then switch to the demo, I don't want my custom alert function to trigger.


This is the end of the main EA code:

if (Orders>OrdersTotal()) {  
      
      AlertOrder(maxlots);
      Orders=OrdersTotal();
      return;      
      
      }
      
      Orders=OrdersTotal();

 I tried putting "Orders = 0" in OnDeInit, but that didn't solve it.  AlertOrder still gets called if i change accounts.  

 Any idea how to fix it?  Thanks in advance!

Tecuciztecatl
70
Tecuciztecatl  

Use ACCOUNT_LOGIN:

/// on init
if (login==0) login=AccountInfoInteger(ACCOUNT_LOGIN);
if (login!=AccountInfoInteger(ACCOUNT_LOGIN))
   {
   login=AccountInfoInteger(ACCOUNT_LOGIN);
   // new account
   }
bunnycat
75
bunnycat  

Thanks so much!!! Works great!!!

whroeder1
14785
whroeder1  
Or just check for it directly: if(  UninitializeReason() == REASON_ACCOUNT )
Tecuciztecatl
70
Tecuciztecatl  
WHRoeder:
Or just check for it directly: if(  UninitializeReason() == REASON_ACCOUNT )
Yes, I looked at this, but this phrase confused me: "...or reconnection to the trade server has occurred due to changes in the account settings"
bunnycat
75
bunnycat  

hmm, yeah, even simpler, but I wonder about what Tecuciztecatl brought up.  What do you think falls into that category?

Thanks both of you! 

whroeder1
14785
whroeder1  
bunnycat: What do you think falls into that category?
  1. Confusion, false assumptions, misreading, mis-translations.
  2. Instead of trying a actual test to find out.
bunnycat:
if (Orders>OrdersTotal()) {  
      
      AlertOrder(maxlots);
      Orders=OrdersTotal();
      return;      
      
      }
      
      Orders=OrdersTotal();
No OrderSelect loop with filtering means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
To add comments, please log in or register