Download MetaTrader 5

AccountNumber On Init Validation

To add comments, please log in or register
Panagiotis Kourtesis
2485
Panagiotis Kourtesis  

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

peter.MT4Web
158
peter.MT4Web  

My crystall ball says that your code is broken.

Change it the right way and it will work fine.

Panagiotis Kourtesis
2485
Panagiotis Kourtesis  
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);
   }
  }
Keith Watford
Moderator
9641
Keith Watford  

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!");

?

Panagiotis Kourtesis
2485
Panagiotis Kourtesis  
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!!

Keith Watford
Moderator
9641
Keith Watford  
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.
Ex Ovo Omnia
3185
Ex Ovo Omnia  
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.
whroeder1
14778
whroeder1  

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.

To add comments, please log in or register