admin管理员组文章数量:1278882
I am a vectorbt newbie. so far I have been successfully setup many parameters, but what I cannot find is a way of exiting the trade if the max number of bars is reached
This is my current function:
def indicators(close,rsiPeriod,rsiEntry,rsiExit,kerLength,kerThreshold):
# RSI
delta = close.diff()
gain = (delta.where(delta > 0, 0)).rolling(window=rsiPeriod).mean()
loss = (-delta.where(delta < 0, 0)).rolling(window=rsiPeriod).mean()
rs = gain / loss
rsi = 100 - (100 / (1 + rs))
# Calculate absolute price change over the length period
change = abs(close - close.shift(kerLength))
# Calculate volatility (sum of absolute 1-period changes)
volatility = close.diff().abs().rolling(window=kerLength).sum()
# Calculate KER
ker = change / volatility
trend = np.where(rsi > rsiExit, -1, 0)
trend = np.where((rsi < rsiEntry)& (ker > kerThreshold), 1, trend)
return trend
I want to add a new parameter maxBars so that the exit (trend = -1) should be (rsi > rsiExit) OR (number of bars since open = maxBars).
i can't find it anywhere. Any help is appreciated.
本文标签: pythonVectorbt Setting exit trade with max durationStack Overflow
版权声明:本文标题:python - Vectorbt Setting exit trade with max duration - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741241734a2364112.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论