Please is this possible or correct?

 

Hello guys i have this idea i wish to implement into my EA, this idea involve waiting one hour after my order has been close that is either if TP or SL is hit and i have been thinking and came up with this so guy please i need your help.

below is my attempt, is it correct? or should there be any changes. THANK IN ADVANCE.

void OnTick()
{
if(One_Hour_Delay()>1)
OrderSend(...);
}
int One_Hour_Delay(){
int varl=0;
for(int k=0; k<OrdersHistoryTotal(); k++){
if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number){
if(TimeToStr(TimeCurrent(),TIME_MINUTES) > TimeToStr(OrderCloseTime()+3600,TIME_MINUTES)){
varl++;}}}}
return(varl);}
 
Please edit your post and remove the ALL UPPERCASE title. It's like SHOUTING and is very unpleasant.
 
Alain Verleyen:
Please edit your post and remove the ALL UPPERCASE title. It's like SHOUTING and is very unpleasant.

Thank you so much, i never knew, i have also changed it.

 
Nkechi Sonia Kanu:

Thank you so much, i never knew, i have also changed it.

Thanks.

 
Nkechi Sonia Kanu:

Hello guys i have this idea i wish to implement into my EA, this idea involve waiting one hour after my order has been close that is either if TP or SL is hit and i have been thinking and came up with this so guy please i need your help.

below is my attempt, is it correct? or should there be any changes. THANK IN ADVANCE.

Why converting to string (TimeToStr) for the comparison ?

One_Hour_Delay()>1  Why greater than 1 ? >0 is not enough ?

Your logic could work with some fixes, but it's very inefficient to run such function on each tick. You should record the "last" close time then just check if current time is at least 1 hour later than "last" close time.

 
Alain Verleyen:

Why converting to string (TimeToStr) for the comparison ?

One_Hour_Delay()>1  Why greater than 1 ? >0 is not enough ?

Your logic could work with some fixes, but it's very inefficient to run such function on each tick. You should record the "last" close time then just check if current time is at least 1 hour later than "last" close time.


  • The reason i converted to string is to help convert the TimeCurrent() to minutes 

TimeToStr(TimeCurrent(),TIME_MINUTES)

  • well ummm i guess am not too good in logic... lol ; >0 will do.
  • please just give a hint on how i can do that please.

 
Nkechi Sonia Kanu:

  • The reason i converted to string is to help convert the TimeCurrent() to minutes 

  • well ummm i guess am not too good in logic... lol ; >0 will do.
  • please just give a hint on how i can do that please.

I already gave you hints. Up to you to try and come back if you need help.

 
datetime varl=TimeToStr(TimeCurrent()+3600,TIME_MINUTES);
earl=0;
for(int i=0; i<OrdersHistoryTotal(); i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number){
if(OrderCloseTime()>=varl){
earl++;}}}}

if(earl>0)
OrderSend(...);
}

Hello everyone i did another test using Alain Verleyen idea but with a little modification, what i did was to  stored the current time plus another one hour in a variable and i picked the closing time of the latest closed trade and check if its closed time is greater than or equal to the current time + one hour.

please guys help me, what i wanted is to make an EA to wait an hour after a position has been closed.


THANKS IN ADVANCE.

 
  1. datetime varl=TimeToStr(TimeCurrent()+3600,TIME_MINUTES);
    Why such complicated code? var1=TimeCurrent()+3600;

  2. if(OrderCloseTime()>=varl){
    The close time of any order will never be an hour in the future.

  3. Find the latest close time. Then see if it was an hour ago.
 
whroeder1:
  1. Why such complicated code? var1=TimeCurrent()+3600;

  2. The close time of any order will never be an hour in the future.

  3. Find the latest close time. Then see if it was an hour ago.

void OnTick()
{
datetime varl=TimeToStr(TimeCurrent()+3600,TIME_MINUTES);

int earl=0;
for(int i=0; i<OrdersHistoryTotal(); i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number){
if(TimeToStr(OrderCloseTime(),TIME_MINUTES)>=varl){
earl++;}}}}

if(earl>0)
OrderSend(...);
}

Hello Whroeder1, thanks for helping out.

  1. The reason why i use TimeToStr() is because i notice you can convert any time either to TIME_MINUTES, TIME_DATE or TIME_SECONDS (TIME_MINUTES convert the time to hours) if i had used TimeCurrent+3600, without  #property strict it will just display series of numbers and with #property strict it will display the date, the hour, minutes and seconds thats what i don't want...i just want the time in hour thats why i use TimeToStr().
  2. Yeah i saw i made a mistake so i corrected it using TimeToStr.
  3. i simply just converted the closing time to hour and check if its greater than the current time +one hour .

 

I just saw something TimeCurrent() gives the current time of the trading server, which always move and is never stactic and adding an hour to it will make the OrderClosingTime() never be equal to it,

so what i should do is add the one hour to the OrderClosingTime() instead and check if the TimeCurrent() is greater than it.


HOPE AM ON THE RIGHT TRACK GUYS. 

Reason: