Specific values for stop loss #338
-
Hi, I have just started with algo trading and use this library to backtest my strategies. Its really great. However, I am having trouble with one specific thing. Thanks a lot and kudos on this wonderful implementation! The feature set is so very deep and I am sure I have a long way to go before I understand everything about the library. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @ironstone05, most arguments can be specified as arrays. Both sl_stop = (low.vbt.fshift(1) - entry_price) / entry_price
sl_stop[sl_stop > 0] = np.nan # previous low is already higher than now? disable stop loss
sl_stop = sl_stop.abs() # only positive values are allowed |
Beta Was this translation helpful? Give feedback.
Hi @ironstone05, most arguments can be specified as arrays. Both
sl_stop
andtp_stop
are percentages of the stop entry price. The default stop entry price isclose
, meaning even though you ordered at the current opening or any other price, the threshold will be computed from the current close (because if the stop is being hit in the same candle, vectorbt wouldn't know whether it's after the entry - we have no intra-candle data - so we use close just for safety). You can change that withstop_entry_price
(see enum https://vectorbt.dev/api/portfolio/enums/#vectorbt.portfolio.enums.StopEntryPrice), also globally invbt.settings['portfolio']['stop_entry_price']
. Now, you need to bring both st…