### Execute Complete Pattern Detection Workflow Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt A full pipeline example that loads OHLC data, runs multiple pattern detection algorithms, and iterates through results to generate summary statistics and visualizations. ```python import pandas as pd from chart_patterns.doubles import find_doubles_pattern from chart_patterns.triangles import find_triangle_pattern from chart_patterns.pennant import find_pennant ohlc = pd.read_csv("eurusd-4h.csv") ohlc = find_doubles_pattern(ohlc, double="both", progress=True) ohlc = find_triangle_pattern(ohlc, triangle_type="ascending", progress=True) ohlc = find_pennant(ohlc, progress=True) for pattern in ['double', 'triangle', 'pennant']: count = len(ohlc[ohlc['chart_type'] == pattern]) if count > 0: display_chart_pattern(ohlc, pattern=pattern, save=True) ``` -------------------------------- ### Detect and Visualize Chart Patterns with Python Source: https://github.com/zeta-zetra/chart_patterns/blob/main/README.md This snippet demonstrates how to load OHLC financial data from a CSV file, apply the pennant pattern detection algorithm, and render the resulting chart. It requires a pandas DataFrame with 'open', 'high', 'low', and 'close' columns. ```python import pandas as pd # read in your ohlc data ohlc = pd.read_csv("eurusd-4h.csv") # headers must include - open, high, low, close # Find the head and shoulers pattern ohlc = find_pennant(ohlc, progress=True) # Plot the results display_chart_pattern(ohlc, pattern="pennant") ``` -------------------------------- ### Detect Inverse Head and Shoulders Patterns with Python Source: https://github.com/zeta-zetra/chart_patterns/blob/main/README.md This snippet demonstrates the detection of Inverse Head and Shoulders patterns using the `chart_patterns` library in Python. It employs `find_inverse_head_and_shoulders` for pattern identification and `display_chart_pattern` for visualization. The output plots are saved to the 'images/ihs' directory if multiple patterns are detected. ```python import pandas as pd from chart_patterns.chart_patterns.inverse_head_and_shoulders import find_inverse_head_and_shoulders from chart_patterns.chart_patterns.plotting import display_chart_pattern # read in your ohlc data ohlc = pd.read_csv("eurusd-4h.csv") # headers must include - open, high, low, close # Find inversr head and shoulders ohlc = find_inverse_head_and_shoulders(ohlc) # Plot the results display_chart_pattern(ohlc, pattern="ihs") # If multiple patterns were found, then plots will saved inside a folder named images/ihs ``` -------------------------------- ### Detect Double Tops and Bottoms Patterns with Python Source: https://github.com/zeta-zetra/chart_patterns/blob/main/README.md This snippet demonstrates how to use the `find_doubles_pattern` function from the `chart_patterns` library to detect double tops and double bottoms in OHLC data. It requires pandas for data manipulation and the `chart_patterns` library for pattern detection and plotting. The function takes OHLC data and a 'double' type ('tops' or 'bottoms') as input and returns the OHLC data with detected patterns. Plotting is handled by `display_chart_pattern`. ```python import pandas as pd from chart_patterns.chart_patterns.doubles import find_doubles_pattern from chart_patterns.chart_patterns.plotting import display_chart_pattern # read in your ohlc data ohlc = pd.read_csv("eurusd-4h.csv") #headers include - open, high, low, close # Find the double bottom pattern ohlc = find_doubles_pattern(ohlc, double="bottoms") # Find the double tops pattern ohlc = find_doubles_pattern(ohlc, double="tops") # Plot the results display_chart_pattern(ohlc, pattern="double") # If multiple patterns were found, then plots will saved inside a folder named images/double ``` -------------------------------- ### Detect Triangle Patterns (Ascending, Descending, Symmetrical) with Python Source: https://github.com/zeta-zetra/chart_patterns/blob/main/README.md This Python code snippet shows how to detect various triangle patterns (ascending, descending, symmetrical) using the `find_triangle_pattern` function from the `chart_patterns` library. It requires pandas for data handling and `display_chart_pattern` for visualization. Detected patterns are saved in the 'images/triangle' directory. ```python import pandas as pd from chart_patterns.chart_patterns.triangles import find_triangle_pattern from chart_patterns.chart_patterns.plotting import display_chart_pattern # read in your ohlc data ohlc = pd.read_csv("eurusd-4h.csv") # headers must include - open, high, low, close # Find the ascending triangle ohlc = find_triangle_pattern(ohlc) # Find the descending triangle ohlc = find_triangle_pattern(ohlc, triangle_type="descending") # Find the symmetrical triangle ohlc = find_triangle_pattern(ohlc, triangle_type="symmetrical") # Plot the results display_chart_pattern(ohlc, pattern="triangle") # If multiple patterns were found, then plots will saved inside a folder named images/triangle ``` -------------------------------- ### Detect and Analyze Pennant Patterns in Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Demonstrates how to identify pennant patterns within a pandas DataFrame using specific geometric constraints. It includes logic to filter detected patterns and extract detailed pivot point information. ```python ohlc = find_pennant( ohlc, lookback=20, min_points=3, r_max=0.9, r_min=0.9, slope_max=-0.0001, slope_min=0.0001, lower_ratio_slope=0.95, upper_ratio_slope=1.0, progress=True ) pennants = ohlc[ohlc['chart_type'] == 'pennant'] for idx, row in pennants.iterrows(): print(f"Pennant at index {idx}: Highs={row['pennant_highs']}, Lows={row['pennant_lows']}") ``` -------------------------------- ### Detect Flag Patterns with Python Source: https://github.com/zeta-zetra/chart_patterns/blob/main/README.md This code snippet shows how to detect flag chart patterns using the `find_flag_pattern` function from the `chart_patterns` Python library. It requires pandas for reading OHLC data and the `chart_patterns` library for pattern detection and visualization. The `display_chart_pattern` function is used to plot the detected flag patterns, saving them to an 'images/flag' directory if multiple patterns are found. ```python import pandas as pd from chart_patterns.chart_patterns.flag import find_flag_pattern from chart_patterns.chart_patterns.plotting import display_chart_pattern # read in your ohlc data ohlc = pd.read_csv("eurusd-4h.csv") #headers include - open, high, low, close # Plot the results display_chart_pattern(ohlc, pattern="flag") # If multiple patterns were found, then plots will saved inside a folder named images/flag ``` -------------------------------- ### Detect Pennant Patterns with Python Source: https://github.com/zeta-zetra/chart_patterns/blob/main/README.md This code snippet demonstrates how to detect pennant chart patterns using the `find_pennant` function from the `chart_patterns` Python library. It requires pandas for reading OHLC data and `display_chart_pattern` for plotting the detected patterns. The function processes OHLC data and can save plots to an 'images/pennant' directory if multiple patterns are found. ```python import pandas as pd from chart_patterns.chart_patterns.pennant import find_pennant from chart_patterns.chart_patterns.plotting import display_chart_pattern ``` -------------------------------- ### Detect Double Tops and Bottoms - Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Detects double top and double bottom chart patterns by analyzing sequences of pivot points. Double tops suggest potential bearish reversals, while double bottoms indicate potential bullish reversals. The function requires OHLC data and returns an augmented DataFrame with pattern details. ```python import pandas as pd from chart_patterns.doubles import find_doubles_pattern from chart_patterns.plotting import display_chart_pattern # Load OHLC data ohlc = pd.read_csv("eurusd-4h.csv") # Find double bottom patterns ohlc = find_doubles_pattern( ohlc, lookback=25, # Number of periods to analyze double="bottoms", # Options: "tops", "bottoms", "both" bottoms_min_ratio=0.98, # Minimum ratio between trough points progress=True # Show progress bar ) # Find double top patterns ohlc = find_doubles_pattern( ohlc, lookback=25, double="tops", tops_max_ratio=1.01, # Maximum ratio between peak points progress=True ) # Check for detected patterns patterns_found = ohlc[ohlc['chart_type'] == 'double'] print(f"Found {len(patterns_found)} double patterns") # Access pattern details for idx, row in patterns_found.iterrows(): print(f"Pattern at index {idx}: {row['double_type']}") print(f" Pivot indices: {row['double_idx']}") print(f" Pivot values: {row['double_point']}") # Plot and save all detected patterns to images/double/ display_chart_pattern(ohlc, pattern="double", save=True) ``` -------------------------------- ### Detect Head and Shoulders Patterns with Python Source: https://github.com/zeta-zetra/chart_patterns/blob/main/README.md This Python code utilizes the `chart_patterns` library to identify Head and Shoulders chart patterns. It imports `find_head_and_shoulders` for detection and `display_chart_pattern` for visualization. The function processes OHLC data, and detected patterns are plotted and saved in the 'images/hs' directory if multiple instances are found. ```python import pandas as pd from chart_patterns.chart_patterns.head_and_shoulders import find_head_and_shoulders from chart_patterns.chart_patterns.plotting import display_chart_pattern # read in your ohlc data ohlc = pd.read_csv("eurusd-4h.csv") # headers must include - open, high, low, close # Find the head and shoulers pattern ohlc = find_head_and_shoulders(ohlc) # Plot the results display_chart_pattern(ohlc, pattern="hs") # If multiple patterns were found, then plots will saved inside a folder named images/hs ``` -------------------------------- ### Detect Pivot Points in Price Data - Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Identifies pivot highs and lows in OHLC data by comparing candle values with surrounding candles. This is a foundational function for all chart pattern detection. It requires pandas for data manipulation and returns an augmented DataFrame with pivot point indicators. ```python import pandas as pd from chart_patterns.pivot_points import find_all_pivot_points from chart_patterns.plotting import display_pivot_points # Load OHLC data (columns: open, high, low, close) ohlc = pd.read_csv("eurusd-4h.csv") # Find pivot points with default settings (3 candles left/right) ohlc = find_all_pivot_points(ohlc, left_count=3, right_count=3) # Access pivot point data # pivot column values: 0=no pivot, 1=pivot low, 2=pivot high, 3=both pivot_lows = ohlc[ohlc['pivot'] == 1] pivot_highs = ohlc[ohlc['pivot'] == 2] print(f"Found {len(pivot_lows)} pivot lows and {len(pivot_highs)} pivot highs") # Visualize pivot points on candlestick chart display_pivot_points(ohlc, plot_obs=500) ``` -------------------------------- ### Visualize and Save Chart Patterns with Plotly Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Shows how to render detected patterns on candlestick charts. The library supports saving visualizations as PNG files or displaying them interactively, with support for custom themes. ```python from chart_patterns.plotting import display_chart_pattern, display_pivot_points # Save pattern to image display_chart_pattern(ohlc, pattern="triangle", save=True, lookback=60) # Custom theme visualization custom_theme = {"bg_color": "#1a1a2e", "up_color": "#00ff88", "down_color": "#ff4444"} display_pivot_points(ohlc, theme=custom_theme, plot_obs=300) ``` -------------------------------- ### Find Inverse Head and Shoulders Pattern in Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Detects the bullish reversal Inverse Head and Shoulders pattern. It analyzes OHLC data to find three troughs where the middle trough is lower than the surrounding two, connected by a neckline. Requires pandas and specific functions from chart_patterns. ```python import pandas as pd from chart_patterns.inverse_head_and_shoulders import find_inverse_head_and_shoulders from chart_patterns.plotting import display_chart_pattern # Load OHLC data ohlc = pd.read_csv("eurusd-4h.csv") # Find inverse head and shoulders patterns ohlc = find_inverse_head_and_shoulders( ohlc, lookback=60, pivot_interval=10, short_pivot_interval=5, head_ratio_before=0.98, # Head/left shoulder ratio threshold head_ratio_after=0.98, # Head/right shoulder ratio threshold upper_slmax=1e-4, # Maximum neckline slope progress=True ) # Access pattern data ihs_patterns = ohlc[ohlc['chart_type'] == 'ihs'] print(f"Found {len(ihs_patterns)} inverse head and shoulders patterns") for idx, row in ihs_patterns.iterrows(): print(f"Pattern at index {idx}") print(f" Point indices: {row['ihs_idx']}") print(f" Point values: {row['ihs_point']}") # Order: left shoulder, left peak, head, right peak, right shoulder # Plot and save patterns display_chart_pattern(ohlc, pattern="ihs", save=True, lookback=60) ``` -------------------------------- ### Find Flag Pattern in Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Identifies flag continuation patterns in OHLC data. These patterns are characterized by parallel trendlines sloping against the prior trend, typically forming after a strong price move. Requires pandas and specific functions from chart_patterns. ```python import pandas as pd from chart_patterns.flag import find_flag_pattern from chart_patterns.plotting import display_chart_pattern # Load OHLC data ohlc = pd.read_csv("eurusd-4h.csv") # Find flag patterns ohlc = find_flag_pattern( ohlc, lookback=25, # Candles to analyze min_points=3, # Minimum pivot points required r_max=0.9, # R-squared threshold for highs r_min=0.9, # R-squared threshold for lows slope_max=0, # Slope threshold for highs slope_min=0, # Slope threshold for lows lower_ratio_slope=0.9, # Lower slope ratio limit upper_ratio_slope=1.05, # Upper slope ratio limit progress=True ) # Access flag pattern data flags = ohlc[ohlc['chart_type'] == 'flag'] print(f"Found {len(flags)} flag patterns") for idx, row in flags.iterrows(): print(f"Flag at index {idx}") print(f" High pivot indices: {row['flag_highs_idx']}") print(f" Low pivot indices: {row['flag_lows_idx']}") print(f" High slope: {row['flag_slmax']:.6f}") print(f" Low slope: {row['flag_slmin']:.6f}") # Plot and save flag patterns display_chart_pattern(ohlc, pattern="flag", save=True) ``` -------------------------------- ### Find Head and Shoulders Pattern in Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Detects the bearish reversal Head and Shoulders pattern. It analyzes OHLC data to find three peaks where the middle peak is higher than the surrounding two, connected by a neckline. Requires pandas for data manipulation and specific functions from chart_patterns. ```python import pandas as pd from chart_patterns.head_and_shoulders import find_head_and_shoulders from chart_patterns.plotting import display_chart_pattern # Load OHLC data ohlc = pd.read_csv("eurusd-4h.csv") # Find head and shoulders patterns ohlc = find_head_and_shoulders( ohlc, lookback=60, # Number of periods to analyze pivot_interval=10, # Candles for pivot detection short_pivot_interval=5, # Secondary pivot interval (must be < pivot_interval) head_ratio_before=1.0002, # Head/left shoulder ratio threshold head_ratio_after=1.0002, # Head/right shoulder ratio threshold upper_slmin=1e-4, # Maximum neckline slope progress=True ) # Access pattern data hs_patterns = ohlc[ohlc['chart_type'] == 'hs'] print(f"Found {len(hs_patterns)} head and shoulders patterns") for idx, row in hs_patterns.iterrows(): print(f"Pattern at index {idx}") print(f" Point indices: {row['hs_idx']}") print(f" Point values: {row['hs_point']}") # Order: left shoulder, left trough, head, right trough, right shoulder # Plot and save patterns display_chart_pattern(ohlc, pattern="hs", save=True, lookback=60) ``` -------------------------------- ### Find Pennant Pattern in Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Identifies pennant continuation patterns in OHLC data. Similar to symmetrical triangles, pennants form after a strong price move and have converging trendlines that meet at an apex. Requires pandas and specific functions from chart_patterns. ```python import pandas as pd from chart_patterns.pennant import find_pennant from chart_patterns.plotting import display_chart_pattern # Load OHLC data ohlc = pd.read_csv("eurusd-4h.csv") # The find_pennant function would be called here, similar to other pattern detection functions. # Example placeholder for the function call: # ohlc = find_pennant(ohlc, ...) # Access pennant pattern data would follow, e.g.: # pennants = ohlc[ohlc['chart_type'] == 'pennant'] # print(f"Found {len(pennants)} pennant patterns") # Plot and save pennant patterns would also be called: # display_chart_pattern(ohlc, pattern="pennant", save=True) ``` -------------------------------- ### Detect Triangle Patterns - Python Source: https://context7.com/zeta-zetra/chart_patterns/llms.txt Identifies ascending, descending, and symmetrical triangle chart patterns using linear regression on pivot points. These patterns have specific characteristics regarding resistance and support trendlines. The function requires OHLC data and returns an augmented DataFrame with triangle pattern details. ```python import pandas as pd from chart_patterns.triangles import find_triangle_pattern from chart_patterns.plotting import display_chart_pattern # Load OHLC data ohlc = pd.read_csv("eurusd-4h.csv") # Find ascending triangle (flat top, rising bottom) ohlc = find_triangle_pattern( ohlc, lookback=25, # Candles to look back min_points=3, # Minimum pivot points required rlimit=0.9, # R-squared fit threshold slmax_limit=0.00001, # Slope limit for highs slmin_limit=0.00001, # Slope limit for lows triangle_type="ascending", # Options: "ascending", "descending", "symmetrical" progress=True ) # Find descending triangle (falling top, flat bottom) ohlc = find_triangle_pattern(ohlc, triangle_type="descending", progress=True) # Find symmetrical triangle (converging lines) ohlc = find_triangle_pattern(ohlc, triangle_type="symmetrical", progress=True) # Access triangle pattern data triangles = ohlc[ohlc['chart_type'] == 'triangle'] for idx, row in triangles.iterrows(): print(f"Triangle at {idx}: {row['triangle_type']}") print(f" High slope: {row['triangle_slmax']:.6f}") print(f" Low slope: {row['triangle_slmin']:.6f}") # Plot and save triangle patterns display_chart_pattern(ohlc, pattern="triangle", save=True) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.