Time filter - page 2

 
RaptorUK:

I did it this way, it uses server time not local time . . .

Hi Raptor

When I print out time current it doesn't return 24 hr format eg 9pm will return 9 instead of 21 is there any settings to enable 24h?

 
I don't think there is any option to print in anything other than 24 hr format, are you sure you aren't printing 9am ? timecurrent is Broker time . . .
 
RaptorUK:
I don't think there is any option to print in anything other than 24 hr format, are you sure you aren't printing 9am ? timecurrent is Broker time . . .
oh yes u're right my broker is returning am .Thanks Raptor
 
RaptorUK:

I did it this way, it uses server time not local time . . .

Hi Raptor 1 more question about this time filter thing

I'm puzzled by why is there a need to have " start > end | start < end "

logic in the time filter what is the purpose to these logics?

 
praetorian:

Hi Raptor 1 more question about this time filter thing

I'm puzzled by why is there a need to have " start > end | start < end "

logic in the time filter what is the purpose to these logics?

I'm not sure whose code you are talking about . . . but it might be to allow for the 2 possible situations:

1. Start time is less than the end time, for example, start at 10:00 end at 22:00

2. Start time is greater than end tome, for example start at 23:00 end at 11:00

 
RaptorUK:

I'm not sure whose code you are talking about . . . but it might be to allow for the 2 possible situations:

1. Start time is less than the end time, for example, start at 10:00 end at 22:00

2. Start time is greater than end tome, for example start at 23:00 end at 11:00

isn't it kind of redunant ? the filter would't fail without these logic right?

 
praetorian:

isn't it kind of redunant ? the filter would't fail without these logic right?

As I said, I'm not sure which code you are talking about . . . but in my code things have too be treated a little differently when the start time > end time compared to when the start time < end time
 
input int StartTradingTime = 0;
input int StopTradingTime = 24;

bool TimeOfDayFlg() {
   bool allowTrading = false;
   int hour = TimeHour(TimeCurrent());

   // user input check <
   if (StartTradingTime < StopTradingTime) {
      // actual time filter
      if (hour >= StartTradingTime &&  hour <= StopTradingTime) {
         allowTrading = true;
      }
   }
   // user input check >
   if (StartTradingTime > StopTradingTime) {
      // actual time filter
      if ( hour <= StopTradingTime) {
         allowTrading = true;
      }
      if(hour >= StartTradingTime) {
         allowTrading = true;
      }
   }
   // user input check ==
   if (StartTradingTime == StopTradingTime) {
      if(hour == StartTradingTime) {
         allowTrading = true;
      }
   }

   return allowTrading;
}
The code above fine for me but it currenlt only handles Hour.. 

I simulated it using Java Code and by using static data:
        boolean allowTrading = false;
        int startTime = 24;
        int stopTime = 5;
        int hour = 5;
 
JJoseph Galicio #:
      if (hour >= StartTradingTime &&  hour <= StopTradingTime) {
  1. Because of the equals sign, you have to set start and stop equal. Which means stop doesn't really mean stop. Generally use less than [start … stop)
  2. Your code simplified.
    input int StartTradingTime = 0;
    input int StopTradingTime = 24;
    
    bool TimeOfDayFlg() {
       int hour = TimeHour(TimeCurrent());
       if (StartTradingTime < StopTradingTime)
          return hour >= StartTradingTime && hour < StopTradingTime);
       return hour < StopTradingTime || hour >= StartTradingTime);
    }

Reason: