Questions from Beginners MQL5 MT5 MetaTrader 5 - page 440

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello 2015.09.17_19:07 GMT+3 .I have set the dimensions of dynamic arrays in the EA program. And the compiler gives errors: "comma expected". And if there is a variable in the program text, -- gives warnings: "variable such-and-such hides variable declaration at global level". I don't get it. Everything seems to be correct, like in Help. Here are some code snippets:
//--- array of maximal bar prices
bool ArraySetAsSeries(double &High[],bool);
//---
bool ArraySetAsSeries(double &Low[],bool);
//--- set the array sizes with reserve (reserve)
int ArrayResize(double &mrate[],int 16,int 9);
int ArrayResize(double &maVal[],int 16,int 9);
int ArrayResize(double &fVal[],int 3,int 2);
int ArrayResize(double &zVal[],int 3,int 0);
int ArrayResize(double &High[],int 1,int 0);
int ArrayResize(double &Low[],int 1,int 0);
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Hello 2015.09.17_19:07 GMT+3 .I have set the dimensions of dynamic arrays in the EA program. And the compiler gives errors: "comma expected". And if in the program text there is
If you mean my code - then yes, my code is checking for a new bar.
I am interested in the code I have attached - I want to understand what it does.
The code you gave doesn't do anything, or rather it doesn't work. Error:
This condition will only work once - the first time you run the program. At this point, the static variable will be initialized.
The condition below is meaningless to check at all since the variable TimeN in your code will be equal to eternal zero (or rather the date January 1, 1970) and this eternal zero will be compared to the variable TimeC which equals the time the current bar opens):
The code you gave doesn't do anything, or rather it doesn't work. Error:
This condition will only work once - the first time you run the program. At this point, the static variable will be initialized.
The condition below is meaningless to check at all since the variable TimeN in your code will be equal to eternal zero (or rather it will be the date January 1, 1970) and this eternal zero will be compared to the variable TimeC which equals the opening time of the current bar):
Now I wonder why I should have written it... into Expert Advisor.
Thanks for the clarification!
If the new bar is on the M1 timeframe, then print the message:
Turns out I didn't give the full code, the correct one was
int init()
{
static datetime TimeN=0;
return(INIT_SUCCEEDED);
}
int start()
{
datetime TimeC=iTime(NULL,TF,0);
if(TimeN==0)TimeN=TimeC;
if(TimeN==TimeC) return(0);
TimeN=TimeC;
// Код программы исполняется при появлении нового бара
return(INIT_SUCCEEDED);
}
Turns out I didn't give the full code, the correct code was
int init()
{
static datetime TimeN=0;
return(INIT_SUCCEEDED);
}
int start()
{
datetime TimeC=iTime(NULL,TF,0);
if(TimeN==0)TimeN=TimeC;
if(TimeN==TimeC) return(0);
TimeN=TimeC;
// Код программы исполняется при появлении нового бара
return(INIT_SUCCEEDED);
}
Here's the working code:
Have you tried to compile this code? There is an error here: the variable TimeN is declared in OnInit() and on exit from OnInit() this variable will be destroyed. Therefore, an error occurs in the OnTick() function
Here is the working code:
I wrote static datetime TimeN=0; in the area beforeint OnInit() - where external and other variables are declared.