I wrote a simple program for calculate daily ATR with ta-lib library. I compare result with ATR indicator in Tradingview and them are very different. Code is: `
def ohlcv(symbol, tf, bars_back=MAX_BAR_BACK):
ohlc = exchange.fetch_ohlcv(symbol, timeframe=tf, limit=bars_back)
ohlc_df = pd.DataFrame(ohlc, columns=['datetime', 'open', 'high', 'low', 'close', 'volume'])
ohlc_df['datetime'] = pd.to_datetime(ohlc_df['datetime'], unit='ms')
return ohlc_df
def ATR(symbol, tf, period=MAX_BAR_BACK):
data = ohlcv(symbol, tf)
close = data['close'].values
high = data['high'].values
low = data['low'].values
data.dropna(inplace=True)
return ta.ATR(high, low, close, timeperiod=period)[-1]
tradingview = ta.ATR on BTCUSDT ==> 278.7 MyCode = ATR() on BTCUSDT ==> 1275.0
Sorry, my English is poor. Please F1 me!!!
Which one is correct? and What is fault of My code??????