SellAtStop and BuyAtStop work differently when Bid/Ask spread is wider than 1 tick
Author: aykuts
Creation Date: 4/2/2014 2:31 AM
profile picture

aykuts

#1
Hi,

In Turkey, there are certain stocks that trade with wider spread between Bid and Ask.

As one example, HALKB ticker is typically quoted as 10.00 / 10.05 during the day.

So, in a bid to capture this wider bid/ask spread in my strategy, I use:

CODE:
Please log in to see this code.


Interestingly however, these two identical order types (as per Quickref documentation) yield different Buy (And Sell) levels when used within the strategy.

If we continue from the same example:
* This code BUYS at 10.05 (when BUY signal is 10.00 TL) => Great, fine!
* This code however sells at 9.99 TL (when SELL signal is 10.00 TL) =>Wrong?!

This problem involves one hidden and very dangerous issue (other than the loss of just one-tick while selling the stock)

In fact, when the SELL price is calculated at 9.99 by the code:
- the strategy will execute this order ONLY WHEN the price AT NEXT BAR hovers around 9.95 / 10.00 (so that the code that can execute this SELL order at 9.99)
- that means, the code will execute this order ONLY WHEN it checks the NEXT BAR FIRST and sees if the price is moving down at the next bar
- So, that is front running (i.e. looking forward to next bar if the price falls, and, then, executing the order at 9.99 while the current bar price is 10.05 / 10.00.)

**

* Why is the calculation methodology between BuyAtStop and SellAtStop are different?
* Any remedies to prevent this `implicit` front running of the code?

Thanks in advance for your time and consideration,

Aykut Saribiyik




profile picture

Eugene

#2
There's no difference between *AtStop with regard to tick handling.

1. What were the OHLC for bar and bar+1?
2. Or better, can you demonstrate what you're experiencing using some Yahoo! symbol as example? We may need to see how exactly is your code producing the orders (e.g. same bar, etc.)
profile picture

Cone

#3
The difference is likely due to:
a) the precision of the data (remember that you're seeing rounding pricing to 2 decimals)
b) the rounding effect (ceiling/floor) of stop/limit orders for stocks to 2 decimals (default), which can be changed in Preferences > Advanced Settings > Pricing Decimal places.

Basically, if you enable Preferences > Backtest Settings > Turn off limit/stop rounding entirely, you'll probably see what you expect.
profile picture

aykuts

#4
Hi,

I checked each trade one by one, and i think you are right: Most of the trades are sold at stop at a price one tick below the StopPrice, just because the round of the calculated StopLevel falls below the targeted StopPrice.

Thanks once again for your valuable help.

Aykut
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).