Download MetaTrader 5
To add comments, please log in or register
Sell products via the Market and track your sales statistics
bunnycat
75
bunnycat 2016.05.12 03:47 

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 2016.05.12 08:34  

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 2016.05.12 16:33  

Thanks so much!!! Works great!!!

whroeder1
13627
whroeder1 2016.05.12 17:15  
Or just check for it directly: if(  UninitializeReason() == REASON_ACCOUNT )
Tecuciztecatl
70
Tecuciztecatl 2016.05.12 18:09  
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 2016.05.12 20:56  

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
13627
whroeder1 2016.05.13 12:08  
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