Spaces:
Running
Running
Create forex_signals.py
Browse files- utils/forex_signals.py +49 -0
utils/forex_signals.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
from datetime import datetime, timedelta
|
3 |
+
|
4 |
+
# Generate forex signals with new logic
|
5 |
+
def generate_forex_signals(trading_capital, market_risk, user_timezone, leverage, stop_loss_percentage, take_profit_percentage):
|
6 |
+
# Example list of currency pairs (add 10 more pairs here)
|
7 |
+
currency_pairs = ["EUR/USD", "USD/JPY", "GBP/USD", "AUD/USD", "USD/CAD", "USD/CHF",
|
8 |
+
"NZD/USD", "EUR/GBP", "GBP/JPY", "EUR/JPY", "AUD/JPY", "EUR/AUD",
|
9 |
+
"GBP/CAD", "USD/ZAR", "EUR/CHF", "GBP/NZD"]
|
10 |
+
|
11 |
+
# Simulating generated signals
|
12 |
+
signals = []
|
13 |
+
for pair in currency_pairs:
|
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": (datetime.now() + trade_duration).strftime("%Y-%m-%d %H:%M:%S"),
|
31 |
+
"exit_time": (datetime.now() + trade_duration).strftime("%Y-%m-%d %H:%M:%S"),
|
32 |
+
"roi": round(roi, 2),
|
33 |
+
"signal_strength": round(signal_strength * 100, 2),
|
34 |
+
"stop_loss": round(stop_loss, 5),
|
35 |
+
"take_profit": round(take_profit, 5)
|
36 |
+
}
|
37 |
+
|
38 |
+
signals.append(signal)
|
39 |
+
|
40 |
+
# Sort signals by ROI in descending order
|
41 |
+
signals = sorted(signals, key=lambda x: x["roi"], reverse=True)
|
42 |
+
|
43 |
+
# Best signal is the one with the highest ROI
|
44 |
+
best_signal = signals[0] if signals else None
|
45 |
+
|
46 |
+
return {
|
47 |
+
"all_signals": signals,
|
48 |
+
"best_signal": best_signal
|
49 |
+
}
|