Daily timeframe with intraday stops
Author: Gamba
Creation Date: 3/17/2016 8:34 PM
profile picture

Gamba

#1
I have a simple breakout strategy, which tries to buy at the high of yesterday. I use a BuyStop order for this and then right after the position is entered I try to set a intraday stop value of 0.5%. If stop is not triggered the trade should be closed at the end of the day.

The stop order triggered, but the intraday stop not. The trade is closed at the end of the day.

CODE:
Please log in to see this code.


It doesn't work out for me using daily bars. I know that this is peeking and I only want to use it for backtesting.
profile picture

Eugene

#2
Hi,

Yes, it's peeking and flawed conceptually:

WealthScript Programming Guide > Programming Trading Strategies > Peeking > Trading based on Position Active Status

But this Wiki FAQ has a couple ideas to offer on how to properly handle this scenario:

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

Gamba

#3
Eugene, I don't know the problem with this issue. After looking at the resource the MostProbableAtStop is not the right function to call because I only use long orders. And the priority functions including TimeOfDay-Priority is not needed, because I use only a single stock to test and there is no limit order.

If I examine the daily bar I can see if the high is reached. If not then there is no trade. If so, then I could compute the stop. If the stop is reached then the trade is closed, if not the trade is closed at the end of the day.

I really don't know where the problem of executing is for this setup?
profile picture

Eugene

#4
QUOTE:
If I examine the daily bar I can see if the high is reached. If not then there is no trade. If so, then I could compute the stop.

IMHO, BuyAtStop and SellAtStop can not co-exist on the same bar (just as an *AtLimit) w/o the tricks described. Just give it a thought: you do not know the order of these events just looking at the EOD bar, w/o accompanying intraday data.

You make an assumption that it's the High that gets hit first, and then there may happen the stop loss exit if the price falls 0.5%. What about the other scenario that you don't consider? The price has only touched High[bar-1] (no entry yet), went south 0.5%, then rebounded, pierced your entry level and never came back. In real life you exit at close but your system exits you at an improbable stop loss. Perhaps it's a borderline case but still possible.
profile picture

Gamba

#5
I guess this is what happened in most cases here. Because that is the reason most trades exits at the close.
But it would be clear if all trades exits at the stop ... but only some trades exits at the stop, others exits on the close.

With the described techniques there is no chance to get other results, I tried it.

So I guess the only way to achieve this is to use intraday data?
profile picture

Eugene

#6
I think the problem with the code per se is the syntax error you're making:

CODE:
Please log in to see this code.
profile picture

Gamba

#7
Sorry, copy and paste error, but that doesn't change anything for the results...
profile picture

Eugene

#8
Don't know about your results but in my case there's a reasonable proportion of AtStop exits triggered.
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).