[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 553

 

I am a beginner.

Folks, please advise, as I know the robot is activated every time a tick changes. How to make it activate only when a new candle opens, i.e. when the opening price of the candle appears.

Thank you all for the tips.

 
iruogl:

I am a beginner.

Folks, please advise, as I know the robot is activated every time a tick changes. How to make it activate only when a new candle opens, i.e. when the opening price of the candle appears.

Thank you all for the tips.

To quote the moderator "The function returns true when a new bar appears on M15. Use only in EA."

bool CheckOpenM15()
{
   static int PrevTime=0;
   if (PrevTime==iTime(NULL, PERIOD_M15,0)) return(false);
   PrevTime=iTime(NULL, PERIOD_M15,0);
   return(true);
}
 
paladin80:

To quote the moderator "The function returns true when a new bar appears on M15. Use only in EA."


Thank you very much.
 
iruogl:

Thank you very much.

paladin80:

To quote the moderator "The function returns true when a new bar appears on M15. Use only in EA."


I'm still learning. And in this function, how can you determine the opening price of a candle.
 
rigonich:

Questions for the pros from the dummies:

1. when performing any operations with normalized variables of double type, they behave like variables of int type (the result is a normalized number), or

the result should be normalized?

2. In the help, it is written: "Two non-normalized floating-point numbers cannot be linked using the == or != operations". Can I compare a normalized and a non-normalized

number? Can the operations >= and <= be used?

Any numbers can be compared with each other using >= and <=. After NormalizeDouble is normalized, it is already possible to compare as == or !=. However, you need to see if it makes sense to compare numbers like this, e.g. 10 decimal places, it's just not realistic to find a situation where they would be equal or unequal.
 
iruogl:


I'm still learning. And in this function how can you determine the opening price of a candle.

This function only detects when a candle appears. To find the opening price, use iOpen. Something like this:

int init()
{ ...
}
//---
int start()
{ 
   if (CheckOpenM15())
   {  double BarOpenPrice=iOpen(NULL, PERIOD_M15, 0)
   }
...
}
//---
int deinit()
{ ...
}

// сама функция должна находиться отдельно
bool CheckOpenM15()
{
   static int PrevTime=0;
   if (PrevTime==iTime(NULL, PERIOD_M15,0)) return(false);
   PrevTime=iTime(NULL, PERIOD_M15,0);
   return(true);
}
 
iruogl:

I am a beginner.

Folks, please advise, as I know the robot is activated every time a tick changes. How to make it activate only when a new candle opens, i.e. when the opening price of the candle appears.

Thank you all for the tips.


I am also a beginner, but I think I need to declare a variable of datetime type on global level (for example datetime TIME;) , in init()and check at the beginning of start() if TIME== Time[0] -- return(0); if not -- TIME= Time[0];. In this case, expert will execute start() only once at opening of a new bar.
 
paladin80:
Any numbers can be compared with each other using >= and <=. After NormalizeDouble is normalized, it is possible to compare them as == or !=. However, you need to see if it makes sense to compare numbers with e.g. 10 decimal places, it is unrealistic to find a situation where they would be equal or unequal.

Thanks you very much for the answer. Just to clarify a question: after normalization the number in computer memory remains the same and only its representation changes. or the number itself changes?
 
rigonich:

Thank you very much for your answer. Just to clarify a question: after normalization the number in the computer memory remains the same and only its representation changes, or the number itself changes?

After normalisation the number changes, e.g:

double var1=0.12345 6789;
double var2=NormalizeDouble(var1,5); // var2=0.12346

Another thing is when you print it out, with DoubleToStr, e.g.:

double var1=0.12345 6789;
Print("var1 = ",DoubleToStr(var1,5)); // Выход: var1=0.12345

And if you print it out after normalisation, it goes like this:

double var1=0.12345 6789;
double var2=NormalizeDouble(var1,5);  // var2=0.12346
Print("var2 = ",DoubleToStr(var2,5)); // Выход: var2=0.12346
 
paladin80:

This function only detects when a candle appears. To find the opening price, use iOpen. Something like this:


Thank you, you are very helpful
Reason: