StopTrail(Limit)
-
Use the link below to go the original post
Click here to see the full blog post
-
Many thanks DRo :D
-
Hi, thanks for the post. I realize this is an old post, but I like to clarify something. In an "ideal" back test, my traillig stop orders are based off high for each trading day for a buy (long) position, and off the low of the day for sell (short) postion. So, the trailing stop orders are updated each day after the close based on the highs and lows reached. If the next day, the low is below the trailing stop order, the long trade is closed for the day at the traling stop limit price, neglecting slippage. I see your example here all trail stops are based off the close, is there a way that I can impliment my way of testing? Can I choose the data set that the trailing stop orders are adjusted and executed based on? thanks.
-
@michael172 said in StopTrail(Limit):
I see your example here all trail stops are based off the close
The trail stops are based off the latest available data point. Which when looking at a bar is the
close
. But when you have live data it will be the last incoming tick.@michael172 said in StopTrail(Limit):
Can I choose the data set that the trailing stop orders are adjusted and executed based on?
The functioning of the
StopTrail
order simulate what actual brokers offer. Your custom behavior has to be manually coded. -
@backtrader Thanks for the quick reply. I understand what you are saying. It would be nice if I had intrady data when I do my backtest, then this wold work perfectly with data playback. Unfortunatly, I only have access to Open, High, Low, Close data, so I'll have to dig around to see if there is a sample code that does what I need or god forbid... have to write my own... :)
-
@backtrader I have the same question as @Michael172.
For a long trade with a trailing stop, the stop price should be based off the
high
and not theclose
for the normal implementation.For example if my trailing stop is set to
trailamount=20
, if the high bar has aclose
of 2800, and ahigh
of 2810, the stop price should be 2790. That's how IB implements a trailing stop.Why is the trailing stop based off
close
and is there a way to change it? -
@algoguy235 said in StopTrail(Limit):
@backtrader I have the same question as @Michael172.
No you don't. His question is about a specific approach to the market he has and you claim that Interactive Brokers is doing something ... but this isn't actually the case.
@algoguy235 said in StopTrail(Limit):
Why is the trailing stop based off close
It is not. Please read again the description of the functionality and the answer given above.
@algoguy235 said in StopTrail(Limit):
For example if my trailing stop is set to trailamount=20, if the high bar has a close of 2800, and a high of 2810, the stop price should be 2790. That's how IB implements a trailing stop.
This is plainly WRONG.
IB uses the LAST available price to calculate the stop. If it used the
high
it could be using a price which is very OLD and miles away from the current LAST price. This could lead to immediate execution of theStop
, which would make the trailing functionality *pointlessEven if it seems incredible, the LAST price is always the CLOSE price. In most cases it is just a temporary
close
because the current bar isn't closed. It can of course be the LAST, the CLOSE and the HIGH, all at the same time (and even the OPEN and LOW if one is operating only withticks
)