How to restrict trading to RTH (NOT US timezone) extending into next day

Hi,

I am building a system to trade only the first 5 hrs of the RTH. Since my timezone is different, the RTH actually extends into the next day for me.
Example: RTH begins at 9:00 PM (20:00) and I want the system to trade till 2:00 AM (02:00) which is about 5 hours of trading.
From the example here, I tried:

tn = TimeNum();
startTime = 210000; // start in HHMMSS format
endTime = 020000;  // end in HHMMSS format
timeOK = tn >= startTime AND tn <= endTime;

But this does not work properly - I don't see the signals properly.
So, I thought of doing something like a time-difference based approach like:

tn = TimeNum();
startTime = 200000; // start in HHMMSS format
d1 = DateTimeConvert( 2, DateNum(), startTime );
d2 = DateTimeConvert( 2, DateNum(), tn );
diff = DateTimeDiff( d2, d1 );
timeOK = diff < 18000 AND diff > 0;

But, this only works till midnight (00:00) and no signals appear after that. Is there a better way to code it such that it restricts the signals from 9PM to 2AM only? (5 hrs)

You can write like this:

if (strartTime>endTime)
{
        timeOK = TimeNum() > startTime  OR TimeNum() < endTime;
}
else
{
        timeOK = TimeNum() > startTime And TimeNum() < endTime;
}

Did you try using TimeShift in Intraday settings?

This feature is very useful for those in different timezones.

https://www.amibroker.com/guide/w_dbsettings.html

www.amibroker.com/kb/2006/03/19/how-does-the-daily-time-compression-work/

Thanks for your replies @travick and @enjoynova.
@travick That intraday setting messes up with my charting timelines - I want to see all the bars (full trading RTH) but only want to trade on a portion of it - so I thought dealing this within the code itself would be better.

@enjoynova your suggestion worked! But I only needed:

timeOK = TimeNum() > startTime  OR TimeNum() < endTime;

the other condition never gets satisfied because startTime will always be greater than endTime since if the next day comes, those variables will have the same date when they are being compared. Please do correct me if I'm wrong.

Hey!
just following up on my previous reply, I read more about timeshift after my post and saw that it is actually a better approach and would save me a lot of headache in the coding part.
So, is it possible to mention the hours in decimals? like if the timezone difference is 11.5 hrs, how would I specify it since that text box does not allow [. , -] or any special characters.

Yes!What I show you is that when you modify the trading time, it automatically adapts.

You mean the timeshift settings? because in your suggestion there isn't any change to the trading time.

If you are talking about the timeshift setting, do you have any idea on how to mention fractional hours?
I mean instead of whole numbers like 6 or 7, how would I go about mentioning 6 hrs 30 mins or 7 hrs 45 mins? The example only shows for a whole number and that text input box only accepts numbers and no special characters.