You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Sometime the ZigZag Waves are not formed correctly for Deviation: 0.1% or greater
To Reproduce
!pipinstall-Ugit+https://github.com/twopirllc/pandas-ta.git@developmentfrompandas_taimportzigzagimportpandas_taastaimportpandasaspdimportnumpyasnpimportplotly.ioaspiofromdatetimeimportdatefromdatetimeimportdatetime, timedeltafrompytzimporttimezoneimportplotly.graph_objectsasgoimportplotly.figure_factoryasffimportplotly.expressaspximportplotly.ioaspioimportyfinanceasyf# Define the stock ticker symbol (replace 'ES=F' with your desired stock symbol)ticker='ES=F'# Fetch the last 1 day of data with 1-minute intervalsdata=yf.download(ticker, interval='1m', period='5d')
# Convert the datetime index from UTC to Eastern Time (US/Eastern)data.index=data.index.tz_convert('US/Eastern')
df2=data.copy()
# Flatten the MultiIndex and remove the ticker part (symbol name)df2.columns=df2.columns.get_level_values('Price')
# Reset index to get a default integer-based indexdf2.reset_index(drop=False, inplace=True)
# Using the Pandas-TA zigzag indicator (or other equivalent library like ta-lib or ta)zigzag_result=ta.zigzag(
high=df2['High'], # High prices of the assetlow=df2['Low'], # Low prices of the assetclose=df2['Close'], # Closing prices of the assetlegs=3, # Minimum number of price points required for a significant trend changedeviation=0.01, # Minimum 1% price movement to form a new zigzag segment (1% deviation)retrace=True, # Consider retraces before identifying new pointslast_extreme=True, # Consider the last extreme point in the calculationoffset=0# No time offset, meaning Zigzag points will be calculated from the current time
)
df2=df2.join(zigzag_result)
zigzag_result2=ta.zigzag(
high=df2['High'],
low=df2['Low'],
close=df2['Close'],
legs=3,
deviation=0.1, #0.07retrace=True,
last_extreme=True,
offset=0
)
df2=df2.join(zigzag_result2,rsuffix='_zigzag')
df2=df2.iloc[:-1]
# Filter non-NaN values in ZIGZAGv_0.01%_3 for plottingvalid_zigzag_data=df2[df2['ZIGZAGv_0.01%_3'].notna()]
# Create the figurefig=go.Figure()
# Adding Candlestick tracefig.add_trace(go.Candlestick(
x=df2['Datetime'], # Assuming `Datetime` is set as indexopen=df2['Open'],
high=df2['High'],
low=df2['Low'],
close=df2['Close'],
name='Candlesticks'
))
# Adding Zigzag line trace with dotsfig.add_trace(go.Scatter(
x=valid_zigzag_data['Datetime'], # Non-NaN indicesy=valid_zigzag_data['ZIGZAGv_0.01%_3'], # Non-NaN Zigzag valuesmode='markers+lines', # Both markers (dots) and linesline=dict(color='rgba(0, 0, 255, 0.9)', width=2.5), # Customize the line color and widthmarker=dict(color='red', size=4), # Customize the dots color and sizename='Wave Formation 0.01% DEV'
))
# Filter non-NaN values in ZIGZAGv_0.01%_3 for plottingvalid_zigzag_data2=df2[df2['ZIGZAGv_0.1%_3'].notna()]
# Adding Zigzag line trace with dotsfig.add_trace(go.Scatter(
x=valid_zigzag_data2['Datetime'], # Non-NaN indicesy=valid_zigzag_data2['ZIGZAGv_0.1%_3'], # Non-NaN Zigzag valuesmode='markers+lines', # Both markers (dots) and linesline=dict(color='yellow', width=2.5), # Customize the line color and widthmarker=dict(color='red', size=4), # Customize the dots color and sizename='Wave Formation 0.1% DEV'
))
# Set up layoutfig.update_layout(
title="Price with Higher High and Lower Low Patterns",
xaxis_title="Date",
xaxis=dict(
rangeslider=dict(
visible=True# Set to True to make the range slider visible
)),
yaxis=dict(
autorange=True, # Enable dynamic Y-axis range adjustmentfixedrange=False# Allow zooming on the y-axis
),
yaxis_title="Price",
template="plotly_dark",
showlegend=True,
legend=dict(
orientation='h', # Horizontal legendyanchor='top',
y=1.5, # Position legend slightly above the plotxanchor='left',
x=0.5, # Center the legend horizontallyfont=dict(
color="grey"# Change the legend text color here (e.g., 'white', 'black', or any valid CSS color)
)
)
)
# Show plotfig.show()
# Optionally, save the figure to an HTML filepio.write_html(fig, file='Wave Pattern Formation 5d.html', auto_open=True)
Expected behavior
As Data is coming on 1min Basis, sometimes zigzag are plotted correctly as below.
Screenshots
While Rest of Time Zigzag is not plotted correctly, like below.
The text was updated successfully, but these errors were encountered:
Could you share the dataset which results in inconsistent results? Perhaps you can make a temporary csv file to store results. My intuition is that maybe there are null values reported in dataset by yfinance. Did you try using other tickers? If yes, did you face occasional inconsistent results there too?
Which version are you running? The lastest version is on Github. Pip is for major releases.
Have you tried the development version? Did it resolve the issue?
Describe the bug
Sometime the ZigZag Waves are not formed correctly for Deviation: 0.1% or greater
To Reproduce
Expected behavior
As Data is coming on 1min Basis, sometimes zigzag are plotted correctly as below.
Screenshots
While Rest of Time Zigzag is not plotted correctly, like below.
The text was updated successfully, but these errors were encountered: