Stop executed at close or next open in Rules
Author: Tims
Creation Date: 8/20/2019 8:40 PM
profile picture

Tims

#1
Is there a way with a rules based system to use a stop loss based on the close, that executes on the close or the following open?
profile picture

Eugene

#2
1. So the idea is to execute the stop loss not if the Low price just falls below some level but if the Close price does, right?

2. What is responsible for delaying the exit to "...or the following open"? This sounds ambiguous.
profile picture

Tims

#3
1. The intraday price is what would trigger the stop loss, which we would like to be executed on the close at the close price, but would be satisfied with execution on the following open at the open price.
profile picture

Eugene

#4
QUOTE:
but would be satisfied with execution on the following open at the open price.

Look, the C# language compiler is a soulless beast that is challenging to satisfy. ;) As I fail to see any bit of logic/rules behind this in your description, let's restate my question. What logic may delay the execution until the following open if the condition has been already met on this bar? Please be specific. Alternatively we can drop this delay thing altogether to simplify implementation.
profile picture

Cone

#5
Tims,
If I understand you correctly, you're looking for:
1. a drag and drop rule,
2. that once triggered by intraday price,
3. will sell at the close of the session.

Is that correct?

If it is...
a. would the stop loss trigger price be calculated by an indicator? based on some % deviation from the entry price? something else?
b. Are you testing/trading with intraday or Daily data?
profile picture

Tims

#6
We are using daily data. We use a CMC indicator to act much like a trail stop.
I'm sorry if I confused you at first.
Here's what I want: If the intraday price crosses below the CMC trend line, we want the order executed on the close of that day. I have tried using a 1 day SMA, based on the close, but that is executed the following day at the market. I have considered using the SMA(based on the open, hoping that word allow the order to be executed on the close, it haven't tried it.
To simplify, when the intraday price crosses below the CMC, I want it filled on the close, at the close price. Is this possible without changing to intraday data, which I'm not prepared to do.

Thanks for your patience and your help.
Tims
profile picture

Eugene

#7
Like I suspected, dropping the ambiguous "on the following open" condition helps. I think you've already got everything in place for that:

profile picture

Cone

#8
A couple comments -
1. In Eugene's example, the General Indicator's rule defaults to 20 Percent.. You'd enter 0 for the Percent.

2. Perhaps it doesn't matter for your use case, but the CMC value for the current day would use all of the data for the current bar, which won't be available until the close.. in which case it will be too late to place an order at the close. Anyway, this is the general problem with using AtClose orders on the same bar.
profile picture

Tims

#9
Hello again, Eugene and Cone!
Here's where I think I am with both of your last responses:
Eugene gives me a couple of lines of code that I guess he recommends
for exiting on the close.
Then Cone, you cleverly explain it won't work because the CMC needs the whole bar, so it won't execute on the close.
Honestly, I love you guys, you provide an older man with entertainment, which I need!
I was a licensed CTA(series 3) for 25 years, trading cash currencies in the Interbank market for large institutional clients, plus trading all the commodities in all the NY and Chicago markets . I designed and traded my own systems, a few ok, a lot, not ok.
So, after all that blarney, I still need a little help.
Instead of using the CMC, of which I'm not overly fond of, could I use something like a moving average low band, based on the open? Better yet can you suggest any other trend indicator that would execute on the close? You don't need to worry if it's any good, I'll figure that out.
I'm continuing in this quest, because I REALLY don't want to go back to Tradestation. I know the guy who started it (was Omega then), and he stole my girlfriend.
Winding up(whew), is there a trend indicator I can use that will allow an e execution on the close?

I appreciate both of you taking the time from your hectic days, to humor an old trader.
Goodbye, Tims
profile picture

Eugene

#10
Hi Tim,

Really entertaining :)

Perhaps your expectation was set a bit high, thinking that the "couple lines of code" can save from changing to intraday data for which you're not prepared to. Actually, there's no problem here to execute on the close. Problem is, on Daily data whatever indicator you'd take based on any OHLC (including Open) can only be executed on the next bar. Even though it wouldn't be peeking to know the Open but the deal is that there is no intra-bar processing so to say. The process works as explained by this Wiki FAQ:

Is it necessary to have access to intra-bar tick data to daytrade with Wealth-Lab?

As you asked for a "stop loss on the close", I showed you that. Note that this is only good for backtests because AtClose orders are not supported by the Orders tool. There's a workaround for code-based Strategies which you can find in the WealthScript Programming Guide ("How to: Alert for AtClose Signals").
profile picture

Cone

#11
@Tims
Also note that Rules-based AtClose orders will not give you a trade Alert since they are executed on "bar" (the current bar processed) instead of "bar + 1" (the next, or tomorrow's, bar). No Alert = no trade automation. If you're able to update your Daily data during the market hours (not possible with Fidelity Daily, so you'd need another source like Yahoo!), you could run the strategy near the end of the day, but you'll have to look at the Trades list for Exits for the current day and then manually place those trades.

I don't want to give you the impression that you can't do what you want, but to do it you will need either:

1. An EOD Provider that can update during the day (like Yahoo!, but if you're really trading it, I'd look for a more reliable source), but you'll have to look at the Trades list and manually place orders as described above.

- or -

2. Fully automate the Strategy with using intraday data. This requires you to leave the Strategy Wizard and do some programming, but it won't be difficult and I'd be glad to help!

Finally, Wealth-Lab doesn't have a MOC order TIF, but using intraday data, you can set up the strategy to Stage Market orders 1 to 5 minutes before the closing bell, and then you could manually place all the Market orders, say 10 seconds, before the close.
profile picture

KGo

#12
Know that using "on the close" orders with Fidelity requires that the order be placed no less than 15 min before the close. This means last 15 min of data may not be used to produce that order type.

QUOTE:
you can set up the strategy to Stage Market orders 1 to 5 minutes before the closing bell, and then you could manually place all the Market orders, say 10 seconds, before the close.

This is the best method. However if automation is needed, executing at market 1 to 5 minutes before the close may have little impact on strategy profit for liquid instruments. This can easily be backtested for your strategy trades.
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).