I would like to calculate the ADR for the last 5 days, but I have the problem that I don't know how to get the 5 days because I "only" have 1 minute Time Frame datas. So I would have to screw it up, but no matter what I try I never get the right result when I compare it with Tradingview Here is the code:
from backtesting import Backtest, Strategy
import pandas as pd
def getADR(highs,lows):
high = highs.max()
low = lows.min()
return high-low
class MyStrategy(Strategy):
def init(self):
pass
def next(self):
high = self.data.High[-1]
open = self.data.Open[-1]
low = self.data.Low[-1]
close = self.data.Close[-1]
# And here I want to check the ADR of the last 5 days. So I have to somehow make 5 daily data out of the 1 minute data
xx = getADR(self.data.High[""" :390? i dont know """],self.data.High[""" :390? i dont know """])
df = pd.read_csv('AAPL_Stock1m.csv',index_col='Timestamp',parse_dates=True)
bt = Backtest(df,MyStrategy,cash=50000)
print(bt.run())
My Index looks like this (shortened) https://pastebin.com/WaDvhGES
I hope that someone can help me with my problem :)
I tried to go through the index until I got 5 days out, e.g. [-390:] and then [-400] etc. but somehow the ADR result is not correct.
ADR = High(max)-Low(min)