Hi, I'm trying to build pivot point standard in fyers api but im getting an error.

def levels(df):

“”“returns pivot point and support/resistance levels”“”

high = round(df[“high”][-1],2)

low = round(df[“low”][-1],2)

close = round(df[“close”][-1],2)

pivot = round((high + low + close)/3,2)

r1 = round((2*pivot - low),2)

r2 = round((pivot + (high - low)),2)

r3 = round((high + 2*(pivot - low)),2)

s1 = round((2*pivot - high),2)

s2 = round((pivot - (high - low)),2)

s3 = round((low - 2*(high - pivot)),2)

return (pivot,r1,r2,r3,s1,s2,s3)

hist_data = fyers.history(history_data)

hist_data = hist_data[‘candles’]

df = pd.DataFrame(hist_data, columns=[‘data’, ‘open’, ‘high’, ‘low’, ‘close’, ‘volume’])

pp_levels = levels(df.iloc[:-1,:])

output:

ValueError: -1 is not in range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File “C:\Users\kolia.spyder-py3[algo.py](http://algo.py)”, line 104, in

pp_levels = levels(df.iloc[:-1,:])

File “C:\Users\kolia.spyder-py3[algo.py](http://algo.py)”, line 89, in levels

high = round(df[“high”][-1],2)

File “C:\Users\kolia\anaconda3\lib\site-packages\pandas\core[series.py](http://series.py)”, line 942, in getitem

return self._get_value(key)

File “C:\Users\kolia\anaconda3\lib\site-packages\pandas\core[series.py](http://series.py)”, line 1051, in _get_value

loc = self.index.get_loc(label)

File “C:\Users\kolia\anaconda3\lib\site-packages\pandas\core\indexes[range.py](http://range.py)”, line 387, in get_loc

raise KeyError(key) from err

KeyError: -1

Hi Aditya,
can you let me know what you are trying to do in this line - pp_levels = levels(df.iloc[:-1,:])

df.iloc[:-1,:] it will remove current candle data

hi @vikram Siri did you spot any mistake in the above code ?

Hey Aditya,
I’ll test this out on my end and i’ll let you know

i just figure it out .its working now

high = round(df[“high”].iloc[-1],2)