Expert doesn't perform any trades!

 

i made my expert locked by certain account number and with time constraint and can only work on a demo account , the problem is that it doesn't perform any trades !

static datetime allowed_until = D'2020.12.30 00:00'; 
const long allowed_accounts =  11111111;                           
int password_status = -1;



void OnInit()
{
   datetime now = TimeCurrent();
   long account_login = AccountInfoInteger(ACCOUNT_LOGIN);
   
   if (account_login == allowed_accounts && now < allowed_until ) 
      { 
         password_status = 1;
         Print("EA verified");    
      }
      
   else
   {
      Print("EA is not allowed"); 
   } 
    

}
void OnTick()
  {
//---
 if (password_status == 1 && TimeCurrent() < allowed_until &&  AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO) 
  {

    // Logic for orders

  }

 else Print("EA expired.");

  } // on tick
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
Account Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Any help ?
 
andrw11:

i made my expert locked by certain account number and with time constraint and can only work on a demo account , the problem is that it doesn't perform any trades !

of course it does not performed any trade . There is no ordersend code has been implement .

 
Cosmas Moses Boniface:

of course it does not performed any trade . There is no ordersend code has been implement .

the whole logic and order sending and management are there , i just represented them with  his line "logic for trades" as the problem isn't in there as i'm using the same expert just without the constraints and it's working fine 

 

your code works for me. 

1. Error is in the "logic for order"

2. the account number isn't right

 
La_patates:

your code works for me. 

1. Error is in the "logic for order"

2. the account number isn't right

1.Can't be . as i have mentioned i'm already using it without issues 

2.i know , i changed it for the privacy of the client 

 
andrw11:

1.Can't be . as i have mentioned i'm already using it without issues 

2.i know , i changed it for the privacy of the client 

"Can't be"doesn't work here. There is an issue somewhere.

I put my account number in there and put my code in the "logic", it runs flawlessly. So we're back at the same issue as my last post. The error is in code we can't see. Is your client trying to use it on a live account?
 
void OnInit()
{
   datetime now = TimeCurrent();
   long account_login = AccountInfoInteger(ACCOUNT_LOGIN);
   
   if (account_login == allowed_accounts && now < allowed_until ) 

Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:

  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 
La_patates:
"Can't be"doesn't work here. There is an issue somewhere.

I put my account number in there and put my code in the "logic", it runs flawlessly. So we're back at the same issue as my last post. The error is in code we can't see. Is your client trying to use it on a live account?

yes live account ( DEMO NOT REAL) 

 
William Roeder:

Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:

  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

Thanks for the clarification , so you think if i moved the code in "OnInit" to "OnTick" , this would solve the issue ?

 
andrw11:

Thanks for the clarification , so you think if i moved the code in "OnInit" to "OnTick" , this would solve the issue ?

Why don't you simply debug your code instead of asking unanswerable questions. No one here knows about your broker and how they set up your account.

Print("account_login == allowed_accounts : ",account_login == allowed_accounts);
Print("now < allowed_until : ",now < allowed_until);
Print("password_status == 1 : ",password_status == 1);
Print("TimeCurrent() < allowed_until : ",TimeCurrent() < allowed_until);
Print("AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO : ",AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO);