I'm trying to convert indicator Top Bottom by ceyhun from tradingview to python. I am stuck converting the barssince lines. One of them is like this
per = input(14, title="Bottom Period")
loc = low < lowest(low[1], per) and low <= lowest(low[per], per)
bottom = barssince(loc)
So far I have this in python
bottomPeriod = 14
data['counter'] = data.index.where(data.loc[data.index[-1], "low"] < min(data["low"][(-bottomPeriod-1):-1]) and data.loc[data.index[-1], "low"] <= min(data["low"][(-bottomPeriod*2-1):(-bottomPeriod-1)]))
data['counter'].fillna(method="ffill",inplace=True)
data['Rows_since_condition'] = data.index-data['counter']
data.drop(['counter'], axis=1,inplace=True)
I can't get the where
to work. I'm almost about to start iterating over the dataset but it is a big one and needs to run fast. Any help is much appreciated