import yfinance as yf import pandas as pd import numpy as np import matplotlib.pyplot as plt
# Function to check for price and volume breakouts def breakout_scanner(ticker, price_breakout_pct=1.05, volume_mult=1.5, lookback=20): # Download historical data (6 months of daily data) df = yf.download(ticker, period="6mo", interval="1d")
# Calculate moving averages for volume df['Avg_Volume'] = df['Volume'].rolling(window=lookback).mean()
# Get the recent high and low recent_high = df['High'].max() recent_low = df['Low'].min()
# Last row data (current day) last_row = df.iloc[-1]
# Check for Price Breakout (above recent high or below recent low) price_breakout_up = last_row['Close'] >= recent_high * price_breakout_pct price_breakout_down = last_row['Close'] <= recent_low * (2 - price_breakout_pct) # A breakout below recent low
# Check for Volume Breakout (above average volume threshold) volume_breakout = last_row['Volume'] >= df['Avg_Volume'].iloc[-1] * volume_mult
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.