How to add ordersend to Time filter

 

Could someone please tell me

How to add if false == ordersend();

Although I add these coding, EA still open positions.

input string SettingTradingTime ="================================================================== ";
input bool Filter_TradingTime=true;
input string Time_Start= "02:00";
input string Time_End= "21:00";

//----------------------------------------------------------------------------------------||
string Time_Serv;
//----------------------------------------------------------------------------------------||
bool TradingTime()
  {
   Time_Serv =TimeToStr(TimeCurrent(),TIME_MINUTES|TIME_SECONDS);
   if(Filter_TradingTime)
     {
      if(Time_Serv>=Time_Start && Time_Serv<=Time_End)
        {return true; }
      else
        {
         return false;
        }
     }
   return true;
  }
 
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.

Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Yes,


This will not work. Your times need to be in datetime variable type for the comparison you are doing.
 
Dominik Egert:
Yes,


This will not work. Your times need to be in datetime variable type for the comparison you are doing.
Thank you.
 
Forexalpha777:

Could someone please tell me

How to add if false == ordersend();

Although I add these coding, EA still open positions.

you can use this code instead:

input string Time_Start_Hour = 2;
input string Time_Start_Minute = 0;

input string Time_End_Hour = 21;
input string Time_End_Minute = 0;

extern bool Filter_TradingTime=true;
uchar hour = Hour();
uchar minute = Minute();


void OnTick()
   {   
   TradingTime();
   }

bool TradingTime()
  {
   if(Filter_TradingTime)
     {
      if(hour >= Time_Start_Hour && hour<=Time_End_Hour)
        return true; 
      else
         return false;
     }
   }

and about orderSend function, it returns an integer value

and when no order opened, it returns -1

you should write such this:

int ticket = OrderSend();
if (ticket <0)
or
if(ticket ==-1)
 
I suggest not using strings to do such comparison.

Strings are characters. In MQL5 they are Unicode. This type of comparison is considered inconsistent.



 
Mohsen Bjp:

you can use this code instead:

and about orderSend function, it returns an integer value

and when no order opened, it returns -1

you should write such this:

Appreciate it. I will try.
 
Dominik Egert:
I suggest not using strings to do such comparison.

Strings are characters. In MQL5 they are Unicode. This type of comparison is considered inconsistent.


Thank you for the advice