This can be simplified if (TimeHour(TimeCurrent())>=7 && TimeHour(TimeCurrent())<=18){ time_OK=true; }else{ time_OK=false; }
What you wrote if (aBool){ time_OK=aBool; }else{ time_OK=aBool; }
Simplified. time_OK=TimeHour(TimeCurrent())>=7 && TimeHour(TimeCurrent())<=18;
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.- The other months are stop at "else" of the code.Impossible; the code finishes the if/else and continues there after. Your problem is elsewhere. Put a print statements (including variable values) after and find out why.
- Must i use "MqlDateTime& dt_struct" in TimeCurrent?Not if you want the current time.
Hi, excuse me, I explained bad.
if (TimeHour(TimeCurrent())>=7 && TimeHour(TimeCurrent())<=18){ time_OK=true; }else{ time_OK=false; }if (time_OK=true) { ....EA is all in here...}
Impossible; the code finishes the if/else and continues there after. Your problem is elsewhere. Put a print statements (including variable values) after and find out why.
Infact, i have used "else" only for detect this problem through print, and EA stops here.
Same mistake if I catch the last 3 month, it opens only a position on the 1st of dicembre. I' m starting to think that is a problem of historical data... I' m using tickstory.
I have found the problem. A stupid error.
if (TimeHour(TimeCurrent())>=7 && TimeHour(TimeCurrent())<=18)
{time_OK=true;)
if(time_OK==true)
{
if (giro==0)
{
if (TIME>=7 && TIME<12) //
{ if (TimeHour(TimeCurrent())>12 && TimeHour(TimeCurrent())<18)
{giro=1;}
}
if (TIME>=12 && TIME<24) //
{if (TimeHour(TimeCurrent())>=7 && TimeHour(TimeCurrent())<12)
{giro=1;}
}
if (TIME>=0 && TIME<7) // THIS WAS THE PROBLEM. I HAVE FORGOTTEN TO SELECT THE TIME OF ORDERCLOSE, IF IT HAD HAPPENED BETWEEN 0 AND 6. IN THIS CASE "giro" COULD NOT CHANGE THEIR STATUS.
{if (TimeHour(TimeCurrent())>=7 && TimeHour(TimeCurrent())<12) //
giro=1;} //
}
}
if (giro==1)
{
total=OrdersTotal();
Symb=Symbol();
for(int i=1; i>=OrdersTotal(); i++)
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If
{ //
if (OrderSymbol()==Symb) //
{
ticket=OrderTicket();
prezzo=OrderOpenPrice();
SL=prezzo-15*Point;
TP=prezzo+20*Point;//
RefreshRates();
if ((Bid>=TP)||(Ask<=SL))
{
ans=OrderClose(ticket,lotti,Ask,2,red);
if (ans==true)
{
Print("ordine chiuso");
contabarre=0;
giro=0;
TIME=Hour();
return(0);
}
}
return(0);} //
}
else
{
break; //
}
}
![]() Play video | Please edit your post. For large amounts of code, attach it. |

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all.
I have inserted this code in my EA:
if (TimeHour(TimeCurrent())>=7 && TimeHour(TimeCurrent())<=18)
{time_OK=true;}
else {time_OK=false;}
The backtest period going from 28 february 2015 to 28 february 2016. However, the ea operates only in march 2015(where it starts) and in february 2016. The other months are stop at "else" of the code.
Why? Must i use "MqlDateTime& dt_struct" in TimeCurrent?
Thanks all.