I am running the below-mentioned code to create a candlestick chart with traces but an error is being reflected as Exception has occurred: AttributeError 'dict' object has no attribute 'add_trace'
The code is as follows
import pandas as pd
import plotly.graph_objects as go
import yfinance as yf
import plotly.offline
from plotly.offline import init_notebook_mode, iplot, iplot_mpl
a=input("Enter symbol of the company\n")
tick1=a+'.NS'
HD=yf.Ticker(tick1)
His=HD.history(period='3mo',interval='1d')
His.reset_index(inplace=True)
His['20wma']=His['Close'].rolling(window=140).mean()
fig={"data":[go.Candlestick(x=His['Date'],open=His['Open'],high=His['High'],low=His['Low'],close=His['Close'])]}
fig.add_trace(go.Scatter(x=His['Date'],y=His['20wma'],line=dict(color="e0e0e0")))
plotly.offline.plot(fig)
For graph_objects, go.Figure() is the correct way to write it. Figure() is the correct way to write it. And the color setting needs the hexadecimal notation #.
import pandas as pd
import plotly.graph_objects as go
import yfinance as yf
import plotly.offline
from plotly.offline import init_notebook_mode, iplot, iplot_mpl
a=input("Enter symbol of the company\n")
tick1=a # edit
# rick1=a+'.NS'
HD=yf.Ticker(tick1)
His=HD.history(period='3mo',interval='1d')
His.reset_index(inplace=True)
His['20wma']=His['Close'].rolling(window=20).mean()
fig=go.Figure(data=(go.Candlestick(
x=His['Date'],
open=His['Open'],
high=His['High'],
low=His['Low'],
close=His['Close'])))
fig.add_trace(go.Scatter(
x=His['Date'],
y=His['20wma'],
mode='lines',
line=dict(color="#e0e0e0")))
plotly.offline.plot(fig)