position.close() and stop loss features #1018
Answered
by
peacerider
huytradingz
asked this question in
Q&A
-
Hello all, I am fairly new to trading, backtesting and backtesting.py in general, I would like know more about two things:
`class EmaCross(Strategy):
Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Answered by
peacerider
Aug 2, 2023
Replies: 1 comment 7 replies
-
The answer to your question No1 is written below. https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Position "Place new order to close portion of the trade at next market price." |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thank you for your explanation. I understood.
Your trailing stop is not working.
Once the order (buy or sell) is done, the stop loss of backtesting.py "sl" is not changed until the position is closed.
If you want to change the stop loss level to always be 5% of price.
You need to change the "sl" parametor of "trades".
https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Strategy.trades
Example