SellAtClose and Time In Force
Author: thodder
Creation Date: 1/11/2010 10:01 AM
profile picture

thodder

#1
I am not a fan of using SellAtClose with strategies that will trade on a live account; however, I am working with some other investors that would like to place an order with a time in force of on market close. They believe this method will do that. I do not. According to the documentation, SellAtClose:
QUOTE:
Sells the Position specified in the pos parameter at the specified bar, using the closing price of the bar as the exit price

It does not say anything about setting the time in force. Am I correct that this will not set the time in force to on market close with a strategy run with a scale of daily?

Is there a way to set the time in force to trade on the market close within a strategy?
profile picture

Cone

#2
User Guide: Orders > Features and Limitations of Automated Trading > Limitations: AtClose Orders
AtClose Orders are not supported by the Orders tool. See How to: Alert for AtClose Signals in the WealthScript Programming Guide.

Follow that link to see how to use a Market Order (at 15:59) to sell near the close. But the take-away is Wealth-Lab does not support AtClose orders at all for live trading.
profile picture

thodder

#3
Thanks Cone! You reinforced my opinion that AtClose needs to be used carefully. Okay for backtesting, but it's use ends there.
profile picture

thodder

#4
Cone,

Do you know if there is any way to set the Time in Force within the strategy? It would be nice to have the capability to set 'On Market Close' and 'Good til Cancel' orders within a strategy.

Tim
profile picture

Cone

#5
Time in Force and GTC = execute the trading signal until you don't want to execute it anymore. Isn't this clear? In other words, a BuyAtLimit, for example, is GTC as long as you keep executing the BuyAtLimit on successive bars. It's "canceled" when you no longer execute BuyAtLimit.
profile picture

thodder

#6
Are orders submitted as day or GTC orders? You state:

QUOTE:
a BuyAtLimit... is GTC as long as you keep executing the BuyAtLimit on successive bars


What if the bars are weekly bars? Will the order be valid all week or cancelled by the broker at the end of the first trading day (i.e. day orders).

As an example for GTC, what if I decide to run a strategy with a scale of weekly to place stop and limit orders for the week. This strategy would only be run on the weekends to generate orders that needed to remain active for the week until they were executed or cancelled.

An example of "On Market Close" would be if I had a strategy that runs on a daily scale which I ran every night. I may decide that I want to sell the order at the close of the following day, but I won't have WLP running all day long (intraday) to submit an order during the last few minutes of the trading day. For someone that works during the day but moonlights as a swing trader, this could be a valid request.

Another example of "On Market Close" is to handle shortened trading days when the market closes at 1pm EST. I'd hate to write a strategy with a hard-coded 15:59 as a time to exit a position and end up leaving the position open at the end of the day because it never hit that time.

I'm not saying this is the typical use of WLP, but it seems like a valid request to me.
profile picture

thodder

#7
Btw, I am clear that my strategy should keep executing BuyAtLimit on successive bars to keep it active. I've seen it with forward testing on a paper account; although I am a little unclear how this would work if auto trading was turned off with a live account. Fidelity has some extra hoops you have to jump through to allow auto trading on a live account, so I try to design my strategies to run with or without auto trading.

If I stop executing BuyAtLimit on successive bars with a strategy run using an intraday scale with auto trade off, will I get an alert to cancel the order? If I remember right, I get an alert on each bar and I would just have to be aware that an alert did NOT get generated to know that I had to manually cancel the order. There might be something in the help that I missed to better understand this.

At the moment I am planning that intraday strategies should have auto trading on, but daily scale strategies could run manually (assuming TIF = day order).
profile picture

Cone

#8
QUOTE:
What if the bars are weekly bars?
User Guide: Preferences > Trading...
Important!
Trading Alerts by Strategies using weekly, monthly, or larger scales are placed as Good Til Canceled (GTC).

QUOTE:
An example of "On Market Close"...
You use-case is not supported by Wealth-Lab. If AT Pro or fidelity.com supports it, then you'll have to do it there.


QUOTE:
Another example of "On Market Close" is to handle shortened trading days
Don't hard code it. Parse the Markets.xml file to determine if you're trading a short day. That's probably overboard anyway. Since you know when a short day will occur in advance, it would be easy to change your hard-coded time for that day.

QUOTE:
If I stop executing BuyAtLimit on successive bars with a strategy run using an intraday scale with auto trade off, will I get an alert to cancel the order?
If you're not on Auto, it's manual. You have to cancel the orders (or cancel/replace) manually (except at the end of the day).
profile picture

Eugene

#9
QUOTE:
Parse the Markets.xml file to determine if you're trading a short day.

A shortcut (pun intended): Shortened Sessions
profile picture

thodder

#10
Thanks Eugene and Cone!

I had a feeling I missed a few details in the help. I appreciate you pointing it out.

I had already put together something for getting the market close time; although I might look at the Shortened Sessions to see if I could make it easier. Basically I created the following method:
CODE:
Please log in to see this code.


At some point during testing with WLP 5.5, I thought I got exceptions accessing Bars.MarketInfo, so I tried to make it as safe as possible. I was never able to isolate the exception.

My thought for handling "On Market Close" would be to do special processing in an intraday strategy with the code:
CODE:
Please log in to see this code.


I think I'm on the same page as you guys for special processing near market close.

As always, I appreciate your help.
profile picture

Eugene

#11
QUOTE:
although I might look at the Shortened Sessions to see if I could make it easier.

It should be a bit terse. I like your approach, just not sure if MarketInfo was a later addition (5.3?) or have always been there.
profile picture

thodder

#12
I noticed Bars.MarketInfo in WLP 5.5. I don't know if it was available in an earlier release or not. It still appears to be undocumented in WLP 5.6.

I discussed it in an earlier post (/Forum/Posts/BarsMarketInfo-29890) when my main concern was whether this property would remain in the api since it is not documented. I hope it will. It is much better to use Bars.MarketInfo instead of parsing Markets.xml whenever I need to check it.
profile picture

thodder

#13
I had a support ticket for documenting Bars.MarketInfo. It is closed now stating that it is documented at: http://personal.fidelity.com/products/trading/Trading_Platforms_Tools/wlp-under-the-hood.shtml. I could not find Bars.MarketInfo in any of those pdfs. Could you tell me exactly where it is supposed to be documented?
profile picture

Eugene

#14
It's missing. Sorry for the inconvenience.
profile picture

thodder

#15
Thanks Eugene

No problem. Can the support ticket be reopened so we can follow it?
profile picture

Eugene

#16
Thanks Tim, no such need. The Bars.MarketInfo class will be documented in the QuickRef.
profile picture

thodder

#17
So it is expected to be documented with the next release of WLP? That's fine.

profile picture

Eugene

#18
Yes, I'll be adding the MarketInfo class to the QuickRef for the next release.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).