Limit/Stop[bar+1] alerts not triggered after market hours
Author: kbellare
Creation Date: 12/6/2013 5:00 PM
profile picture

kbellare

#1
I'm runnning a strategy (on Daily, top 100 ETFs) that Buy[bar] on Yahoo partial bar during market hours (just before close) and places SellAtStop[bar+1, StopPrice] and SellAtLimit[bar+,ProfitTarget] orders (code below - i have changed BuyAtClose to BuyAtMarket in the StrategyMonitor version of code)

I ran the Strategy Monitor (with Auto-Stage) at 3:30pm ET, which triggered an alert and staged a Buy order, which i manually filled.
However, when i ran the StrategyMonitor after-hours (4:30pm ET), it did not trigger the SellAtLimit(profit target) alert. I did log into Fidelity account ..

1) How do i fix this? When does the StrategyMonitor know that the position is active - Is it as soon as it stages the order or does it retrieve the positions every time it runs the strategy?

2) Can i somehow place the Limit (Profit-target) and Stop(Stop-loss) orders during market hours along with the Buy order (similar to an OCO order that brokerages offer)? That solves 2 issues
2a) Protects me if the market tanks in the same bar as the Stop is in place
2b) Prevents me from running the StrategyMonitor twice each day.


CODE:
Please log in to see this code.


Thanks,
Kiran
profile picture

Eugene

#2
Before we begin, first I'd like to know why would you want to run the SM after-hours?
profile picture

kbellare

#3
Because the Stop(bar+1) and Limit(bar+1) alerts didn't trigger when i was running during market hours (at bar), I ran it a second time after-hours thinking the system would be at "bar+1" stage after-hours. I inferred that the problem with running it again on the 2nd day during market hours is that "Tomorrow never comes" - it would now be at the next "bar" and bar+1 will never arrive.

- Pl advise how i can make the Stop(bar+1) and Limit(bar+1) signals trigger, ideally at the same partial bar when i enter a position, so i can place an OCO order.

-> Here's my code for trying to use the same strategy code for backtesting and simulation during and after market hours. Note -
1) I use my PC time-of-day to drive my logic for Alerts vs Backtesting
2) Also have binary Strategy Parameter called SameDayEntry and SameDayExit to optimize and test whether partial bar vs next day execution yields better results

CODE:
Please log in to see this code.

profile picture

Eugene

#4
QUOTE:
- Pl advise how i can make the Stop(bar+1) and Limit(bar+1) signals trigger, ideally at the same partial bar when i enter a position, so i can place an OCO order.


Please see the FAQ: I want to test a strategy that buys and sells with stop/limit orders on the same bar. Got nothing else to comment.

QUOTE:
1) How do i fix this? When does the StrategyMonitor know that the position is active - Is it as soon as it stages the order or does it retrieve the positions every time it runs the strategy?


I haven't tried it, and have no idea if this would work. To adjust the default market hours, launch a text editor with elevated privileges by right-clicking its shortcut and selecting "Run as admin" and manually edit the Open and Close Market hours in the ..\Data\Markets.xml file beneath Wealth-Lab's main program directory under Program Files (or Program Files(x86), only when using 32-bit WLP on 64-bit Windows).

Good luck with entering the unsupported territory with this tweak, as this is likely to break some assumptions of Fidelity's data and/or broker providers.
profile picture

kbellare

#5
Hi Eugene,

My question is quite basic - i have SellAtLimit(bar+1) order set up in my strategy, but it doesn't generate an Alert even though it has generated the corresponding Buy Alert, Auto-Staged and Placed an order.

The User Manual->Orders->Features says "Bracketed Exit Orders - Bracket trading is supported when Auto-Trading as well as for manual-order entry. Stop and limit orders for the same instrument can co-exist simultaneously. When one order is executed, the Order Manager cancels the other order automatically, i.e., one cancels other (OCO). "

- Is there some setting to ensure my SellAtLimit signal trigger an Alert when the corresponding Buy Alert is triggered, staged and placed? (During backtesting, the SellAtLimit(bar+1) generates accurate signals that result in trades.)

thanks
Kiran
profile picture

Eugene

#6
Hi Kiran,

Your question would be "quite basic" if your scheme was standard and did not involve trading on the partial bar as if it was already closed, mid-day Close using EOD data and so on. Supported are Daily Strategy Scheduling in the SM and GetSessionOpen. Trying to treat what actually is an intraday strategy (because of Stop/Limit orders on the same bar and mid-day close) as Daily is not supported. Throwing in Stop/Limit orders for bar+1 after having placed an entry order near the close of this bar just adds more confusion.

Please count me out for the rest of this discussion since the methods used deviate from standards.

P.S. As for placing the Limit and Stop orders during market hours along with the Buy order, this is explained in the User Guide > Preferences > Trading > Allow Same Bar Exits for Auto-Trading. The code your posted does not satisfy the Checklist for enabling stop and limit exits on the entry bar there because RiskStopLevel and AutoProfitLevel haven't been assigned.
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).