Exit, then potentially re-entry on same bar
Author: 123blee9
Creation Date: 8/5/2017 7:16 PM
profile picture

123blee9

#1
I've written a strategy that allows for potential position re-entry after an exit on the same bar if certain conditions are met. I plan to auto-trade this strategy intraday (I recently was approved for auto-trading). Given the re-entry is of the form "BuyAtLimit(bar, ......), I don't think the long entry buy limit order will "fire" when the appropriate conditions are met, as it's based on the current bar.

1) Is my assumption correct?

2) If so, is there a way to code WLP such that it achieves my objective of potential same bar re-entry after an exit occurs on the same bar when auto-trading? The BuyAtLimit conditions are based on "prior day" known values as compared to price action on the current intraday bar after an exit occurs on that same intraday bar.
profile picture

Eugene

#2
Since this was discussed many times before, answer has been added to the FAQ:

I want to test a strategy that buys and sells with stop/limit orders on the same bar.

Re: BuyAtLimit(bar. Of course you wanted to say BuyAtLimit(bar+1? Because otherwise it would suffer from a peeking error and not trigger Alerts.
profile picture

123blee9

#3
In my particular case, there is no peeking as the condition to SellAtMarket is based on the Opening price for the day. In other words, it the position is closed at the day's opening bell as based off the day's opening price, I wish to enter a BuyAtLimit order immediately. The code works fine on backtests, I'm concerned about how to implement it, if possible, in auto-trading. Would a BuyAtMarket[ bar, ......] order work in auto-trading if I test whether the buy limit condition is satisfied within my bar loop?

Since this is a BuyAtLimit order entry conditional on the day's opening price (Is the current long position closed at the opening bell?), I can just use 1-minute bars with BuyAtLimit[ bar+1, ...] . My analysis was originally performed on 60-minute bars.
profile picture

Eugene

#4
QUOTE:
Would a BuyAtMarket[ bar, ......] order work in auto-trading if I test whether the buy limit condition is satisfied within my bar loop?

Not for auto-trading. A trading Alert will not be generated on the BuyAtMarket(bar). To stress this again, you have to use bar+1 if you plan to get Alerts.

QUOTE:
Since this is a BuyAtLimit order entry conditional on the day's opening price (Is the current long position closed at the opening bell?), I can just use 1-minute bars with BuyAtLimit[ bar+1, ...] . My analysis was originally performed on 60-minute bars.

That's a solution. If you can just use intraday data instead of EOD then no problem. You can generate *AtLimit Alerts using bar+1 on intraday bar scales without peeking or the .Priority workaround.
profile picture

Cone

#5
I think I understand the motivation. A dip-buying band strategy may alert to sell at market, but the open of the next bar is so low that it immediately reenters a new position (generally for more shares at a lower price for % of Equity sizing). Selling and then buying the position back serves only to pay a round-trip in commissions.

How you solve this depends on your data feed and broker. For example, stocks that are gapping down into band-buying territory are usually very active in the premarket. If you have a streaming feed like IQFeed, you could stage your market orders and load the limit orders in the Quotes tool. If one of your limit orders is triggering before 0930, just don't Place either order. (You'd probably need to adjust the Market times for IQFeed in the Market Manager for that to work.)

If you're with Fidelity, streaming to WL Pro won't start until the opening so you'll need an external source - maybe you can use a filter in ATPro to find if your stocks are gapping down.

Also, if you're like me, you will place market-on-open orders to participate in the primary market's open. This must be done at least 10 minutes before the NYSE open (2 minutes before for Nasdaq I think). If you enter orders this way, you cannot cancel or change a MOO order once it's accepted. In this case, you simply have to accept the round trip commission when it happens.
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).