AccountNumber On Init Validation

Back to topics list To post a new topic, please log in or register
avatar
18
kei2tahn 2016.03.30 10:52
 

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

avatar
108
eddie 2016.03.30 11:01 #
 

My crystall ball says that your code is broken.

Change it the right way and it will work fine.


avatar
18
kei2tahn 2016.03.30 12:36 #
 
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);
   }
  }
avatar
Moderator
3406
GumRai 2016.03.30 13:24 #
 

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

?

avatar
18
kei2tahn 2016.03.30 13:32 #
 
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!!

avatar
Moderator
3406
GumRai 2016.03.30 13:55 #
 
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.
avatar
1109
Ovo 2016.03.30 14:06 #
 
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.
avatar
12985
WHRoeder 2016.03.30 14:18 #
 

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.




Back to topics list  

To add comments, please log in or register