AccountNumber On Init Validation

 

Hi,


I would like to ask the forum the forum the following:

In an indicator in the Init block code, I have added some code to test the accountnumber, AccountCompany & IsDemo if the accountnumber,AccountCompany & IsDemo are equal to their preset values then the indicator Starts

else it doesnt start. The aforementioned code works fine but if I close the terminal, without closing the indicator's window, and reopen the terminal then the same indicator, that was previously ok, does not open. Visually that can be seen with the indicators subchart being blanck. Does anyone know why this is happening?


Thanking zou in advance,

Panos

 

My crystall ball says that your code is broken.

Change it the right way and it will work fine.

 
eddie:

My crystall ball says that your code is broken.

Change it the right way and it will work fine.



This is the InitCodeBlock

Is my validation method incorrect? Could you please have a look?

//****************************** ACCOUNT Related Data ******************************************

struct ACCOUNT_DATA
{
int Account_Number;
string Broker_Name;
bool Demo;
};

ACCOUNT_DATA Account_Data;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

   Account_Data.Account_Number=AccountNumber();
   Account_Data.Broker_Name=AccountCompany();
   Account_Data.Demo=IsDemo();
   
   
    if (Account_Data.Account_Number==1234 && Account_Data.Broker_Name=="MyBroker Stockbrokers Limited" && Account_Data.Demo==true)
   {
    return(INIT_SUCCEEDED);
   }else
   {
    Print("Not Valid Account!");
    return(INIT_FAILED);
   }
  }
 

kei2tahn:

Visually that can be seen with the indicators subchart being blanck. Does anyone know why this is happening?


Do you also see the print

Print("Not Valid Account!");

?

 
GumRai:

Do you also see the print

?

If I close the terminal, while having loaded the indicator on my chart, and then reopen the terminal thy chart reopens but with the subchart of my indicator blanck.

Yes I do see the print "Not Valid Account" after reopening the terminal!!

 
kei2tahn:

If I close the terminal, while having loaded the indicator on my chart, and then reopen the terminal thy chart reopens but with the subchart of my indicator blanck.

Yes I do see the print "Not Valid Account" after reopening the terminal!!

Then I guess that the terminal is loading the indicator before loading all the account information.
 
GumRai:
Then I guess that the terminal is loading the indicator before loading all the account information.
Yes, every indicator runs OnInit and then OnCalculate (to fill buffers) without need for a tick or a connection.
 

OnInit should do the minimum necessary, do not assume that there are candles, history, orders, etc., ready.

Make your check in OnCalculate so all information is valid. ExpertRemove - Common Functions - MQL4 Reference the if not.

 
I'm beginner to mql4 and I'm also getting the same issue when I have AccountNumber validation on OnInit/init ().
The code works fine but if I close the terminal, without closing the indicator's window, and reopen the terminal then the same indicator, that was previously ok, does not open. 
It seems like terminal is loading the indicator before loading all the account information.
Could you please suggest how to fix it. 
In my code I don't have OnCalculate function , can I use the AccountNumber validation on start().
please help.
thanks
 
sdkp:   AccountNumber validation on OnInit/init ().
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.
 
Panagiotis Kourtesis:

This is the InitCodeBlock

Is my validation method incorrect? Could you please have a look?

int ok= 0; //define a glob- var
int init()
{

Account_Data.Account_Number=AccountNumber();
.........
if (Account_Data.Account_Number==1234 && Account_Data.Broker_Name=="MyBroker Stockbrokers Limited" && Account_Data.Demo==true)
{
ok=1;
return(INIT_SUCCEEDED);
}else
{
Print("Not Valid Account!");
ok=0;
return(INIT_FAILED);
}
}

onStart()
{

if (ok==0) {
Print("Not Valid Account!");
ok=0;
return(INIT_FAILED);
}
........ orginal code ......

}
17:37
Reason: