NexusFi: Find Your Edge


Home Menu

 





Possible to set "strategies" to only trade during NY session?


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one kjhosken with 1 posts (1 thanks)
    2. looks_two bobbydigital83 with 1 posts (0 thanks)
    3. looks_3 Massive l with 1 posts (4 thanks)
    4. looks_4 Captain135 with 1 posts (1 thanks)
      Best Posters
    1. looks_one Massive l with 4 thanks per post
    2. looks_two kjhosken with 1 thanks per post
    3. looks_3 barabas with 1 thanks per post
    4. looks_4 Captain135 with 1 thanks per post
    1. trending_up 4,622 views
    2. thumb_up 7 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Possible to set "strategies" to only trade during NY session?

  #1 (permalink)
 bobbydigital83 
San Francisco Ca/USA
 
Experience: Advanced
Platform: tos
Trading: es
Posts: 29 since Jan 2019
Thanks Given: 12
Thanks Received: 7

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.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
60 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #2 (permalink)
 
barabas's Avatar
 barabas 
Chicago IL USA
 
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation
Trading: ES,NQ, CL
Posts: 111 since Feb 2019
Thanks Given: 105
Thanks Received: 173

I believe there are two ways of doing this.

One way is just to take off the Extended hours of trading under chart settings.- under futures or stock chart.

The other way is thru coding. Which I dont know how but I have one studies that does have it so I know you can..

Regards

Reply With Quote
Thanked by:
  #3 (permalink)
 kjhosken 
Seattle, WA/USA
 
Experience: Intermediate
Platform: TOS, TS
Trading: Forex, crude
Posts: 96 since Sep 2016
Thanks Given: 7
Thanks Received: 35



bobbydigital83 View Post
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.

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):
 
Code
input rthstart = 930;
input rthend = 1600;
def rth = if (secondstilltime(rthstart)<=0) and (secondstilltime(rthend) >=0) then 1 else 0;
def buysignal = *stuff*
AddOrder(OrderType.BUY_AUTO, *stuff* and rth == 1, *order price if specified*, *# contracts if specified*, Color.ORANGE, Color.ORANGE, "BTFD ");
AddOrder(OrderType.Sell_To_close, rth == 0, close, *# contracts if specified*, Color.ORANGE, Color.ORANGE, "EOD_Exit");

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
 
Massive l's Avatar
 Massive l 
OR/USA
Legendary /NQ Trader
 
Experience: None
Posts: 2,129 since Mar 2011
Thanks Given: 1,859
Thanks Received: 5,106

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.

 
Code
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;

AddOrder(OrderType.BUY_TO_OPEN, ratio > 1 and avg > 1 and ratio < 1.2 and tradinghours==1 , open[-1], 2, Color.green, Color.green, name = "______" );

AddOrder(OrderType.SELL_TO_CLOSE, ratio < .9  or ratio > 1.3  or flatatclose==1 , close[0], 1, Color.white, Color.white, name = "______" );

AddOrder(OrderType.SELL_TO_OPEN, ratio < 1 and avg < 1 and ratio > .8 and tradinghours==1, open[-1], 2, Color.red, Color.red, name = "______" );

AddOrder(OrderType.BUY_TO_CLOSE, ratio > 1.1  or ratio <= .7  or flatatclose==1 , close[0],1, Color.white, Color.white, name = "______"  );

Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 Captain135 
Bay Area, CA
 
Experience: Intermediate
Platform: TradeStation, TOS
Trading: Futures, Equities, Options on Futures
Posts: 48 since Feb 2017
Thanks Given: 53
Thanks Received: 30


Massive l View Post
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.

 
Code
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;

AddOrder(OrderType.BUY_TO_OPEN, ratio > 1 and avg > 1 and ratio < 1.2 and tradinghours==1 , open[-1], 2, Color.green, Color.green, name = "______" );

AddOrder(OrderType.SELL_TO_CLOSE, ratio < .9  or ratio > 1.3  or flatatclose==1 , close[0], 1, Color.white, Color.white, name = "______" );

AddOrder(OrderType.SELL_TO_OPEN, ratio < 1 and avg < 1 and ratio > .8 and tradinghours==1, open[-1], 2, Color.red, Color.red, name = "______" );

AddOrder(OrderType.BUY_TO_CLOSE, ratio > 1.1  or ratio <= .7  or flatatclose==1 , close[0],1, Color.white, Color.white, name = "______"  );


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.

 
Code
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");

Reply With Quote
Thanked by:




Last Updated on April 29, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts