NexusFi: Find Your Edge


Home Menu

 





Exit Trade on Close at End of Week?


Discussion in EasyLanguage Programming

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




 
Search this Thread

Exit Trade on Close at End of Week?

  #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?
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
Quantum physics & Trading dynamics
The Elite Circle
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

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 Twitter Reply With Quote
  #3 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
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!

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,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

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 Twitter Reply With Quote
Thanked by:
  #6 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
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.

Reply With Quote




Last Updated on October 18, 2021


© 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