How can I test to see if my broker allows me to do automatic trading or not?

 

Hey guys,

Is there a simple code that I can test on my MT5 application to see if my broker allows automatic trading or not? (I am not in Forex market and just like to see does automatic trading work in our market(Iran market) or not? I know my broker allows conditional orders on MT5)


***I also seek about some simple and short articles about "what is automatic trading and how does it work"?

 
Documentation on MQL5: MQL5 programs / Trade Permission
Documentation on MQL5: MQL5 programs / Trade Permission
  • www.mql5.com
MQL5 language provides a special group of trade functions designed for developing automated trading systems. Programs developed for automated trading with no human intervention are called Expert Advisors or trading robots. In order to create an Expert Advisor in MetaEditor, launch MQL5 Wizard and select one of the two options: Expert Advisor...
 
Marco vd Heijden:

Hello please see: https://www.mql5.com/en/docs/runtime/tradepermission


Thanks Marco,

But as I am new on this, where should I run the codes for checking?

 

That depends on what you are trying to achieve.

Are you trying to make an EA or Script?

Do you want to check it when you try to place an order, or do you want to check it when the EA/Script is loaded onto the chart?

In the last case you can put it in OnInit() function.

Otherwise before OrderSend() / OrderCheck().

Here is an example stand alone script that will print to the logfile:

//+------------------------------------------------------------------+ 
//| Script program start function                                    | 
//+------------------------------------------------------------------+ 
void OnStart() 
  { 
//--- Name of the company 
   string company=AccountInfoString(ACCOUNT_COMPANY); 
//--- Name of the client 
   string name=AccountInfoString(ACCOUNT_NAME); 
//--- Account number 
   long login=AccountInfoInteger(ACCOUNT_LOGIN); 
//--- Name of the server 
   string server=AccountInfoString(ACCOUNT_SERVER); 
//--- Account currency 
   string currency=AccountInfoString(ACCOUNT_CURRENCY); 
//--- Demo, contest or real account 
   ENUM_ACCOUNT_TRADE_MODE account_type=(ENUM_ACCOUNT_TRADE_MODE)AccountInfoInteger(ACCOUNT_TRADE_MODE); 
//--- Now transform the value of  the enumeration into an understandable form 
   string trade_mode; 
   switch(account_type) 
     { 
      case  ACCOUNT_TRADE_MODE_DEMO: 
         trade_mode="demo"; 
         break; 
      case  ACCOUNT_TRADE_MODE_CONTEST: 
         trade_mode="contest"; 
         break; 
      default: 
         trade_mode="real"; 
         break; 
     } 
//--- Stop Out is set in percentage or money 
   ENUM_ACCOUNT_STOPOUT_MODE stop_out_mode=(ENUM_ACCOUNT_STOPOUT_MODE)AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE); 
//--- Get the value of the levels when Margin Call and Stop Out occur 
   double margin_call=AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL); 
   double stop_out=AccountInfoDouble(ACCOUNT_MARGIN_SO_SO); 
//--- Show brief account information 
   PrintFormat("The account of the client '%s' #%d %s opened in '%s' on the server '%s'", 
               name,login,trade_mode,company,server); 
   PrintFormat("Account currency - %s, MarginCall and StopOut levels are set in %s", 
               currency,(stop_out_mode==ACCOUNT_STOPOUT_MODE_PERCENT)?"percentage":" money"); 
   PrintFormat("MarginCall=%G, StopOut=%G",margin_call,stop_out); 
  }

As you can see there are many checks.

You can simply add the code in there to expand it.

Here are some others Account checks too: https://www.mql5.com/en/docs/constants/environment_state/accountinformation

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
There are several types of accounts that can be opened on a trade server. The type of account on which an MQL5 program is running can be found out using the ENUM_ACCOUNT_TRADE_MODE enumeration. In case equity is not enough for maintaining open positions, the Stop Out situation, i.e. forced closing occurs. The minimum margin level at which Stop...
 
Marco vd Heijden:

That depends on what you are trying to achieve.

Are you trying to make an EA or Script?

Do you want to check it when you try to place an order, or do you want to check it when the EA/Script is loaded onto the chart?

In the last case you can put it in OnInit() function.

Otherwise before OrderSend() / OrderCheck().

Here is an example stand alone script that will print to the logfile:

As you can see there are many checks.

You can simply add the code in there to expand it.

Here are some others Account checks too: https://www.mql5.com/en/docs/constants/environment_state/accountinformation


Thank you very much for your help!

I try to check this code but I get no result. Is that mean this account have no EA access on server side?


   if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED)) 
      Comment("Trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN), 
            ".\n Perhaps an investor password has been used to connect to the trading account.", 
            "\n Check the terminal journal for the following entry:", 
            "\n\'",AccountInfoInteger(ACCOUNT_LOGIN),"\': trading has been disabled - investor mode.");

 

Should I test the codes when the market is open to see auto trading is forbidden or not?

When I test it now(when market is closed) it says this account uses investor password and trading is forbiden for this account!

 
   if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT)) 
      Alert("Automated trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN), 
      " at the trade server side");
 
Marco vd Heijden:

Alert just one time worked and didn't work after that.

 

I used this code:


      if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))
      {
      PrintFormat("Automated trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN), " at the trade server side");
      }
      else
      {
      PrintFormat("trade is free");
      }
     
      if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
      {
      PrintFormat("Trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN),
            ".\n Perhaps an investor password has been used to connect to the trading account.",
            "\n Check the terminal journal for the following entry:",
            "\n\'",AccountInfoInteger(ACCOUNT_LOGIN),"\': trading has been disabled - investor mode.");
            }
            else{
            PrintFormat("trade really is freee");
            }



But I got this results:


2019.01.07 08:59:12.345 HelloWorld (فولای,H1) trade is free
2019.01.07 08:59:12.345 HelloWorld (فولای,H1) Trading is forbidden for the account


Seems the result of first if is true but the second one is false! So what does it mean?

 
rezaeee:

Alert just one time worked and didn't work after that.

You didn't even specify whether it should alert constantly, once, twice, three times or whatever.

This is why i said :

Marco vd Heijden:

That depends on what you are trying to achieve.

It's still unclear what you are trying to do other then to check if EA trading is allowed by the broker, you only have to check this once, it does not change regularly, and how many times it will be checked depends on there you place the code.

 
Marco vd Heijden:

You didn't even specify whether it should alert constantly, once, twice, three times or whatever.

This is why i said :

It's still unclear what you are trying to do other then to check if EA trading is allowed by the broker, you only have to check this once, it does not change regularly, and how many times it will be checked depends on there you place the code.


Dear Marco,

Sorry for unclear posts. Finally I found that my account was expired and the forbidden messages were for that. I asked my broker to re-activate my account, then I tested the above code and got:

2019.01.07 11:14:02.971 TestAuto (وبصادر,D1) trade is free
2019.01.07 11:14:02.973 TestAuto (وبصادر,D1) trade really is freee

So, I think it means my broker allows me doing automatic trading?

If so, please put a very simple code for auto trading that I can test it and see if really auto trading is active in my account and how does it work?(Or give me another link to a simple tutorial about how to write a simple code for auto trading).

 

Best regards.

Reason: