Reputation: 15
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.
Upvotes: 0
Views: 19