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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import yfinance as yf
|
| 5 |
+
import plotly.graph_objects as go
|
| 6 |
+
from plotly.subplots import make_subplots
|
| 7 |
+
import warnings
|
| 8 |
+
warnings.filterwarnings('ignore')
|
| 9 |
+
from curl_cffi import requests
|
| 10 |
+
session = requests.Session(impersonate="chrome")
|
| 11 |
+
|
| 12 |
+
# Import all technical indicators from your file
|
| 13 |
+
from technical_indicators import *
|
| 14 |
+
|
| 15 |
+
# Page configuration
|
| 16 |
+
st.set_page_config(
|
| 17 |
+
page_title="Technical Analysis Dashboard",
|
| 18 |
+
page_icon="π",
|
| 19 |
+
layout="wide",
|
| 20 |
+
initial_sidebar_state="expanded"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Custom CSS for better styling
|
| 24 |
+
st.markdown("""
|
| 25 |
+
<style>
|
| 26 |
+
.main-header {
|
| 27 |
+
font-size: 2.5rem;
|
| 28 |
+
font-weight: bold;
|
| 29 |
+
color: #1f77b4;
|
| 30 |
+
text-align: center;
|
| 31 |
+
margin-bottom: 2rem;
|
| 32 |
+
}
|
| 33 |
+
.sub-header {
|
| 34 |
+
font-size: 1.5rem;
|
| 35 |
+
font-weight: bold;
|
| 36 |
+
text-align: center;
|
| 37 |
+
margin-bottom: 1rem;
|
| 38 |
+
}
|
| 39 |
+
.metric-container {
|
| 40 |
+
background-color: #f0f2f6;
|
| 41 |
+
padding: 1rem;
|
| 42 |
+
border-radius: 0.5rem;
|
| 43 |
+
margin: 0.5rem 0;
|
| 44 |
+
}
|
| 45 |
+
.indicator-section {
|
| 46 |
+
background-color: #ffffff;
|
| 47 |
+
padding: 1.5rem;
|
| 48 |
+
border-radius: 0.5rem;
|
| 49 |
+
margin: 1rem 0;
|
| 50 |
+
border: 1px solid #e0e0e0;
|
| 51 |
+
}
|
| 52 |
+
</style>
|
| 53 |
+
""", unsafe_allow_html=True)
|
| 54 |
+
|
| 55 |
+
# Title
|
| 56 |
+
st.markdown('<h1 class="main-header">π Technical Analysis Dashboard</h1>', unsafe_allow_html=True)
|
| 57 |
+
st.markdown('<h3 class="sub-header">Developed By Zane Vijay Falcao</h3>', unsafe_allow_html=True)
|
| 58 |
+
st.divider()
|
| 59 |
+
# Sidebar for inputs
|
| 60 |
+
with st.sidebar:
|
| 61 |
+
st.header("π Configuration")
|
| 62 |
+
|
| 63 |
+
# Stock symbol input
|
| 64 |
+
symbol = st.text_input("Stock Symbol", value="AAPL", help="Enter stock symbol (e.g., AAPL, GOOGL, MSFT)")
|
| 65 |
+
|
| 66 |
+
# Time period selection
|
| 67 |
+
period = st.selectbox(
|
| 68 |
+
"Time Period",
|
| 69 |
+
["1mo", "3mo", "6mo", "1y", "2y", "5y", "max"],
|
| 70 |
+
index=3
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# Interval selection
|
| 74 |
+
interval = st.selectbox(
|
| 75 |
+
"Data Interval",
|
| 76 |
+
["1d", "5d", "1wk", "1mo"],
|
| 77 |
+
index=0
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
st.divider()
|
| 81 |
+
|
| 82 |
+
# Indicator Categories
|
| 83 |
+
st.header("π Select Indicators")
|
| 84 |
+
|
| 85 |
+
# Trend Indicators
|
| 86 |
+
with st.expander("Trend Indicators", expanded=True):
|
| 87 |
+
show_sma = st.checkbox("Simple Moving Average (SMA)", value=True)
|
| 88 |
+
show_ema = st.checkbox("Exponential Moving Average (EMA)", value=True)
|
| 89 |
+
show_hma = st.checkbox("Hull Moving Average (HMA)")
|
| 90 |
+
show_wma = st.checkbox("Weighted Moving Average (WMA)")
|
| 91 |
+
show_kama = st.checkbox("Kaufman Adaptive Moving Average (KAMA)")
|
| 92 |
+
show_frama = st.checkbox("Fractal Adaptive Moving Average (FRAMA)")
|
| 93 |
+
show_evwma = st.checkbox("Ehlers Volatility Weighted MA (EVWMA)")
|
| 94 |
+
show_vwap = st.checkbox("Volume Weighted Average Price (VWAP)")
|
| 95 |
+
|
| 96 |
+
# Momentum Indicators
|
| 97 |
+
with st.expander("Momentum Indicators", expanded=True):
|
| 98 |
+
show_rsi = st.checkbox("Relative Strength Index (RSI)", value=True)
|
| 99 |
+
show_macd = st.checkbox("MACD", value=True)
|
| 100 |
+
show_stochrsi = st.checkbox("Stochastic RSI")
|
| 101 |
+
show_cmo = st.checkbox("Chande Momentum Oscillator (CMO)")
|
| 102 |
+
show_roc = st.checkbox("Rate of Change (ROC)")
|
| 103 |
+
show_tsi = st.checkbox("True Strength Index (TSI)")
|
| 104 |
+
show_kst = st.checkbox("Know Sure Thing (KST)")
|
| 105 |
+
show_ppo = st.checkbox("Price Percentage Oscillator (PPO)")
|
| 106 |
+
show_uo = st.checkbox("Ultimate Oscillator (UO)")
|
| 107 |
+
|
| 108 |
+
# Volume Indicators
|
| 109 |
+
with st.expander("Volume Indicators"):
|
| 110 |
+
show_obv = st.checkbox("On-Balance Volume (OBV)")
|
| 111 |
+
show_adl = st.checkbox("Accumulation/Distribution Line (ADL)")
|
| 112 |
+
show_chaikin = st.checkbox("Chaikin Oscillator")
|
| 113 |
+
show_efi = st.checkbox("Elder's Force Index (EFI)")
|
| 114 |
+
show_emv = st.checkbox("Ease of Movement (EMV)")
|
| 115 |
+
show_mfi = st.checkbox("Money Flow Index (MFI)")
|
| 116 |
+
show_vpt = st.checkbox("Volume Price Trend (VPT)")
|
| 117 |
+
show_fve = st.checkbox("Fractal Volume Efficiency (FVE)")
|
| 118 |
+
show_vzo = st.checkbox("Volume Zone Oscillator (VZO)")
|
| 119 |
+
|
| 120 |
+
# Volatility Indicators
|
| 121 |
+
with st.expander("Volatility Indicators"):
|
| 122 |
+
show_bollinger = st.checkbox("Bollinger Bands", value=True)
|
| 123 |
+
show_kc = st.checkbox("Keltner Channels")
|
| 124 |
+
show_dc = st.checkbox("Donchian Channels")
|
| 125 |
+
show_atr = st.checkbox("Average True Range (ATR)")
|
| 126 |
+
show_chandelier = st.checkbox("Chandelier Exit")
|
| 127 |
+
show_psar = st.checkbox("Parabolic SAR")
|
| 128 |
+
show_apz = st.checkbox("Adaptive Price Zone (APZ)")
|
| 129 |
+
|
| 130 |
+
# Oscillators
|
| 131 |
+
with st.expander("Oscillators"):
|
| 132 |
+
show_adx = st.checkbox("Average Directional Index (ADX)")
|
| 133 |
+
show_cci = st.checkbox("Commodity Channel Index (CCI)")
|
| 134 |
+
show_fish = st.checkbox("Fisher Transform")
|
| 135 |
+
show_ao = st.checkbox("Awesome Oscillator (AO)")
|
| 136 |
+
show_mi = st.checkbox("Mass Index (MI)")
|
| 137 |
+
show_wto = st.checkbox("Wave Trend Oscillator (WTO)")
|
| 138 |
+
show_copp = st.checkbox("Coppock Curve")
|
| 139 |
+
show_ift_rsi = st.checkbox("Inverse Fisher Transform RSI")
|
| 140 |
+
|
| 141 |
+
# Complex Indicators
|
| 142 |
+
with st.expander("Complex Indicators"):
|
| 143 |
+
show_ichimoku = st.checkbox("Ichimoku Cloud")
|
| 144 |
+
show_pivot = st.checkbox("Pivot Points")
|
| 145 |
+
show_pivot_fib = st.checkbox("Fibonacci Pivot Points")
|
| 146 |
+
show_basp = st.checkbox("Buyer and Seller Pressure (BASP)")
|
| 147 |
+
show_baspn = st.checkbox("Normalized BASP")
|
| 148 |
+
show_dmi = st.checkbox("Directional Movement Index (DMI)")
|
| 149 |
+
show_ebbp = st.checkbox("Elder Bull/Bear Power")
|
| 150 |
+
|
| 151 |
+
st.divider()
|
| 152 |
+
|
| 153 |
+
# Parameter settings
|
| 154 |
+
st.header("βοΈ Parameters")
|
| 155 |
+
sma_period = st.slider("SMA Period", 5, 50, 20)
|
| 156 |
+
ema_period = st.slider("EMA Period", 5, 50, 20)
|
| 157 |
+
rsi_period = st.slider("RSI Period", 5, 30, 14)
|
| 158 |
+
bb_period = st.slider("Bollinger Bands Period", 10, 30, 20)
|
| 159 |
+
bb_std = st.slider("Bollinger Bands Std Dev", 1.0, 3.0, 2.0, 0.1)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
| 163 |
+
st.divider()
|
| 164 |
+
@st.cache_data
|
| 165 |
+
def fetch_data(symbol, period, interval):
|
| 166 |
+
ticker = yf.Ticker(symbol.upper(), session=session)
|
| 167 |
+
return ticker.history(period=period, interval=interval)
|
| 168 |
+
|
| 169 |
+
# Main content area
|
| 170 |
+
if col3.button("π Analyze Stock", type="secondary", use_container_width=True):
|
| 171 |
+
|
| 172 |
+
try:
|
| 173 |
+
# Fetch data
|
| 174 |
+
with st.spinner(f"Fetching data for {symbol.upper()}..."):
|
| 175 |
+
|
| 176 |
+
data = fetch_data(symbol, period, interval)
|
| 177 |
+
|
| 178 |
+
if data.empty:
|
| 179 |
+
st.error("No data found for the given symbol. Please check the symbol and try again.")
|
| 180 |
+
st.stop()
|
| 181 |
+
|
| 182 |
+
# Display basic info
|
| 183 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 184 |
+
|
| 185 |
+
with col1:
|
| 186 |
+
st.metric("Current Price", f"${data['Close'].iloc[-1]:.2f}")
|
| 187 |
+
|
| 188 |
+
with col2:
|
| 189 |
+
price_change = data['Close'].iloc[-1] - data['Close'].iloc[-2]
|
| 190 |
+
st.metric("Price Change", f"${price_change:.2f}", f"{price_change:.2f}")
|
| 191 |
+
|
| 192 |
+
with col3:
|
| 193 |
+
pct_change = (price_change / data['Close'].iloc[-2]) * 100
|
| 194 |
+
st.metric("% Change", f"{pct_change:.2f}%", f"{pct_change:.2f}%")
|
| 195 |
+
|
| 196 |
+
with col4:
|
| 197 |
+
st.metric("Volume", f"{data['Volume'].iloc[-1]:,.0f}")
|
| 198 |
+
|
| 199 |
+
# Calculate indicators
|
| 200 |
+
indicators = {}
|
| 201 |
+
|
| 202 |
+
# Trend Indicators
|
| 203 |
+
if show_sma:
|
| 204 |
+
indicators['SMA'] = SMA(data, sma_period)
|
| 205 |
+
if show_ema:
|
| 206 |
+
indicators['EMA'] = EMA(data, ema_period)
|
| 207 |
+
if show_hma:
|
| 208 |
+
indicators['HMA'] = HMA(data, 20)
|
| 209 |
+
if show_wma:
|
| 210 |
+
indicators['WMA'] = WMA(data, 20)
|
| 211 |
+
if show_kama:
|
| 212 |
+
indicators['KAMA'] = KAMA(data)
|
| 213 |
+
if show_frama:
|
| 214 |
+
indicators['FRAMA'] = FRAMA(data)
|
| 215 |
+
if show_evwma:
|
| 216 |
+
indicators['EVWMA'] = EVWMA(data)
|
| 217 |
+
if show_vwap:
|
| 218 |
+
indicators['VWAP'] = VWAP(data)
|
| 219 |
+
|
| 220 |
+
# Momentum Indicators
|
| 221 |
+
if show_rsi:
|
| 222 |
+
indicators['RSI'] = RSI(data, rsi_period)
|
| 223 |
+
if show_macd:
|
| 224 |
+
indicators['MACD'] = MACD(data)
|
| 225 |
+
if show_stochrsi:
|
| 226 |
+
indicators['StochRSI'] = STOCHRSI(data)
|
| 227 |
+
if show_cmo:
|
| 228 |
+
indicators['CMO'] = CMO(data)
|
| 229 |
+
if show_roc:
|
| 230 |
+
indicators['ROC'] = ROC(data)
|
| 231 |
+
if show_tsi:
|
| 232 |
+
indicators['TSI'] = TSI(data)
|
| 233 |
+
if show_kst:
|
| 234 |
+
indicators['KST'] = KST(data)
|
| 235 |
+
if show_ppo:
|
| 236 |
+
indicators['PPO'] = PPO(data)
|
| 237 |
+
if show_uo:
|
| 238 |
+
indicators['UO'] = UO(data)
|
| 239 |
+
|
| 240 |
+
# Volume Indicators
|
| 241 |
+
if show_obv:
|
| 242 |
+
indicators['OBV'] = OBV(data)
|
| 243 |
+
if show_adl:
|
| 244 |
+
indicators['ADL'] = ADL(data)
|
| 245 |
+
if show_chaikin:
|
| 246 |
+
indicators['Chaikin'] = CHAIKIN(data)
|
| 247 |
+
if show_efi:
|
| 248 |
+
indicators['EFI'] = EFI(data)
|
| 249 |
+
if show_emv:
|
| 250 |
+
indicators['EMV'] = EMV(data)
|
| 251 |
+
if show_mfi:
|
| 252 |
+
indicators['MFI'] = MFI(data)
|
| 253 |
+
if show_vpt:
|
| 254 |
+
indicators['VPT'] = VPT(data)
|
| 255 |
+
if show_fve:
|
| 256 |
+
indicators['FVE'] = FVE(data)
|
| 257 |
+
if show_vzo:
|
| 258 |
+
indicators['VZO'] = VZO(data)
|
| 259 |
+
|
| 260 |
+
# Volatility Indicators
|
| 261 |
+
if show_bollinger:
|
| 262 |
+
indicators['Bollinger'] = BOLLINGER(data, bb_period, bb_std)
|
| 263 |
+
if show_kc:
|
| 264 |
+
indicators['KC'] = KC(data)
|
| 265 |
+
if show_dc:
|
| 266 |
+
indicators['DC'] = DC(data)
|
| 267 |
+
if show_atr:
|
| 268 |
+
indicators['ATR'] = ATR(data)
|
| 269 |
+
if show_chandelier:
|
| 270 |
+
indicators['Chandelier'] = CHANDELIER(data)
|
| 271 |
+
if show_psar:
|
| 272 |
+
indicators['PSAR'] = PSAR(data)
|
| 273 |
+
if show_apz:
|
| 274 |
+
indicators['APZ'] = APZ(data)
|
| 275 |
+
|
| 276 |
+
# Oscillators
|
| 277 |
+
if show_adx:
|
| 278 |
+
indicators['ADX'] = ADX(data)
|
| 279 |
+
if show_cci:
|
| 280 |
+
indicators['CCI'] = CCI(data)
|
| 281 |
+
if show_fish:
|
| 282 |
+
indicators['Fisher'] = FISH(data)
|
| 283 |
+
if show_ao:
|
| 284 |
+
indicators['AO'] = AO(data)
|
| 285 |
+
if show_mi:
|
| 286 |
+
indicators['MI'] = MI(data)
|
| 287 |
+
if show_wto:
|
| 288 |
+
indicators['WTO'] = WTO(data)
|
| 289 |
+
if show_copp:
|
| 290 |
+
indicators['Coppock'] = COPP(data)
|
| 291 |
+
if show_ift_rsi:
|
| 292 |
+
indicators['IFT_RSI'] = IFT_RSI(data)
|
| 293 |
+
|
| 294 |
+
# Complex Indicators
|
| 295 |
+
if show_ichimoku:
|
| 296 |
+
indicators['Ichimoku'] = ICHIMOKU(data)
|
| 297 |
+
if show_pivot:
|
| 298 |
+
indicators['Pivot'] = PIVOT(data)
|
| 299 |
+
if show_pivot_fib:
|
| 300 |
+
indicators['Pivot_Fib'] = PIVOT_FIB(data)
|
| 301 |
+
if show_basp:
|
| 302 |
+
indicators['BASP'] = BASP(data)
|
| 303 |
+
if show_baspn:
|
| 304 |
+
indicators['BASPN'] = BASPN(data)
|
| 305 |
+
if show_dmi:
|
| 306 |
+
indicators['DMI'] = DMI(data)
|
| 307 |
+
if show_ebbp:
|
| 308 |
+
indicators['EBBP'] = EBBP(data)
|
| 309 |
+
|
| 310 |
+
# Create main price chart
|
| 311 |
+
fig = make_subplots(
|
| 312 |
+
rows=4, cols=1,
|
| 313 |
+
shared_xaxes=True,
|
| 314 |
+
vertical_spacing=0.05,
|
| 315 |
+
subplot_titles=('Price Chart', 'Volume', 'Oscillators', 'Additional Indicators'),
|
| 316 |
+
row_heights=[0.5, 0.2, 0.15, 0.15]
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
# Add candlestick chart
|
| 320 |
+
fig.add_trace(
|
| 321 |
+
go.Candlestick(
|
| 322 |
+
x=data.index,
|
| 323 |
+
open=data['Open'],
|
| 324 |
+
high=data['High'],
|
| 325 |
+
low=data['Low'],
|
| 326 |
+
close=data['Close'],
|
| 327 |
+
name='Price'
|
| 328 |
+
),
|
| 329 |
+
row=1, col=1
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
# Define colors for trend indicators to avoid repetition
|
| 333 |
+
colors = ["red", "yellow", "green", "purple", "orange", "brown", "pink", "gray", "cyan", "magenta"]
|
| 334 |
+
color_idx = 0
|
| 335 |
+
|
| 336 |
+
# Add trend indicators to price chart (row 1)
|
| 337 |
+
trend_indicators = ['SMA', 'EMA', 'HMA', 'WMA', 'KAMA', 'FRAMA', 'EVWMA', 'VWAP']
|
| 338 |
+
for name in trend_indicators:
|
| 339 |
+
if name in indicators:
|
| 340 |
+
fig.add_trace(
|
| 341 |
+
go.Scatter(
|
| 342 |
+
x=data.index,
|
| 343 |
+
y=indicators[name].fillna(method='ffill'), # Handle NaNs
|
| 344 |
+
mode='lines',
|
| 345 |
+
name=name,
|
| 346 |
+
line=dict(color=colors[color_idx % len(colors)])
|
| 347 |
+
),
|
| 348 |
+
row=1, col=1
|
| 349 |
+
)
|
| 350 |
+
color_idx += 1
|
| 351 |
+
|
| 352 |
+
# Add volatility indicators to price chart (row 1)
|
| 353 |
+
if 'Bollinger' in indicators:
|
| 354 |
+
bb = indicators['Bollinger']
|
| 355 |
+
fig.add_trace(
|
| 356 |
+
go.Scatter(
|
| 357 |
+
x=data.index,
|
| 358 |
+
y=bb['BB_UPPER'].fillna(method='ffill'),
|
| 359 |
+
mode='lines',
|
| 360 |
+
name='BB Upper',
|
| 361 |
+
line=dict(color='lightblue', dash='dash')
|
| 362 |
+
),
|
| 363 |
+
row=1, col=1
|
| 364 |
+
)
|
| 365 |
+
fig.add_trace(
|
| 366 |
+
go.Scatter(
|
| 367 |
+
x=data.index,
|
| 368 |
+
y=bb['BB_LOWER'].fillna(method='ffill'),
|
| 369 |
+
mode='lines',
|
| 370 |
+
name='BB Lower',
|
| 371 |
+
line=dict(color='lightblue', dash='dash'),
|
| 372 |
+
fill='tonexty',
|
| 373 |
+
fillcolor='rgba(173, 216, 230, 0.2)'
|
| 374 |
+
),
|
| 375 |
+
row=1, col=1
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
if 'KC' in indicators:
|
| 379 |
+
kc = indicators['KC']
|
| 380 |
+
fig.add_trace(
|
| 381 |
+
go.Scatter(x=data.index, y=kc['KC_UPPER'].fillna(method='ffill'), name='KC Upper', line=dict(color='orange')),
|
| 382 |
+
row=1, col=1
|
| 383 |
+
)
|
| 384 |
+
fig.add_trace(
|
| 385 |
+
go.Scatter(x=data.index, y=kc['KC_LOWER'].fillna(method='ffill'), name='KC Lower', line=dict(color='orange')),
|
| 386 |
+
row=1, col=1
|
| 387 |
+
)
|
| 388 |
+
fig.add_trace(
|
| 389 |
+
go.Scatter(x=data.index, y=kc['KC_MIDDLE'].fillna(method='ffill'), name='KC Middle', line=dict(color='gray', dash='dot')),
|
| 390 |
+
row=1, col=1
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
if 'DC' in indicators:
|
| 394 |
+
dc = indicators['DC']
|
| 395 |
+
fig.add_trace(
|
| 396 |
+
go.Scatter(x=data.index, y=dc['DC_U'].fillna(method='ffill'), name='DC Upper', line=dict(color='green')),
|
| 397 |
+
row=1, col=1
|
| 398 |
+
)
|
| 399 |
+
fig.add_trace(
|
| 400 |
+
go.Scatter(x=data.index, y=dc['DC_L'].fillna(method='ffill'), name='DC Lower', line=dict(color='green')),
|
| 401 |
+
row=1, col=1
|
| 402 |
+
)
|
| 403 |
+
fig.add_trace(
|
| 404 |
+
go.Scatter(x=data.index, y=dc['DC_M'].fillna(method='ffill'), name='DC Middle', line=dict(color='limegreen', dash='dot')),
|
| 405 |
+
row=1, col=1
|
| 406 |
+
)
|
| 407 |
+
|
| 408 |
+
if 'Chandelier' in indicators:
|
| 409 |
+
ce = indicators['Chandelier']
|
| 410 |
+
fig.add_trace(
|
| 411 |
+
go.Scatter(x=data.index, y=ce['CHANDELIER_Long'].fillna(method='ffill'), name='Chandelier Long', line=dict(color='darkred')),
|
| 412 |
+
row=1, col=1
|
| 413 |
+
)
|
| 414 |
+
fig.add_trace(
|
| 415 |
+
go.Scatter(x=data.index, y=ce['CHANDELIER_Short'].fillna(method='ffill'), name='Chandelier Short', line=dict(color='darkgreen')),
|
| 416 |
+
row=1, col=1
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
+
if 'APZ' in indicators:
|
| 420 |
+
apz = indicators['APZ']
|
| 421 |
+
fig.add_trace(
|
| 422 |
+
go.Scatter(x=data.index, y=apz['APZ_UPPER'].fillna(method='ffill'), name='APZ Upper', line=dict(color='orange', dash='dot')),
|
| 423 |
+
row=1, col=1
|
| 424 |
+
)
|
| 425 |
+
fig.add_trace(
|
| 426 |
+
go.Scatter(x=data.index, y=apz['APZ_LOWER'].fillna(method='ffill'), name='APZ Lower', line=dict(color='coral', dash='dot')),
|
| 427 |
+
row=1, col=1
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
if 'Ichimoku' in indicators:
|
| 431 |
+
ichimoku = indicators['Ichimoku']
|
| 432 |
+
fig.add_trace(
|
| 433 |
+
go.Scatter(x=data.index, y=ichimoku['TENKAN'].fillna(method='ffill'), name='Tenkan-sen', line=dict(color='blue')),
|
| 434 |
+
row=1, col=1
|
| 435 |
+
)
|
| 436 |
+
fig.add_trace(
|
| 437 |
+
go.Scatter(x=data.index, y=ichimoku['KIJUN'].fillna(method='ffill'), name='Kijun-sen', line=dict(color='red')),
|
| 438 |
+
row=1, col=1
|
| 439 |
+
)
|
| 440 |
+
fig.add_trace(
|
| 441 |
+
go.Scatter(x=data.index, y=ichimoku['SENKOU_A'].fillna(method='ffill'), name='Senkou A', line=dict(color='green')),
|
| 442 |
+
row=1, col=1
|
| 443 |
+
)
|
| 444 |
+
fig.add_trace(
|
| 445 |
+
go.Scatter(x=data.index, y=ichimoku['SENKOU_B'].fillna(method='ffill'), name='Senkou B', line=dict(color='red'), fill='tonexty', fillcolor='rgba(0, 255, 0, 0.2)'),
|
| 446 |
+
row=1, col=1
|
| 447 |
+
)
|
| 448 |
+
fig.add_trace(
|
| 449 |
+
go.Scatter(x=data.index, y=ichimoku['CHIKOU'].fillna(method='ffill'), name='Chikou Span', line=dict(color='purple')),
|
| 450 |
+
row=1, col=1
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
if 'Pivot' in indicators:
|
| 454 |
+
pivot = indicators['Pivot']
|
| 455 |
+
for col in ['pivot', 'r1', 'r2', 'r3', 's1', 's2', 's3']:
|
| 456 |
+
fig.add_trace(
|
| 457 |
+
go.Scatter(x=data.index, y=pivot[col].fillna(method='ffill'), name=f'Pivot {col.upper()}', line=dict(dash='dash')),
|
| 458 |
+
row=1, col=1
|
| 459 |
+
)
|
| 460 |
+
|
| 461 |
+
if 'Pivot_Fib' in indicators:
|
| 462 |
+
pivot_fib = indicators['Pivot_Fib']
|
| 463 |
+
for col in ['pivot', 'r1', 'r2', 'r3', 's1', 's2', 's3']:
|
| 464 |
+
fig.add_trace(
|
| 465 |
+
go.Scatter(x=data.index, y=pivot_fib[col].fillna(method='ffill'), name=f'Fib Pivot {col.upper()}', line=dict(dash='dot')),
|
| 466 |
+
row=1, col=1
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
if 'PSAR' in indicators:
|
| 470 |
+
psar = indicators['PSAR']
|
| 471 |
+
fig.add_trace(
|
| 472 |
+
go.Scatter(x=data.index, y=psar['psar'].fillna(method='ffill'), name='PSAR', mode='markers', marker=dict(size=5, color='blue')),
|
| 473 |
+
row=1, col=1
|
| 474 |
+
)
|
| 475 |
+
fig.add_trace(
|
| 476 |
+
go.Scatter(x=data.index, y=psar['psarbull'].fillna(method='ffill'), name='PSAR Bull', mode='markers', marker=dict(size=5, color='green')),
|
| 477 |
+
row=1, col=1
|
| 478 |
+
)
|
| 479 |
+
fig.add_trace(
|
| 480 |
+
go.Scatter(x=data.index, y=psar['psarbear'].fillna(method='ffill'), name='PSAR Bear', mode='markers', marker=dict(size=5, color='red')),
|
| 481 |
+
row=1, col=1
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
# Add volume (row 2)
|
| 485 |
+
fig.add_trace(
|
| 486 |
+
go.Bar(
|
| 487 |
+
x=data.index,
|
| 488 |
+
y=data['Volume'],
|
| 489 |
+
name='Volume',
|
| 490 |
+
marker_color='lightblue'
|
| 491 |
+
),
|
| 492 |
+
row=2, col=1
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
+
# Add oscillators to row 3
|
| 496 |
+
if 'RSI' in indicators:
|
| 497 |
+
fig.add_trace(
|
| 498 |
+
go.Scatter(x=data.index, y=indicators['RSI'].fillna(method='ffill'), mode='lines', name='RSI', line=dict(color='purple')),
|
| 499 |
+
row=3, col=1
|
| 500 |
+
)
|
| 501 |
+
fig.add_hline(y=70, line_dash="dash", line_color="red", row=3, col=1)
|
| 502 |
+
fig.add_hline(y=30, line_dash="dash", line_color="green", row=3, col=1)
|
| 503 |
+
|
| 504 |
+
if 'StochRSI' in indicators:
|
| 505 |
+
fig.add_trace(
|
| 506 |
+
go.Scatter(x=data.index, y=indicators['StochRSI'].fillna(method='ffill'), mode='lines', name='StochRSI', line=dict(color='orange')),
|
| 507 |
+
row=3, col=1
|
| 508 |
+
)
|
| 509 |
+
fig.add_hline(y=80, line_dash="dash", line_color="red", row=3, col=1)
|
| 510 |
+
fig.add_hline(y=20, line_dash="dash", line_color="green", row=3, col=1)
|
| 511 |
+
|
| 512 |
+
if 'CCI' in indicators:
|
| 513 |
+
fig.add_trace(
|
| 514 |
+
go.Scatter(x=data.index, y=indicators['CCI'].fillna(method='ffill'), mode='lines', name='CCI', line=dict(color='blue')),
|
| 515 |
+
row=3, col=1
|
| 516 |
+
)
|
| 517 |
+
fig.add_hline(y=100, line_dash="dash", line_color="red", row=3, col=1)
|
| 518 |
+
fig.add_hline(y=-100, line_dash="dash", line_color="green", row=3, col=1)
|
| 519 |
+
|
| 520 |
+
if 'ADX' in indicators:
|
| 521 |
+
fig.add_trace(
|
| 522 |
+
go.Scatter(x=data.index, y=indicators['ADX'].fillna(method='ffill'), mode='lines', name='ADX', line=dict(color='cyan')),
|
| 523 |
+
row=3, col=1
|
| 524 |
+
)
|
| 525 |
+
fig.add_hline(y=25, line_dash="dash", line_color="gray", row=3, col=1)
|
| 526 |
+
|
| 527 |
+
if 'Fisher' in indicators:
|
| 528 |
+
fig.add_trace(
|
| 529 |
+
go.Scatter(x=data.index, y=indicators['Fisher'].fillna(method='ffill'), mode='lines', name='Fisher Transform', line=dict(color='magenta')),
|
| 530 |
+
row=3, col=1
|
| 531 |
+
)
|
| 532 |
+
|
| 533 |
+
if 'AO' in indicators:
|
| 534 |
+
fig.add_trace(
|
| 535 |
+
go.Scatter(x=data.index, y=indicators['AO'].fillna(method='ffill'), mode='lines', name='Awesome Oscillator', line=dict(color='green')),
|
| 536 |
+
row=3, col=1
|
| 537 |
+
)
|
| 538 |
+
fig.add_hline(y=0, line_dash="dash", line_color="gray", row=3, col=1)
|
| 539 |
+
|
| 540 |
+
if 'MI' in indicators:
|
| 541 |
+
fig.add_trace(
|
| 542 |
+
go.Scatter(x=data.index, y=indicators['MI'].fillna(method='ffill'), mode='lines', name='Mass Index', line=dict(color='purple')),
|
| 543 |
+
row=3, col=1
|
| 544 |
+
)
|
| 545 |
+
fig.add_hline(y=27, line_dash="dash", line_color="red", row=3, col=1)
|
| 546 |
+
|
| 547 |
+
if 'IFT_RSI' in indicators:
|
| 548 |
+
fig.add_trace(
|
| 549 |
+
go.Scatter(x=data.index, y=indicators['IFT_RSI'].fillna(method='ffill'), mode='lines', name='IFT RSI', line=dict(color='orange')),
|
| 550 |
+
row=3, col=1
|
| 551 |
+
)
|
| 552 |
+
|
| 553 |
+
# Add momentum and volume indicators to row 4
|
| 554 |
+
if 'MACD' in indicators:
|
| 555 |
+
macd = indicators['MACD']
|
| 556 |
+
macd_line = macd['MACD']
|
| 557 |
+
signal_line = macd['SIGNAL']
|
| 558 |
+
macd_histogram = macd_line - signal_line
|
| 559 |
+
fig.add_trace(
|
| 560 |
+
go.Scatter(x=data.index, y=macd_line.fillna(method='ffill'), mode='lines', name='MACD', line=dict(color='#04c6fc')),
|
| 561 |
+
row=4, col=1
|
| 562 |
+
)
|
| 563 |
+
fig.add_trace(
|
| 564 |
+
go.Scatter(x=data.index, y=signal_line.fillna(method='ffill'), mode='lines', name='MACD Signal', line=dict(color='blue', dash='dash')),
|
| 565 |
+
row=4, col=1
|
| 566 |
+
)
|
| 567 |
+
fig.add_trace(
|
| 568 |
+
go.Bar(x=data.index, y=macd_histogram.fillna(0), name='MACD Histogram', marker_color=['green' if val >= 0 else 'red' for val in macd_histogram]),
|
| 569 |
+
row=4, col=1
|
| 570 |
+
)
|
| 571 |
+
|
| 572 |
+
if 'TSI' in indicators:
|
| 573 |
+
tsi = indicators['TSI']
|
| 574 |
+
fig.add_trace(
|
| 575 |
+
go.Scatter(x=data.index, y=tsi['TSI'].fillna(method='ffill'), name='TSI', line=dict(color='blue')),
|
| 576 |
+
row=4, col=1
|
| 577 |
+
)
|
| 578 |
+
fig.add_trace(
|
| 579 |
+
go.Scatter(x=data.index, y=tsi['signal'].fillna(method='ffill'), name='TSI Signal', line=dict(color='blue', dash='dash')),
|
| 580 |
+
row=4, col=1
|
| 581 |
+
)
|
| 582 |
+
|
| 583 |
+
if 'KST' in indicators:
|
| 584 |
+
kst = indicators['KST']
|
| 585 |
+
fig.add_trace(
|
| 586 |
+
go.Scatter(x=data.index, y=kst['KST'].fillna(method='ffill'), name='KST', line=dict(color='purple')),
|
| 587 |
+
row=4, col=1
|
| 588 |
+
)
|
| 589 |
+
fig.add_trace(
|
| 590 |
+
go.Scatter(x=data.index, y=kst['signal'].fillna(method='ffill'), name='KST Signal', line=dict(color='purple', dash='dot')),
|
| 591 |
+
row=4, col=1
|
| 592 |
+
)
|
| 593 |
+
|
| 594 |
+
if 'PPO' in indicators:
|
| 595 |
+
ppo = indicators['PPO']
|
| 596 |
+
fig.add_trace(
|
| 597 |
+
go.Scatter(x=data.index, y=ppo['PPO'].fillna(method='ffill'), name='PPO', line=dict(color='cyan')),
|
| 598 |
+
row=4, col=1
|
| 599 |
+
)
|
| 600 |
+
fig.add_trace(
|
| 601 |
+
go.Scatter(x=data.index, y=ppo['PPO_signal'].fillna(method='ffill'), name='PPO Signal', line=dict(color='cyan', dash='dash')),
|
| 602 |
+
row=4, col=1
|
| 603 |
+
)
|
| 604 |
+
fig.add_trace(
|
| 605 |
+
go.Bar(x=data.index, y=ppo['PPO_histo'].fillna(0), name='PPO Histogram', marker_color=['green' if val >= 0 else 'red' for val in ppo['PPO_histo']]),
|
| 606 |
+
row=4, col=1
|
| 607 |
+
)
|
| 608 |
+
|
| 609 |
+
if 'CMO' in indicators:
|
| 610 |
+
fig.add_trace(
|
| 611 |
+
go.Scatter(x=data.index, y=indicators['CMO'].fillna(method='ffill'), name='CMO', line=dict(color='orange')),
|
| 612 |
+
row=4, col=1
|
| 613 |
+
)
|
| 614 |
+
fig.add_hline(y=50, line_dash="dash", line_color="red", row=4, col=1)
|
| 615 |
+
fig.add_hline(y=-50, line_dash="dash", line_color="green", row=4, col=1)
|
| 616 |
+
|
| 617 |
+
if 'ROC' in indicators:
|
| 618 |
+
fig.add_trace(
|
| 619 |
+
go.Scatter(x=data.index, y=indicators['ROC'].fillna(method='ffill'), name='ROC', line=dict(color='green')),
|
| 620 |
+
row=4, col=1
|
| 621 |
+
)
|
| 622 |
+
fig.add_hline(y=0, line_dash="dash", line_color="gray", row=4, col=1)
|
| 623 |
+
|
| 624 |
+
if 'UO' in indicators:
|
| 625 |
+
fig.add_trace(
|
| 626 |
+
go.Scatter(x=data.index, y=indicators['UO'].fillna(method='ffill'), name='Ultimate Oscillator', line=dict(color='purple')),
|
| 627 |
+
row=4, col=1
|
| 628 |
+
)
|
| 629 |
+
fig.add_hline(y=70, line_dash="dash", line_color="red", row=4, col=1)
|
| 630 |
+
fig.add_hline(y=30, line_dash="dash", line_color="green", row=4, col=1)
|
| 631 |
+
|
| 632 |
+
if 'OBV' in indicators:
|
| 633 |
+
fig.add_trace(
|
| 634 |
+
go.Scatter(x=data.index, y=indicators['OBV'].fillna(method='ffill'), name='OBV', line=dict(color='blue')),
|
| 635 |
+
row=4, col=1
|
| 636 |
+
)
|
| 637 |
+
|
| 638 |
+
if 'ADL' in indicators:
|
| 639 |
+
fig.add_trace(
|
| 640 |
+
go.Scatter(x=data.index, y=indicators['ADL'].fillna(method='ffill'), name='ADL', line=dict(color='cyan')),
|
| 641 |
+
row=4, col=1
|
| 642 |
+
)
|
| 643 |
+
|
| 644 |
+
if 'EFI' in indicators:
|
| 645 |
+
fig.add_trace(
|
| 646 |
+
go.Scatter(x=data.index, y=indicators['EFI'].fillna(method='ffill'), name='EFI', line=dict(color='magenta')),
|
| 647 |
+
row=4, col=1
|
| 648 |
+
)
|
| 649 |
+
|
| 650 |
+
if 'EMV' in indicators:
|
| 651 |
+
fig.add_trace(
|
| 652 |
+
go.Scatter(x=data.index, y=indicators['EMV'].fillna(method='ffill'), name='EMV', line=dict(color='orange')),
|
| 653 |
+
row=4, col=1
|
| 654 |
+
)
|
| 655 |
+
|
| 656 |
+
if 'MFI' in indicators:
|
| 657 |
+
fig.add_trace(
|
| 658 |
+
go.Scatter(x=data.index, y=indicators['MFI'].fillna(method='ffill'), name='MFI', line=dict(color='blue')),
|
| 659 |
+
row=4, col=1
|
| 660 |
+
)
|
| 661 |
+
fig.add_hline(y=80, line_dash="dash", line_color="red", row=4, col=1)
|
| 662 |
+
fig.add_hline(y=20, line_dash="dash", line_color="green", row=4, col=1)
|
| 663 |
+
|
| 664 |
+
if 'VPT' in indicators:
|
| 665 |
+
fig.add_trace(
|
| 666 |
+
go.Scatter(x=data.index, y=indicators['VPT'].fillna(method='ffill'), name='VPT', line=dict(color='blue', dash='dot')),
|
| 667 |
+
row=4, col=1
|
| 668 |
+
)
|
| 669 |
+
|
| 670 |
+
if 'FVE' in indicators:
|
| 671 |
+
fig.add_trace(
|
| 672 |
+
go.Scatter(x=data.index, y=indicators['FVE'].fillna(method='ffill'), name='FVE', line=dict(color='blue', dash='dot')),
|
| 673 |
+
row=4, col=1
|
| 674 |
+
)
|
| 675 |
+
|
| 676 |
+
if 'VZO' in indicators:
|
| 677 |
+
fig.add_trace(
|
| 678 |
+
go.Scatter(x=data.index, y=indicators['VZO'].fillna(method='ffill'), name='VZO', line=dict(color='blue', dash='dot')),
|
| 679 |
+
row=4, col=1
|
| 680 |
+
)
|
| 681 |
+
fig.add_hline(y=40, line_dash="dash", line_color="green", row=4, col=1)
|
| 682 |
+
fig.add_hline(y=5, line_dash="dash", line_color="red", row=4, col=1)
|
| 683 |
+
fig.add_hline(y=-5, line_dash="dash", line_color="red", row=4, col=1)
|
| 684 |
+
fig.add_hline(y=-40, line_dash="dash", line_color="green", row=4, col=1)
|
| 685 |
+
|
| 686 |
+
if 'WTO' in indicators:
|
| 687 |
+
wto = indicators['WTO']
|
| 688 |
+
fig.add_trace(
|
| 689 |
+
go.Scatter(x=data.index, y=wto['WT1'].fillna(method='ffill'), name='WTO WT1', line=dict(color='cyan')),
|
| 690 |
+
row=4, col=1
|
| 691 |
+
)
|
| 692 |
+
fig.add_trace(
|
| 693 |
+
go.Scatter(x=data.index, y=wto['WT2'].fillna(method='ffill'), name='WTO WT2', line=dict(color='cyan', dash='dash')),
|
| 694 |
+
row=4, col=1
|
| 695 |
+
)
|
| 696 |
+
|
| 697 |
+
if 'Coppock' in indicators:
|
| 698 |
+
fig.add_trace(
|
| 699 |
+
go.Scatter(x=data.index, y=indicators['Coppock'].fillna(method='ffill'), name='Coppock Curve', line=dict(color='purple')),
|
| 700 |
+
row=4, col=1
|
| 701 |
+
)
|
| 702 |
+
fig.add_hline(y=0, line_dash="dash", line_color="gray", row=4, col=1)
|
| 703 |
+
|
| 704 |
+
if 'BASP' in indicators:
|
| 705 |
+
basp = indicators['BASP']
|
| 706 |
+
fig.add_trace(
|
| 707 |
+
go.Scatter(x=data.index, y=basp['Buy'].fillna(method='ffill'), name='BASP Buy', line=dict(color='green')),
|
| 708 |
+
row=4, col=1
|
| 709 |
+
)
|
| 710 |
+
fig.add_trace(
|
| 711 |
+
go.Scatter(x=data.index, y=basp['Sell'].fillna(method='ffill'), name='BASP Sell', line=dict(color='red')),
|
| 712 |
+
row=4, col=1
|
| 713 |
+
)
|
| 714 |
+
|
| 715 |
+
if 'BASPN' in indicators:
|
| 716 |
+
baspn = indicators['BASPN']
|
| 717 |
+
fig.add_trace(
|
| 718 |
+
go.Scatter(x=data.index, y=baspn['BASPN_Buy'].fillna(method='ffill'), name='BASPN Buy', line=dict(color='limegreen')),
|
| 719 |
+
row=4, col=1
|
| 720 |
+
)
|
| 721 |
+
fig.add_trace(
|
| 722 |
+
go.Scatter(x=data.index, y=baspn['BASPN_Sell'].fillna(method='ffill'), name='BASPN Sell', line=dict(color='coral')),
|
| 723 |
+
row=4, col=1
|
| 724 |
+
)
|
| 725 |
+
|
| 726 |
+
if 'DMI' in indicators:
|
| 727 |
+
dmi = indicators['DMI']
|
| 728 |
+
fig.add_trace(
|
| 729 |
+
go.Scatter(x=data.index, y=dmi['+DI'].fillna(method='ffill'), name='+DI', line=dict(color='blue')),
|
| 730 |
+
row=4, col=1
|
| 731 |
+
)
|
| 732 |
+
fig.add_trace(
|
| 733 |
+
go.Scatter(x=data.index, y=dmi['-DI'].fillna(method='ffill'), name='-DI', line=dict(color='red')),
|
| 734 |
+
row=4, col=1
|
| 735 |
+
)
|
| 736 |
+
|
| 737 |
+
if 'EBBP' in indicators:
|
| 738 |
+
ebbp = indicators['EBBP']
|
| 739 |
+
fig.add_trace(
|
| 740 |
+
go.Scatter(x=data.index, y=ebbp['Bull'].fillna(method='ffill'), name='Bull Power', line=dict(color='green')),
|
| 741 |
+
row=4, col=1
|
| 742 |
+
)
|
| 743 |
+
fig.add_trace(
|
| 744 |
+
go.Scatter(x=data.index, y=ebbp['Bear'].fillna(method='ffill'), name='Bear Power', line=dict(color='red')),
|
| 745 |
+
row=4, col=1
|
| 746 |
+
)
|
| 747 |
+
|
| 748 |
+
if 'ATR' in indicators:
|
| 749 |
+
fig.add_trace(
|
| 750 |
+
go.Scatter(x=data.index, y=indicators['ATR'].fillna(method='ffill'), name='ATR', line=dict(color='blue')),
|
| 751 |
+
row=4, col=1
|
| 752 |
+
)
|
| 753 |
+
|
| 754 |
+
# Update layout
|
| 755 |
+
fig.update_layout(
|
| 756 |
+
title=f'{symbol.upper()} - Technical Analysis',
|
| 757 |
+
xaxis_rangeslider_visible=False,
|
| 758 |
+
height=800,
|
| 759 |
+
showlegend=True
|
| 760 |
+
)
|
| 761 |
+
|
| 762 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 763 |
+
|
| 764 |
+
# Display indicator values in tabs
|
| 765 |
+
st.subheader("π Indicator Values")
|
| 766 |
+
|
| 767 |
+
# Create tabs for different categories
|
| 768 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(["Trend", "Momentum", "Volume", "Volatility", "Oscillators"])
|
| 769 |
+
|
| 770 |
+
with tab1:
|
| 771 |
+
st.markdown("### Trend Indicators")
|
| 772 |
+
trend_cols = st.columns(3)
|
| 773 |
+
col_idx = 0
|
| 774 |
+
|
| 775 |
+
for name, indicator in indicators.items():
|
| 776 |
+
if name in ['SMA', 'EMA', 'HMA', 'WMA', 'KAMA', 'FRAMA', 'EVWMA', 'VWAP']:
|
| 777 |
+
with trend_cols[col_idx % 3]:
|
| 778 |
+
if isinstance(indicator, pd.Series):
|
| 779 |
+
st.metric(name, f"{indicator.iloc[-1]:.2f}")
|
| 780 |
+
col_idx += 1
|
| 781 |
+
|
| 782 |
+
with tab2:
|
| 783 |
+
st.markdown("### Momentum Indicators")
|
| 784 |
+
momentum_cols = st.columns(3)
|
| 785 |
+
col_idx = 0
|
| 786 |
+
|
| 787 |
+
for name, indicator in indicators.items():
|
| 788 |
+
if name in ['RSI', 'StochRSI', 'CMO', 'ROC', 'UO']:
|
| 789 |
+
with momentum_cols[col_idx % 3]:
|
| 790 |
+
if isinstance(indicator, pd.Series):
|
| 791 |
+
st.metric(name, f"{indicator.iloc[-1]:.2f}")
|
| 792 |
+
col_idx += 1
|
| 793 |
+
|
| 794 |
+
with tab3:
|
| 795 |
+
st.markdown("### Volume Indicators")
|
| 796 |
+
volume_cols = st.columns(3)
|
| 797 |
+
col_idx = 0
|
| 798 |
+
|
| 799 |
+
for name, indicator in indicators.items():
|
| 800 |
+
if name in ['OBV', 'ADL', 'EFI', 'EMV', 'MFI', 'VPT', 'FVE', 'VZO']:
|
| 801 |
+
with volume_cols[col_idx % 3]:
|
| 802 |
+
if isinstance(indicator, pd.Series):
|
| 803 |
+
st.metric(name, f"{indicator.iloc[-1]:.2f}")
|
| 804 |
+
col_idx += 1
|
| 805 |
+
|
| 806 |
+
with tab4:
|
| 807 |
+
st.markdown("### Volatility Indicators")
|
| 808 |
+
volatility_cols = st.columns(3)
|
| 809 |
+
col_idx = 0
|
| 810 |
+
|
| 811 |
+
for name, indicator in indicators.items():
|
| 812 |
+
if name in ['ATR', 'PSAR']:
|
| 813 |
+
with volatility_cols[col_idx % 3]:
|
| 814 |
+
if isinstance(indicator, pd.Series):
|
| 815 |
+
st.metric(name, f"{indicator.iloc[-1]:.2f}")
|
| 816 |
+
col_idx += 1
|
| 817 |
+
|
| 818 |
+
with tab5:
|
| 819 |
+
st.markdown("### Oscillators")
|
| 820 |
+
osc_cols = st.columns(3)
|
| 821 |
+
col_idx = 0
|
| 822 |
+
|
| 823 |
+
for name, indicator in indicators.items():
|
| 824 |
+
if name in ['ADX', 'CCI', 'Fisher', 'AO', 'MI']:
|
| 825 |
+
with osc_cols[col_idx % 3]:
|
| 826 |
+
if isinstance(indicator, pd.Series):
|
| 827 |
+
st.metric(name, f"{indicator.iloc[-1]:.2f}")
|
| 828 |
+
col_idx += 1
|
| 829 |
+
|
| 830 |
+
# Raw data section
|
| 831 |
+
with st.expander("π Raw Data"):
|
| 832 |
+
st.dataframe(data.tail(50))
|
| 833 |
+
|
| 834 |
+
# Download section
|
| 835 |
+
st.subheader("πΎ Download Data")
|
| 836 |
+
|
| 837 |
+
# Combine all indicators into one DataFrame
|
| 838 |
+
combined_df = data.copy()
|
| 839 |
+
for name, indicator in indicators.items():
|
| 840 |
+
if isinstance(indicator, pd.Series):
|
| 841 |
+
combined_df[name] = indicator
|
| 842 |
+
elif isinstance(indicator, pd.DataFrame):
|
| 843 |
+
for col in indicator.columns:
|
| 844 |
+
combined_df[f"{name}_{col}"] = indicator[col]
|
| 845 |
+
|
| 846 |
+
csv = combined_df.to_csv()
|
| 847 |
+
st.download_button(
|
| 848 |
+
label="Download CSV",
|
| 849 |
+
data=csv,
|
| 850 |
+
file_name=f'{symbol}_technical_analysis.csv',
|
| 851 |
+
mime='text/csv'
|
| 852 |
+
)
|
| 853 |
+
|
| 854 |
+
except Exception as e:
|
| 855 |
+
st.error(f"An error occurred: {str(e)}")
|
| 856 |
+
st.error("Please check your internet connection and try again.")
|
| 857 |
+
|
| 858 |
+
# Instructions
|
| 859 |
+
else:
|
| 860 |
+
st.markdown("""
|
| 861 |
+
## π How to Use This Dashboard
|
| 862 |
+
|
| 863 |
+
1. **Enter a stock symbol** in the sidebar (e.g., AAPL, GOOGL, MSFT) for Indian Stocks, use NSE symbols like RELIANCE.NS
|
| 864 |
+
or BHEL.NS.
|
| 865 |
+
2. **Select time period and interval** for the data
|
| 866 |
+
3. **Choose technical indicators** you want to analyze
|
| 867 |
+
4. **Adjust parameters** for the indicators
|
| 868 |
+
5. **Click "Analyze Stock"** to generate the analysis
|
| 869 |
+
|
| 870 |
+
### π Available Indicators
|
| 871 |
+
|
| 872 |
+
This dashboard includes **40+ technical indicators** across multiple categories:
|
| 873 |
+
|
| 874 |
+
- **Trend Indicators**: SMA, EMA, HMA, WMA, KAMA, FRAMA, EVWMA, VWAP
|
| 875 |
+
- **Momentum Indicators**: RSI, MACD, Stochastic RSI, CMO, ROC, TSI, KST, PPO, UO
|
| 876 |
+
- **Volume Indicators**: OBV, ADL, Chaikin Oscillator, EFI, EMV, MFI, VPT, FVE, VZO
|
| 877 |
+
- **Volatility Indicators**: Bollinger Bands, Keltner Channels, Donchian Channels, ATR, Chandelier Exit, Parabolic SAR
|
| 878 |
+
- **Oscillators**: ADX, CCI, Fisher Transform, Awesome Oscillator, Mass Index, Wave Trend Oscillator
|
| 879 |
+
- **Complex Indicators**: Ichimoku Cloud, Pivot Points, Fibonacci Pivots, BASP, DMI, Elder Bull/Bear Power
|
| 880 |
+
|
| 881 |
+
### π‘ Tips
|
| 882 |
+
|
| 883 |
+
- Use multiple indicators together for better analysis
|
| 884 |
+
- Adjust parameters based on your trading timeframe
|
| 885 |
+
- Download the data for further analysis
|
| 886 |
+
- Check different time periods to understand trends
|
| 887 |
+
""")
|
| 888 |
+
|
| 889 |
+
# Footer
|
| 890 |
+
st.markdown("---")
|
| 891 |
+
st.markdown("**Technical Analysis Dashboard** | Built with Streamlit & Python | Data from Yahoo Finance")
|
| 892 |
+
st.markdown("---")
|
| 893 |
+
st.markdown("**Made By Zane Vijay Falcao**")
|