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

Integration of stop with basic signals extended with run combs #60

Closed
wyczolko opened this issue Dec 9, 2020 · 1 comment
Closed

Integration of stop with basic signals extended with run combs #60

wyczolko opened this issue Dec 9, 2020 · 1 comment

Comments

@wyczolko
Copy link

wyczolko commented Dec 9, 2020

I am new to your package and was hoping you might answer a general setup question:

Can you provide a quick example of how to add the stop loss logic to an existing strategy of the form :

fast_ma, slow_ma = vbt.MA.run_combs(price, window=windows, r=2, short_names=['fast', 'slow'])
entries = fast_ma.ma_above(slow_ma, crossed=True)
exits = fast_ma.ma_below(slow_ma, crossed=True)

[STOP LOSS logic here]

Such that the stop loss and normal exit logic integrate together

@polakowo
Copy link
Owner

polakowo commented Dec 9, 2020

You can generate stop signals, combine with your exit signals using OR rule, and select the first exit after each entry.

stop_exits = entries.vbt.signals.generate_stop_exits(price, -0.1)
exits = (exits.vbt | stop_exits).vbt.signals.first(reset_by=entries, allow_gaps=True)

Actually if you are using Portfolio.from_signals, you don't need the last step since only the first signal is executed anyway.

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