Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
It is possible to code into TOS strategies where pre/after market data is shown but have it set where only trades during defined trading hours (NY session) is when trades take place? So essentially, it closes any open orders before NY close and then will not trade until NY sessions begins the next day.
I googled everywhere but found nothing.
Can you help answer these questions from other members on NexusFi?
Yes. Something like this works for me (I wrote this at work, so haven't verified that it works correct, but I use some rendition of this in my strategies):
def isopen=if secondsFromTime(0930)>=0 and secondstillTime(1600)>=0 then 1 else 0;
def isclosed=if secondsFromTime(1600)==0 then 1 else 0;
def tradinghours=if isopen then 1 else 0;
def flatatclose=if isclosed then 1 else 0;
Then add tradinghours == 1 to your buy_to_open / sell_to_open and flatatclose == 1 to your sell_to_close and buy_to_close
The reason I have it at 1600 is because I don't know what timeframe you are using. If you are using 15 min then you can set both at 1615 however if you're using a 20min, 30min or any timeframe that's not divisible by 15 then it won't close your trades at the end of the day.
I use a 20 min chart and leave it at 1600 for my purposes.
This was really helpful! I modified it a bit to have an input to switch between day session, extended hours session, or both. I also put in a 3 minute buffer for the end of session (rather than to the exact second) which lets it go flat on different timeframes.
input session_type = {default day, extended, both};
input day_session_start = 0930;
input day_session_end = 1600;
#
#############Setting Trading Time############################
#Will allow trading immediately after start, however will not enter if within 3 minutes (180 sec) of end time.
#This 3 minute buffer is because having it exactly to the second of close time resulted in occasional misses.
def daySession=if secondsFromTime(day_session_start)>=0 and secondstillTime(day_session_end) > 180 then 1 else 0;
def extSession1 =if secondsFromTime(day_session_end)>=0 and secondstillTime(2359) >= 0 then 1 else 0;
def extSession2 =if secondsFromTime(0000)>=0 and secondstillTime(day_session_start) > 180 then 1 else 0;
def extSession = extSession1 or extSession2;
def DayisClosed=if secondstillTime(day_session_end)== 0 then 1 else 0;
def ExtisClosed=if secondstillTime(day_session_start)== 0 then 1 else 0;
def session;
def flatatclose;
switch (session_type) {
case day:
session = daySession;
flatatclose = DayisClosed;
case extended:
session = extSession;
flatatclose = ExtisClosed;
case both:
session = daySession or ExtSession;
flatatclose = double.NAN;
}
################################################################
#
AddOrder(OrderType.BUY_AUTO, LongCondition and session == 1, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Enter Long");
AddOrder(OrderType.SELL_AUTO, ShortCondition and session == 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "Enter Short");
AddOrder (OrderType.SELL_TO_CLOSE, flatatclose == 1, tickcolor = GetColor(5), arrowcolor = GetColor(5), name = "Session End Close Long");
AddOrder (OrderType.BUY_TO_CLOSE, flatatclose == 1, tickcolor = GetColor(5), arrowcolor = GetColor(5), name = "Session End Close Short");