from breeze_connect import BreezeConnect
from datetime import datetime,date,time,timedelta
import pandas as pd
import numpy as np
import pandas_ta as ta

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)

breeze = BreezeConnect(api_key="")
breeze.generate_session(api_secret="", session_token="")

stock = breeze.get_historical_data(interval="1minute",
                                       from_date="2022-8-30T07:00:00.000Z",
                                       to_date="2022-8-30T18:00:00.000Z",
                                       stock_code="TCS",
                                       exchange_code="NSE",
                                       product_type="others")
df = pd.DataFrame(stock['Success'])
# df["RSI"] = ta.rsi(close = pd.to_numeric(df.close), length=10)
# df['ATR'] = ta.atr(pd.to_numeric(df["high"]),pd.to_numeric(df["low"]),pd.to_numeric(df["close"].shift()), length=14)

# high_low = pd.to_numeric(df["high"]) - pd.to_numeric(df["low"])
# high_close = np.abs(pd.to_numeric(df["high"]) - pd.to_numeric(df["close"].shift()))
# low_close = np.abs(pd.to_numeric(df["low"]) - pd.to_numeric(df["close"].shift()))
# ranges = pd.concat([high_low, high_close, low_close], axis=1)
# true_range = np.max(ranges, axis=1)
# df['ATR-C'] = true_range.rolling(14).sum()/14
#
# df["high_low"] = pd.to_numeric(df["high"]) - pd.to_numeric(df["low"])
# df["high_close"] = np.abs(pd.to_numeric(df["high"]) - pd.to_numeric(df["close"].shift()))
# df["low_close"] = np.abs(pd.to_numeric(df["low"]) - pd.to_numeric(df["close"].shift()))
# df["Max"] = df[['high_low','high_close','low_close']].max(axis=1)
# df["ATR-CR"] = df["Max"].rolling(14).sum()/14
# print(df)

# Function to calculate average true range
# def ATR(DF, n):
#   df = DF.copy() # making copy of the original dataframe
df['H-L'] = abs(pd.to_numeric(df['high']) - pd.to_numeric(df['low']))
df['H-PC'] = abs(pd.to_numeric(df['high']) - pd.to_numeric(df['close']).shift())# high -previous close
df['L-PC'] = abs(pd.to_numeric(df['low']) - pd.to_numeric(df['close']).shift()) #low - previous close
df['TR'] = df[['H-L','H-PC','L-PC']].max(axis =1, skipna = False) # True range
df['ATR'] = df['TR'].rolling(14).mean() # average –true range
df = df.drop(['H-L','H-PC','L-PC','TR','count'], axis =1) # dropping the unneccesary columns
  # df.dropna(inplace = True) # droping null items
df['bricks'] = round(df["ATR"], 0)
  # return df
print(df)

By AskMahe.com

Hi, AskMahe.com is the Brainchild of Mahendran Paramasivan who is interested in bringing the latest technology to the common people and corporates. We are a team and we are providing supports on Technology and innovation as per industrial standard. We are supporting with the help of analysis we made on Technology and innovation to help corporate companies and individuals. We bring the latest updates of technology and innovation in front of the eyes of our readers, clients, and people. We have resources in Cloud computing, IoT, Edge Computing, Dew Computing, 5G, SAP, Web Designing, UI/ UX Design. Regards AskMahe Team askmahe.com