Buy at close and sell next open - held 3 bars?
Author: aaa30040
Creation Date: 1/7/2015 4:28 PM
profile picture

aaa30040

#1
I'm using wealth lab for first time today and have no background in programming. My first attempt at making a test system is just to buy at the close and sell the next open - just as a test.

Using drag and drop rules on daily data of:

Buy at Close
Sell at Market
if current open position is older than number of bars 0

then tried it with a value of 1 bar

both result in trades held three days

What am I doing wrong?
profile picture

Eugene

#2
QUOTE:
both result in trades held three days

That's not entirely correct. With this [excessive] condition (set to 0) or without it, trades are held for only a single bar. When set to 1 bar, trades are held for 3 bars but that's explained in the User Guide (Preferences > Performance Visualizers > Trades):

Both the entry and exit bars count in "Bars Held". For example, a Position that's exited on the next bar after entry is considered to have been held for 2 bars - instead of 1, like in Wealth-Lab Version 4. The new method gives the performance report the most pessimistic "profit per bar" rating possible.
profile picture

aaa30040

#3
Ok, so I took out the excessive condition and now just have:

Buy at Close
Sell at Market

and the positions are still held three bars. Or is there a different way to use drag and drop to buy the close and sell the next open?
profile picture

Eugene

#4
Sorry, I used BuyAtMarket/SellAtClose to arrive at 1 bar. There's a workaround to do what you want using Rules: under Position Management groupbox, switch to "Multiple open positions allowed". This will result in positions being held for 2 bars which is perfectly correct with regard to my explanation above.

P.S. As an alternative, use this code:
CODE:
Please log in to see this code.
profile picture

aaa30040

#5
Thanks - that does it
profile picture

gtg907g

#6
I'm struggling with this issue using rules and even with modifying the code after using rules to build it. I don't really understand why in the world you would count entry and exit bars in bars held as the default. Yes it produces a more pessimistic estimate rating for profits for bars, but does it not also produce a 100% chance of any estimate (for anything) being incorrect for a system that employs an exit strategy on the next bar / one bar hold?? It seems to simply delay everything until the next bar, which completely blows up any trading system that uses a conditional exit that might trigger on the next bar (especially "on the open" exits, like mine).

How can I actually employ an exit strategy that exits simply on the next profitable open (literally if the open means the position is profitable). To be more clear - my example is on daily bars; if today the price closes at 24.50 and I buy tomorrow using a buy stop at say 25 bucks (at the time I buy, I put say a -6% hard sell stop in place) and the next day it opens at 25.10, how can I use rules (or even what kind of code is there) to build an exit strategy to get me out at 25.10 instead of delaying until the next following day.

Thx for the help on this - I'm willing to bet I'm just not doing it right.

Peter
profile picture

Eugene

#7
Simply put, alerts in Wealth-Lab have to be produced beforehand. One issues an alert after the market close "today" without knowing whether the system is still going to be in the green at "tomorrow's" (unknown) open price. So the correct way is to say "exit on the next open if system is profitable at the current bar's close".

An alternative may be to use GetSessionOpen which returns current trading session's opening price for the specifed symbol after market open. I came up with a quick example code that has two modes that you can control via a parameter slider: use GetSessionOpen (0,1). If it's set to 1, run your Strategy window shortly after open to let it obtain the current trading session's opening price and decide if it's still profitable or not. If not, it should wait for the stop loss to trigger. And "Exit after" is the number of bars to exit after a Position is established.

CODE:
Please log in to see this code.


Without some tweaking, Rules cannot be used to create a Strategy of this design.
profile picture

Cone

#8
Maybe Eugene's answer is closer to what you actually want, but to give you what I think you asked for, you can exit for "a profit" (or better on an opening gap) by simply using a limit order with a trigger price 1 penny above the entry price. With $0 commissions, even 1 penny is a profit nowadays... and you should get price improvement (likely, but not guaranteed in live trading) if the market opens trading above your sell limit price.

CODE:
Please log in to see this code.


Of course, if you're using EOD bars, this limit order will be live with a Day TIF. You can make it valid for just the first minute of trade by using 1 minute bars and a little extra code.
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).