Update pages/candlestick_patterns.py
Browse files- pages/candlestick_patterns.py +24 -21
pages/candlestick_patterns.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
-
import mplfinance as mpf
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
import yfinance as yf
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
-
from
|
|
|
|
| 9 |
|
| 10 |
-
# β
Import local
|
| 11 |
from utils.patterns import identify_patterns, calculate_technical_indicators
|
| 12 |
from utils.predictions import predict_movement
|
| 13 |
from utils.trading import fetch_market_data, is_market_open
|
|
@@ -28,19 +28,14 @@ status_color = "π’" if market_open else "π΄"
|
|
| 28 |
market_status = "Market Open" if market_open else "Market Closed"
|
| 29 |
st.sidebar.write(f"{status_color} {market_status}")
|
| 30 |
|
| 31 |
-
# β
**User Inputs
|
| 32 |
-
symbol = st.sidebar.text_input("Enter Stock Symbol", value="AAPL"
|
| 33 |
-
timeframe = st.sidebar.selectbox(
|
| 34 |
-
"Select Timeframe",
|
| 35 |
-
["30m", "1h", "2h", "4h"],
|
| 36 |
-
index=0
|
| 37 |
-
)
|
| 38 |
|
| 39 |
-
# β
**Auto-refresh
|
| 40 |
auto_refresh = st.sidebar.checkbox("Auto-refresh Data", value=True)
|
| 41 |
if auto_refresh:
|
| 42 |
-
st.
|
| 43 |
-
st.rerun() # β
Corrected (Replaces deprecated `st.experimental_rerun()`)
|
| 44 |
|
| 45 |
# π **Main Title**
|
| 46 |
st.title("π Candlestick Pattern & Trading Analysis")
|
|
@@ -58,15 +53,23 @@ try:
|
|
| 58 |
st.subheader(f"Candlestick Chart for {symbol}")
|
| 59 |
|
| 60 |
fig, ax = plt.subplots(figsize=(12, 6))
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
| 69 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
st.pyplot(fig)
|
| 71 |
|
| 72 |
# β
**Pattern Analysis**
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
import yfinance as yf
|
| 6 |
from datetime import datetime, timedelta
|
| 7 |
+
from mplfinance.original_flavor import candlestick_ohlc
|
| 8 |
+
import matplotlib.dates as mdates
|
| 9 |
|
| 10 |
+
# β
Import local functions
|
| 11 |
from utils.patterns import identify_patterns, calculate_technical_indicators
|
| 12 |
from utils.predictions import predict_movement
|
| 13 |
from utils.trading import fetch_market_data, is_market_open
|
|
|
|
| 28 |
market_status = "Market Open" if market_open else "Market Closed"
|
| 29 |
st.sidebar.write(f"{status_color} {market_status}")
|
| 30 |
|
| 31 |
+
# β
**User Inputs**
|
| 32 |
+
symbol = st.sidebar.text_input("Enter Stock Symbol", value="AAPL")
|
| 33 |
+
timeframe = st.sidebar.selectbox("Select Timeframe", ["30m", "1h", "2h", "4h"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# β
**Auto-refresh**
|
| 36 |
auto_refresh = st.sidebar.checkbox("Auto-refresh Data", value=True)
|
| 37 |
if auto_refresh:
|
| 38 |
+
st.rerun()
|
|
|
|
| 39 |
|
| 40 |
# π **Main Title**
|
| 41 |
st.title("π Candlestick Pattern & Trading Analysis")
|
|
|
|
| 53 |
st.subheader(f"Candlestick Chart for {symbol}")
|
| 54 |
|
| 55 |
fig, ax = plt.subplots(figsize=(12, 6))
|
| 56 |
+
df_ohlc = df.copy()
|
| 57 |
+
df_ohlc['Date'] = df_ohlc.index.map(mdates.date2num)
|
| 58 |
+
|
| 59 |
+
candlestick_ohlc(
|
| 60 |
+
ax,
|
| 61 |
+
df_ohlc[['Date', 'Open', 'High', 'Low', 'Close']].values,
|
| 62 |
+
width=0.0005, # Adjust candle width
|
| 63 |
+
colorup='g',
|
| 64 |
+
colordown='r'
|
| 65 |
)
|
| 66 |
+
|
| 67 |
+
ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
|
| 68 |
+
plt.xlabel("Time")
|
| 69 |
+
plt.ylabel("Price")
|
| 70 |
+
plt.title(f"{symbol} - {timeframe} Candlestick Chart")
|
| 71 |
+
plt.grid(True)
|
| 72 |
+
|
| 73 |
st.pyplot(fig)
|
| 74 |
|
| 75 |
# β
**Pattern Analysis**
|