import pandas as pd import numpy as np import matplotlib.pyplot as plt import ta
def load_data(): data = pd.read_csv('historical_data.csv') data['Date'] = pd.to_datetime(data['Date']) data.set_index('Date', inplace=True) return data
def calculate_rsi(data, period=14): data['RSI'] = ta.momentum.RSIIndicator(data['Close'], window=period).rsi() return data
def detect_positive_divergence(data): detected_patterns = [] for i in range(1, len(data) - 1): if (data['Close'] < data['Close'][i-1] and data['RSI'] > data['RSI'][i-1]): detected_patterns.append((data.index, 'Positive Divergence')) return detected_patterns
for i in range(2, len(data) - 2): for pattern, ratios in fib_ratios.items(): high1 = data['High'][i-2] high2 = data['High'] low1 = data['Low'][i-2] low2 = data['Low']
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.