Spaces:
Sleeping
Sleeping
| import datetime | |
| import numpy as np | |
| from utils.fetch_forex_data import fetch_forex_data | |
| from utils.calculate_technical_indicators import calculate_technical_indicators | |
| def generate_forex_signals(trading_capital, market_risk, timezone): | |
| """ | |
| Generate forex trading signals based on technical indicators. | |
| Args: | |
| trading_capital (float): User's trading capital in USD. | |
| market_risk (str): Risk level ("Low", "Medium", "High"). | |
| timezone (str): User's timezone (e.g., "UTC"). | |
| Returns: | |
| dict: Dictionary containing the best signal and all generated signals. | |
| """ | |
| # Define the top 10 most popular currency pairs | |
| currency_pairs = [ | |
| "EUR/USD", "GBP/USD", "USD/JPY", "AUD/USD", "USD/CAD", | |
| "USD/CHF", "NZD/USD", "EUR/JPY", "GBP/JPY", "AUD/JPY" | |
| ] | |
| all_signals = [] | |
| for pair in currency_pairs: | |
| # Fetch historical data for the currency pair | |
| data = fetch_forex_data(pair, timeframe="15m") | |
| # Calculate technical indicators | |
| indicators = calculate_technical_indicators(data) | |
| # Generate trade signal | |
| current_time = datetime.datetime.now() # Get current date and time | |
| entry_time = current_time | |
| exit_time = current_time + datetime.timedelta(minutes=15) | |
| roi = np.random.uniform(10, 20) # Random ROI between 10% and 20% | |
| signal_strength = np.random.uniform(80, 100) # Random signal strength (80%-100%) | |
| # Calculate Stop-Loss and Take-Profit levels based on risk | |
| stop_loss = trading_capital * 0.01 # 1% of capital | |
| take_profit = trading_capital * (roi / 100) # ROI percentage of capital | |
| signal = { | |
| "currency_pair": pair, | |
| "entry_time": entry_time.strftime("%Y-%m-%d %H:%M:%S"), | |
| "exit_time": exit_time.strftime("%Y-%m-%d %H:%M:%S"), | |
| "roi": round(roi, 2), | |
| "signal_strength": round(signal_strength, 2), | |
| "stop_loss": round(stop_loss, 2), | |
| "take_profit": round(take_profit, 2), | |
| } | |
| all_signals.append(signal) | |
| # Select the best signal (highest ROI) | |
| best_signal = max(all_signals, key=lambda x: x["roi"]) | |
| return { | |
| "best_signal": best_signal, | |
| "all_signals": all_signals | |
| } | |