📈 Chart Data Flow - grafico.html | TradingView-Style Technical Analysis

📊 Advanced Charting System: This diagram shows how market price data is transformed into professional-grade candlestick charts with multiple technical indicators using TradingView's Lightweight Charts library.
PHASE 1: TWO-STAGE DATA PIPELINE
Every 5min
⚙️ Lambda Price Collector
Advanced market data processing
market_price_collector.py: - Fetches top BUY/SELL offers from Binance - Modified Z-score outlier detection - Simple average of filtered offers - Handles time gaps and missing data
→
🗄️ DynamoDB Storage
Raw price data repository
Table: crypto_market_prices - Individual price data points - Timestamp-indexed records - Source for candle building - Analytics and backup
→
Triggered
📊 Lambda Candle Builder
OHLC candle construction
candle_builder.py: - Reads price data from DynamoDB - Aggregates into OHLC candles - Multiple timeframes (15m, 1h, 4h, etc.) - Builds complete candle dataset
→
☁️ S3 JSON Storage
Chart-ready data file
s3://bucket/market_price_data.json { "data_point": { "price": 13.25, "timestamp_epoch": ... }, "candles": { "15m": [...], "30m": [...], "1h": [...], "4h": [...], "12h": [...], "1d": [...], "1w": [...] } }
→
⚙️ Data Loader Module
JavaScript S3 file reader
data-loader.js: - fetch('s3-url/market_price_data.json') - formatCandleData() transforms to chart format - getCurrentPrice() extracts latest price - setTimeframe() switches intervals
PHASE 2: CHART LIBRARY SETUP
📊 TradingView Lightweight Charts
Professional charting library
chart-init.js: - LightweightCharts.createChart() - 3 synchronized charts: Main, RSI, MACD - Dark theme with Bolivia timezone - Candlestick series configuration
→
🎯 Chart Synchronization
Multi-chart coordination
chart-sync.js: - Crosshair synchronization - Time scale alignment - Viewport coordination - Disabled sub-chart interaction
→
⚙️ Chart Configuration
Professional styling
Dark theme, Bolivia timezone Optimized bar spacing Grid lines, crosshairs Price scale formatting Localized time labels
PHASE 3: TECHNICAL INDICATORS CALCULATION
📈 EMA Indicators
ema.js: Exponential Moving Averages
Periods: 20, 50, 200
Formula: EMA = (price - prevEMA) × multiplier + prevEMA
Null filtering: Clean data for display
📊 Bollinger Bands
bollinger.js: Statistical bands
Components: Upper, Middle (SMA), Lower
Calculation: SMA ± (2 × Standard Deviation)
Period: 20 (default)
⚡ RSI Oscillator
rsi.js: Relative Strength Index
Formula: 100 - (100 / (1 + RS))
Reference lines: 30 (oversold), 70 (overbought)
Period: 14 (Wilder's smoothing)
🔄 MACD Signal
macd.js: Moving Average Convergence Divergence
Components: MACD Line, Signal, Histogram
Parameters: Fast(12), Slow(26), Signal(9)
Colors: Green/Red histogram
PHASE 4: INTERACTIVE CONTROLS
⏱️ Timeframe Selection
Multi-timeframe analysis
timeframe-handler.js: Buttons: 30m, 1h, 4h, 12h, 1d, 1w, 1M - setTimeframe() switches data - Updates all charts and indicators - Maintains chart synchronization
→
🎛️ Indicator Toggles
Dynamic indicator control
Toggle switches: - EMA (20, 50, 200) - Bollinger Bands - RSI/MACD view modes Real-time calculation and display
→
👁️ Chart View Modes
Flexible indicator display
View options: - Both: RSI + MACD - RSI Only - MACD Only Dynamic container show/hide
PHASE 5: LIVE DATA INTEGRATION
Every 10min
🔄 Auto-refresh System
Background S3 file updates
data-loader.js setupAutoRefresh(): - Fetches latest JSON from S3 - Updates current price display - Refreshes active indicators - Maintains user's timeframe selection
→
💰 Price Display
Current price integration
Header elements: #current-price → Latest USDT/BOB rate #last-update → Data freshness timestamp Price direction indicators (falling/rising)
→
📊 Dynamic Legends
Live indicator values
updateLegends(): - Current price, EMA values - RSI level, MACD signals - Bollinger band levels - Color-coded indicators
PHASE 6: PROFESSIONAL TRADING INTERFACE
🎨 Dark Theme UI
Professional appearance
chart-styles.css: - Dark background (#2e3a46) - Teal/Gold color scheme - Professional grid lines - Mobile responsive design
→
📱 Responsive Design
Mobile optimization
Mobile adaptations: - Stacked chart controls - Touch-friendly timeframe buttons - Responsive chart containers - Optimized for small screens
→
⚡ Performance
Optimized rendering
Performance features: - Chart synchronization - Optimized bar spacing - Efficient indicator updates - Smooth zoom/pan interactions
Data Source
Data Processing
Chart Library
Technical Indicators
User Controls
Frontend/UI
🔧 Technical Architecture: