Download MetaTrader 5
To add comments, please log in or register
Do you have Linux? Find out how to install MetaTrader on it!
Panagiotis Kourtesis
2099
Panagiotis Kourtesis 2016.03.30 08: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

peter.MT4Web
158
peter.MT4Web 2016.03.30 09:01  

My crystall ball says that your code is broken.

Change it the right way and it will work fine.

Panagiotis Kourtesis
2099
Panagiotis Kourtesis 2016.03.30 10: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);
   }
  }
Keith Watford
Moderator
7960
Keith Watford 2016.03.30 11: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!");

?

Panagiotis Kourtesis
2099
Panagiotis Kourtesis 2016.03.30 11: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!!

Keith Watford
Moderator
7960
Keith Watford 2016.03.30 11: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.
Ovo Cz
2951
Ovo Cz 2016.03.30 12: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.
whroeder1
13627
whroeder1 2016.03.30 12: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.

/
To add comments, please log in or register