Spaces:
Running
Running
Update utils/forex_signals.py
Browse files- utils/forex_signals.py +36 -40
utils/forex_signals.py
CHANGED
@@ -1,49 +1,45 @@
|
|
1 |
import random
|
2 |
-
from datetime import datetime
|
3 |
-
|
4 |
-
#
|
5 |
-
def generate_forex_signals(trading_capital, market_risk, user_timezone,
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
signals = []
|
13 |
-
for pair in
|
14 |
-
# Randomized data for demonstration purposes
|
15 |
-
entry_price = random.uniform(1.1, 1.5) # Entry price
|
16 |
-
exit_price = random.uniform(1.1, 1.5) # Exit price
|
17 |
-
signal_strength = random.uniform(0.7, 1.0) # Signal strength (0 to 1)
|
18 |
-
trade_duration = timedelta(minutes=random.randint(15, 120)) # Trade duration in minutes
|
19 |
-
|
20 |
-
# Calculate ROI with leverage
|
21 |
-
roi = ((exit_price - entry_price) / entry_price) * leverage * 100
|
22 |
-
|
23 |
-
# Calculate stop loss and take profit
|
24 |
-
stop_loss = entry_price * (1 - (stop_loss_percentage / 100))
|
25 |
-
take_profit = entry_price * (1 + (take_profit_percentage / 100))
|
26 |
-
|
27 |
-
# Generate signal dictionary
|
28 |
signal = {
|
29 |
"currency_pair": pair,
|
30 |
-
"entry_time":
|
31 |
-
"exit_time": (datetime.now()
|
32 |
-
"roi":
|
33 |
-
"signal_strength":
|
34 |
-
"stop_loss": round(stop_loss, 5),
|
35 |
-
"take_profit": round(take_profit, 5)
|
36 |
}
|
37 |
-
|
38 |
signals.append(signal)
|
39 |
-
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
# Best signal is the one with the highest ROI
|
44 |
-
best_signal = signals[0] if signals else None
|
45 |
|
46 |
return {
|
47 |
-
"
|
48 |
-
"
|
49 |
}
|
|
|
1 |
import random
|
2 |
+
from datetime import datetime
|
3 |
+
|
4 |
+
# Function to generate Forex signals
|
5 |
+
def generate_forex_signals(trading_capital, market_risk, user_timezone, additional_pairs=None):
|
6 |
+
"""
|
7 |
+
Generates trading signals for the forex market.
|
8 |
+
:param trading_capital: The amount of capital the user has for trading.
|
9 |
+
:param market_risk: The risk level selected by the user (Low, Medium, High).
|
10 |
+
:param user_timezone: The user's timezone.
|
11 |
+
:param additional_pairs: List of additional currency pairs to consider (optional).
|
12 |
+
:return: Dictionary of forex signals with relevant details.
|
13 |
+
"""
|
14 |
+
|
15 |
+
# Default list of currency pairs
|
16 |
+
default_pairs = [
|
17 |
+
"EUR/USD", "GBP/USD", "USD/JPY", "AUD/USD", "USD/CHF",
|
18 |
+
"USD/CAD", "NZD/USD", "EUR/GBP", "EUR/JPY", "GBP/JPY"
|
19 |
+
]
|
20 |
+
|
21 |
+
# Add additional pairs if provided
|
22 |
+
if additional_pairs:
|
23 |
+
all_pairs = default_pairs + additional_pairs
|
24 |
+
else:
|
25 |
+
all_pairs = default_pairs
|
26 |
+
|
27 |
+
# Example of generating signals (simplified logic for demo purposes)
|
28 |
signals = []
|
29 |
+
for pair in all_pairs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
signal = {
|
31 |
"currency_pair": pair,
|
32 |
+
"entry_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
33 |
+
"exit_time": (datetime.now().strftime("%Y-%m-%d %H:%M:%S")), # Simplified; should be dynamic
|
34 |
+
"roi": random.uniform(5, 15), # Random ROI for demonstration
|
35 |
+
"signal_strength": random.uniform(50, 100) # Random signal strength for demo
|
|
|
|
|
36 |
}
|
|
|
37 |
signals.append(signal)
|
38 |
+
|
39 |
+
# Determine the best signal based on ROI (just a simplified example)
|
40 |
+
best_signal = max(signals, key=lambda x: x["roi"])
|
|
|
|
|
|
|
41 |
|
42 |
return {
|
43 |
+
"best_signal": best_signal,
|
44 |
+
"all_signals": signals
|
45 |
}
|