NexusFi: Find Your Edge


Home Menu

 





Exit Trade on Close at End of Week?


Discussion in EasyLanguage Programming

Updated
    1. trending_up 4,773 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
CreativelyChris
Los Angeles, CA
 
Posts: 13 since Sep 2021
Thanks Given: 1
Thanks Received: 0

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.

 
Code
if DayOfWeek(Date of Tomorrow) = 5 Then
	SetExitOnClose
Else if DayOfWeek(Date of Tomorrow) = 4 Then
	setExitOnClose
Else if DayOfWeek(Date of Tomorrow) = 3 Then
	setExitOnClose;


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The 50/50 Paradox: Peace and Invasion Each at 20% -- Ira …
Prediction Markets & Event Contracts
Sundays Verdict: Lebanon Locked at 99.85% as Iran June 7 …
Prediction Markets & Event Contracts
Day 96 Missiles Hit Kuwait and Bahrain: June 15 Peace at …
Prediction Markets & Event Contracts
Fabrication or Framework? Irans Denied MOU Explains the …
Prediction Markets & Event Contracts
Al Arabiya: US-Iran Draft Deal Within Hours Contains Hor …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
BERN ALGOS algo trading journal
8 thanks
Volume Indicators
8 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

CreativelyChris,

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.

Regards,

ABCTG



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

 
Code
if DayOfWeek(Date of Tomorrow) = 5 Then
	SetExitOnClose
Else if DayOfWeek(Date of Tomorrow) = 4 Then
	setExitOnClose
Else if DayOfWeek(Date of Tomorrow) = 3 Then
	setExitOnClose;


Follow me on X Reply With Quote
  #3 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT Stellar & Tradestation
Broker: Primarily Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,241 since Dec 2013
Thanks Given: 4,585
Thanks Received: 10,531


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!


Reply With Quote
  #4 (permalink)
CreativelyChris
Los Angeles, CA
 
Posts: 13 since Sep 2021
Thanks Given: 1
Thanks Received: 0

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?


Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

CreativelyChris,

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 View Post
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?


Follow me on X Reply With Quote
Thanked by:
  #6 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT Stellar & Tradestation
Broker: Primarily Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,241 since Dec 2013
Thanks Given: 4,585
Thanks Received: 10,531

@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.


Reply With Quote




Last Updated on October 18, 2021


© 2026 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 - Downloads - Top
no new posts