trading-tools / web /components /timeframe_selector.py
Deploy Bot
Deploy Trading Analysis Platform to HuggingFace Spaces
a1bf219
"""
Timeframe selector component.
Provides dropdown for selecting analysis timeframe.
"""
from typing import List, Tuple
import gradio as gr
# Available timeframes with descriptions
TIMEFRAMES = [
("1 Day", "1d"),
("1 Week", "1w"),
("1 Month", "1mo"),
("3 Months", "3mo"),
("1 Year", "1y"),
("5 Years", "5y"),
]
def create_timeframe_selector() -> gr.Dropdown:
"""
Create timeframe selector component.
Returns:
Gradio Dropdown component for timeframe selection
"""
return gr.Dropdown(
label="Timeframe",
choices=TIMEFRAMES,
value="1w", # Default to weekly for long-term investment focus
info="Select analysis timeframe. Daily/weekly for swing trading, monthly to multi-year for long-term investing.",
)
def get_recommended_timeframe(trading_style: str) -> str:
"""
Get recommended timeframe for trading style.
Args:
trading_style: Trading style (scalping, day_trading, swing_trading, position_trading)
Returns:
Recommended timeframe code
"""
recommendations = {
"scalping": "1m",
"day_trading": "5m",
"swing_trading": "1h",
"position_trading": "1d",
}
return recommendations.get(trading_style, "1d")
def validate_timeframe(timeframe: str) -> bool:
"""
Validate timeframe selection.
Args:
timeframe: Timeframe code
Returns:
True if valid
"""
valid_timeframes = [tf[1] for tf in TIMEFRAMES]
return timeframe in valid_timeframes
def get_timeframe_description(timeframe: str) -> str:
"""
Get human-readable description of timeframe.
Args:
timeframe: Timeframe code
Returns:
Description string
"""
for label, code in TIMEFRAMES:
if code == timeframe:
return label
return timeframe