Dmitry Beresnev commited on
Commit ·
7b70d02
1
Parent(s): a3e694b
add app
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import streamlit as stimport pandas as pdimport plotly.graph_objects as gofrom openbb_terminal.sdk import openbbfrom dotenv import load_dotenvimport os
load_dotenv()token = os.getenv("OPENBB_TOKEN")if token: openbb.account.login(token)
st.title("TradingView + OpenBB Indicators Dashboard")
symbol = st.text_input("Ticker", "AAPL")period = st.slider("SMA/EMA/RSI period", 5, 50, 20)
if st.button("Load Dashboard"):
# Load free stock data via OpenBB df = openbb.stocks.load(symbol)
# ---- Technical Indicators ---- df["SMA"] = df["close"].rolling(period).mean() df["EMA"] = df["close"].ewm(span=period, adjust=False).mean() delta = df["close"].diff() gain = delta.clip(lower=0) loss = -1 * delta.clip(upper=0) avg_gain = gain.rolling(period).mean() avg_loss = loss.rolling(period).mean() rs = avg_gain / avg_loss df["RSI"] = 100 - (100 / (1 + rs))
# ---- Tabs ---- tab1, tab2, tab3 = st.tabs(["TradingView", "Price + SMA/EMA", "RSI"])
# ---- Tab 1: Interactive TradingView ---- with tab1: tradingview_html = f""" <div class="tradingview-widget-container"> <div id="tradingview_{symbol}"></div> <script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script> <script type="text/javascript"> new TradingView.widget({{ "width": "100%", "height": 600, "symbol": "{symbol}", "interval": "D", "timezone": "Etc/UTC", "theme": "light", "style": "1", "locale": "en", "toolbar_bg": "#f1f3f6", "enable_publishing": false, "allow_symbol_change": true, "container_id": "tradingview_{symbol}" }}); </script> </div> """ st.components.v1.html(tradingview_html, height=650)
# ---- Tab 2: Price + SMA/EMA ---- with tab2: fig = go.Figure() fig.add_trace(go.Scatter(x=df.index, y=df["close"], name="Close")) fig.add_trace(go.Scatter(x=df.index, y=df["SMA"], name=f"SMA {period}"))app/main.pyAdded+67