Timer not working

 

Hi all,

I would like to get a timer to close open trades on Saturday and start on Sunday.

For that I try the to use the follow code, but with it no orders are opening. Could you tell me what am I doing wrong ?

extern int    StartHourOnSunday      =   21;    
extern int    LastHourOnFriday       =   21;  
if(Bid > BuyTrigger && BuyAllowed && TradingHours() == true)    
     {//5       
                 RefreshRates();                               
       BuyTicket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage*pips2points,0,0,"Initial Buy Order",MagicNumber,0,Green);
       if(BuyTicket > -1)      
     bool TradingHours()
 //----      
        {   
       if(DayOfWeek()== 5 && Hour()>= LastHourOnFriday)CloseOpen();
       if(DayOfWeek()== 0 && Hour()>= StartHourOnSunday)
       if(Hour() <= LastHourOnFriday) return (true);
 //----                  
       return (false);
        } 

Thank you in advance for any support provided.

Luis

 
luisneves:

Hi all,

I would like to get a timer to close open trades on Saturday and start on Sunday.

For that I try the to use the follow code, but with it no orders are opening. Could you tell me what am I doing wrong ?

Thank you in advance for any support provided.

Luis

Instead of DayOfWeek() use TimeDayOfWeek( TimeCurrent() ) and instead of Hour() use TimeHour( TimeCurrent() )

What is meant to happen on Tuesday or Thursday ? i.e. when the day of the week is not 0 and is not 5 ?

 
RaptorUK:

Instead of DayOfWeek() use TimeDayOfWeek( TimeCurrent() ) and instead of Hour() use TimeHour( TimeCurrent() )

What is meant to happen on Tuesday or Thursday ? i.e. when the day of the week is not 0 and is not 5 ?


Hi RaptorUK,

Thank you for your prompt attention to my post and thank you by the clue about my last issue, now the ea is do what I was looking for.

Regarding your question about what the ea behavior should be in the other days of the week well, I'm just looking to close all trades at week end so, the ea should work 24 hours on those days.

Best regards

Luis

 
RaptorUK:

Instead of DayOfWeek() use TimeDayOfWeek( TimeCurrent() ) and instead of Hour() use TimeHour( TimeCurrent() )

If I may ask, why use TimeDayOfWeek() and TimeHour(), instead of DayOfWeek() and Hour()?
 
// forum.mql4.com/33851 reports DayOfWeek() always returns 5 in tester.
Reason: