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 -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am trying to write some code to exit a trade at the close of the last day of the week.
Generally that will be Friday, but if that is a holiday then it could be Thur, Weds, etc.
I planned to check for this using if... else statements, but when I do, I find that it automatically matches (sells) the earliest day (Weds in this example) when say Friday or Thurs is the last day in the week.
Can you help answer these questions from other members on NexusFi?
could you describe in your own words what the expression "DayOfWeek(Date of Tomorrow) = 4" should do?
In my opinion your best bet is creating a holiday list that you can use to detect if the following day is a holiday or a weekend and in that case
trigger the end of day exit today already.
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,388
Thanks Received: 10,207
I'm not familiar with (Date of Tomorrow) but clearly from what you've said it's using a regular calendar and not a trading day calendar.
Also while I believe SetExitOnClose works well with backtesting, I don't believe it works with live trading unless your using custom sessions. I think that what happens is that when the market closes Tradestation sends the order, which gets rejected, because ... the market is closed!
DayOfWeek(Date of Tomorrow) is a function to return a value for which day of the week it is. 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday.
Rethinking this - I can test to see if "Tomorrow" is a new week, but then I would need to close out the end of that current day. Is there a way to do this?
the reason for my question was to find out what you intend the code to do when you say DayOfWeek(Date of Tomorrow) = 4 - you are basically asking for an exit if tomorrow is a Thursday, which could be true on any Wednesday. Similar for "DayOfWeek(Date of Tomorrow) = 3".
I would suggest looking into using a holiday list and as @SMCJB mentioned it can make sense to replace SetExitOnClose with an actual order statement.
Regards,
ABCTG
CreativelyChris
DayOfWeek(Date of Tomorrow) is a function to return a value for which day of the week it is. 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday.
Rethinking this - I can test to see if "Tomorrow" is a new week, but then I would need to close out the end of that current day. Is there a way to do this?
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,388
Thanks Received: 10,207
@CreativelyChris I think you will find, that if today is Thursday and tomorrow is a Holiday, DayOfWeek(Date of Tomorrow) is still going to return 5 or Friday. It's not going to return 1 or Monday. It's using a calendar day calendar not a trading calendar.