Hi all,
I'm new to Wealth Lab and I hope I'm at the right forum. So basically my question is whether there is a way that I can buy a stock using a trailing stop. I see a Sell trailing stop (percent or $ amount) but I don't see the corresponding one for a Buy order using the Rules. I looked at the QuickRef for coding and I can't find one under Trading neither. Is this function hidden somewhere? Can someone point me to the right direction?
I'm using Fidelity Wealth-Lab Pro 5.6 by the way.
Thanks.
fix
Size:
Color:
Hi Felix,
A Sell trailing stop trails some amount below the highest high achieved since the position was opened. A trailing entry of this kind should be programmed manually, i.e. you need to define the point (price) from which to "trail".
For example, here's a trailing stop entry once the price rises 5% from the bar #0's low:
CODE:
Please log in to see this code.
Size:
Color:
Thanks Eugene! I guess without a trailing stop, I'd have to write some code. I was hoping that it just works like a real trailing stop where the entry price goes down as the stock price go down, so I ended up having to do this.
CODE:
Please log in to see this code.
I was going to take advantage of the free iShare trades and trying to put some of my free cash in TIP/MUB (yield 2-3%) instead of the money market fund (yield 0.09%) without losing too much, and hence the above 0.5% trailing stop. Turns out I haven't found the right strategy yet - I'll need to play a little more with WealthLab. WealthLab has been fun so far.
Size:
Color:
Coding it like that raises an issue of peeking into the future. One can't know for sure which event happened first on a particular bar: the exit or the entry. So, you can't base a buy stop order on the knowledge that a Position has been exited on the same bar, because the order of these events is unknown without looking at intra-bar data.
Size:
Color:
Right, it's looking at one bar at a time and could have "bought" when the stop hasn't been met in reality. So if that's the case, does that mean I have to basically switch to an intraday scale to make it work the way I wanted it to be? I tried the 15-min scale and it looked to be working my way. Thanks!
Size:
Color:
The problem is a general one when executing the TrailingStop and the BuyAtStop on the the same bar. It's possible that in some cases the code will execute as it would occur in real life, and in others it will not because of the lack of granularity in the data - even if using 1 minute bars.
For example, let's say that the next bar's range goes from 99.00 to 101.00 and opens at 100.00. For simplicity, let's say the current bar's high, low, and close is 100.00, so your trail is 99.5. When the next bar opens at 100, let's say it goes to 101 first and then drops to 99 and closes there. The trail would be executed at 99.5, no problem. However, your logic will also execute the BuyAtStop, which could have only been possible if price exceeded 99.5 after your sale - but, in our example that didn't happen.
Consequently, in backtesting, you can execute a reverse order on the same bar only if the signals would trigger simultaneously in real life - for example, a BuyAtStop and SellAtLimit. Even in this case, since a Stop executes at market when the trigger price is reached, you'd need to use at least one "tick" of Limit order slippage to reasonablye guarantee that the limit order would have executed as well.
Size:
Color:
All right, it kind of make sense now. I was trying to sell then buy in the same bar because my stop is pretty low (0.5%), and I saw in a few instances right after the system sold, the ETF I was using (TIP) gapped up and the system did a buy stop at a much higher price. Thanks to both of you for your guidance.
Size:
Color: