Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the PriceType of tailing stop trades? #25

Closed
none2003 opened this issue Jun 3, 2023 · 1 comment
Closed

What is the PriceType of tailing stop trades? #25

none2003 opened this issue Jun 3, 2023 · 1 comment

Comments

@none2003
Copy link

none2003 commented Jun 3, 2023

I guess the PriceType is MIDDLE, based on

When liquidated, the shares are sold at market price equal to ExecContext.sell_fill_price, which is configurable and defaults to the midpoint between the bar’s open and close price.

But the definition of MIDDLE is:

Midpoint between low price and high price of the current bar.

There is a discrepancy between these two. So the question is, what is the PriceType of tailing stop trades?

Is it possible to set a particular PriceType for trailing stop? Currently, it gives following error:

ValueError: sell_shares or hold_bars must be set when sell_fill_price is set.

@edtechre
Copy link
Owner

edtechre commented Jun 3, 2023

Hi @none2003,

Thanks for catching this! The notebook is incorrect, the MIDDLE type is the midpoint between the low and high price. I have updated the notebook.

A trailing stop does not use MIDDLE. It is filled at the stop threshold, e.g. if the stop is hit at $99, then the fill price will be $99. The low price is used to test whether the stop is hit for long positions, and high for short:

if low <= self._stop_data[stop.id].value:
        return self._stop_data[stop.id].value  # fill price

This is not configurable via sell_fill_price. If you need greater control over how the stop is filled, I would suggest creating your own stop, similar to what is done in #24. The stop APIs are provided for quick convenience, but you can achieve the same, and even more sophisticated logic, by checking your own conditions during execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants