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

Calculation of Stop price #539

Open
madhurmehta-sahi opened this issue Dec 9, 2022 · 5 comments
Open

Calculation of Stop price #539

madhurmehta-sahi opened this issue Dec 9, 2022 · 5 comments
Labels

Comments

@madhurmehta-sahi
Copy link

Hi, I have been trying to implement TP/SL using the vbt.Portfolio.from_signals. I passed all the required prices in the parameters

(df.Close, open=df.Open, high=df.High, low=df.Low, entries=signals.TS_Entries, exits=signals.TS_Exits, freq='15m', init_cash=100000, fees=FEES, sl_stop=0.005, tp_stop=0.0025, direction='LONG_ONLY', stop_entry_price='close', size=1,  stop_exit_price='price')

Issue is that even after applying tp_stop as 0.25%, my best trades come out as 3%. Sharing the two OHLC below to explain better:

**Candle1:**
Open - 19522
High - 20255
Low - 19481
Close - 19530

**Candle2**
Open  - 20185.78
High - 20200
Low - 20140
Close - 20164

Entry happens at 19530 (Candle1.Close) and exit happens at 20185 (Candle2.Open). Net returns - 3.3%
I went through the documentation also to understand the possible values of stop_exit_price. But in all the cases, it either pick ups the Open or Close of the next candle. Is it not possible for the framework to calculate the TP price and put that as exit price? That will ensure that no trade goes beyond the mentioned tp_stop

@polakowo
Copy link
Owner

polakowo commented Dec 11, 2022

It uses stop price by default, that is, for long positions entry price x (1 + tp_stop). By setting stop exit price to “price” it will execute using default order price, which in your case is close.

@madhurmehta-sahi
Copy link
Author

I tried with stop price also. I think issue is here is that the entry and exit happens on the same candle (Candle1). Please confirm if this is the issue, and if yes, then how can this be solved?

@polakowo
Copy link
Owner

If you executed using the close price, then it cannot happen at the same bar. But if you executed using open price, then probably, in such a case the stop will be resolved at the next bar (and there's no workaround to this because only one order per bar is supported, you can write your own logic using flexible order functions).

@madhurmehta-sahi
Copy link
Author

understood this part. In my case, I am passing a custom price as the first parameter of the from_signals (this is based on some logic).

price_list = [] // custom logic to fill the prices somewhere in the middle of the candle
from_signals(price_list, open=df.Open, high=df.High, low=df.Low, entries=signals.TS_Entries, exits=signals.TS_Exits, freq='15m', init_cash=100000, fees=FEES, sl_stop=0.005, tp_stop=0.0025, direction='LONG_ONLY', stop_entry_price='close', size=1,  stop_exit_price='price')

in this case, the TP takes price of next close only in all the stop_exit_modes. I was wondering if the entry price x (1 + tp_stop) will be calculated to see if the entry price and close price has sufficient difference to accommodate the TP

Copy link

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants