Spaces:
Sleeping
Sleeping
Commit ยท
a7eeef4
1
Parent(s): c32ee3f
Update crypto timeframe to 15m, relax BTC/ETH filters, and remove Signal History tab
Browse files- forex_macd_dashboard.html +9 -78
- forex_macd_strategy.py +54 -13
forex_macd_dashboard.html
CHANGED
|
@@ -275,8 +275,8 @@
|
|
| 275 |
<button class="tab-btn" onclick="filterCategory('Forex')">Forex Pairs</button>
|
| 276 |
<button class="tab-btn" onclick="filterCategory('Metals/Energy')">Metals & Energy</button>
|
| 277 |
<button class="tab-btn" onclick="filterCategory('Cryptos')">Cryptocurrencies</button>
|
|
|
|
| 278 |
<button class="tab-btn" onclick="filterCategory('Intraday IndianMarket')">Intraday IndianMarket</button>
|
| 279 |
-
<button class="tab-btn" onclick="filterCategory('History')">Signal History</button>
|
| 280 |
</div>
|
| 281 |
|
| 282 |
<div id="dashboard" class="grid">
|
|
@@ -315,23 +315,15 @@
|
|
| 315 |
|
| 316 |
let currentCategory = 'Active';
|
| 317 |
let cachedData = null;
|
| 318 |
-
let cachedHistory = null;
|
| 319 |
|
| 320 |
async function fetchData() {
|
| 321 |
try {
|
| 322 |
-
const
|
| 323 |
-
fetch('forex_macd_signals.json'),
|
| 324 |
-
fetch('signal_history.json').catch(() => ({ ok: false }))
|
| 325 |
-
]);
|
| 326 |
|
| 327 |
if (signalsRes.ok) {
|
| 328 |
cachedData = await signalsRes.json();
|
| 329 |
}
|
| 330 |
|
| 331 |
-
if (historyRes && historyRes.ok) {
|
| 332 |
-
cachedHistory = await historyRes.json();
|
| 333 |
-
}
|
| 334 |
-
|
| 335 |
renderDashboard();
|
| 336 |
} catch (error) {
|
| 337 |
console.error('Error fetching data:', error);
|
|
@@ -344,7 +336,13 @@
|
|
| 344 |
// Update active tab button
|
| 345 |
const buttons = document.querySelectorAll('.tab-btn');
|
| 346 |
buttons.forEach(btn => {
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
btn.classList.add('active');
|
| 349 |
} else {
|
| 350 |
btn.classList.remove('active');
|
|
@@ -360,11 +358,6 @@
|
|
| 360 |
const container = document.getElementById('dashboard');
|
| 361 |
const lastUpdated = document.getElementById('lastUpdated');
|
| 362 |
|
| 363 |
-
if (currentCategory === 'History') {
|
| 364 |
-
renderHistory();
|
| 365 |
-
return;
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
container.innerHTML = '';
|
| 369 |
lastUpdated.textContent = `Last Updated: ${new Date(data.last_updated).toLocaleString()}`;
|
| 370 |
|
|
@@ -494,69 +487,7 @@
|
|
| 494 |
});
|
| 495 |
}
|
| 496 |
|
| 497 |
-
function renderHistory() {
|
| 498 |
-
const dashboard = document.getElementById('dashboard');
|
| 499 |
-
if (!cachedHistory || cachedHistory.length === 0) {
|
| 500 |
-
dashboard.innerHTML = `
|
| 501 |
-
<div style="grid-column: 1/-1; text-align: center; padding: 4rem; color: var(--text-secondary);">
|
| 502 |
-
No signal history available yet.
|
| 503 |
-
</div>
|
| 504 |
-
`;
|
| 505 |
-
return;
|
| 506 |
-
}
|
| 507 |
-
|
| 508 |
-
let html = `
|
| 509 |
-
<div style="grid-column: 1/-1; background: var(--card-bg); border-radius: 1rem; padding: 1.5rem; border: 1px solid var(--border);">
|
| 510 |
-
<h2 style="margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.5rem;">
|
| 511 |
-
๐ Signal Event Logs
|
| 512 |
-
</h2>
|
| 513 |
-
<div style="overflow-x: auto;">
|
| 514 |
-
<table style="width: 100%; border-collapse: collapse; text-align: left;">
|
| 515 |
-
<thead>
|
| 516 |
-
<tr style="border-bottom: 2px solid var(--border); color: var(--text-secondary); font-size: 0.875rem;">
|
| 517 |
-
<th style="padding: 1rem;">Entry Time</th>
|
| 518 |
-
<th style="padding: 1rem;">Event Time</th>
|
| 519 |
-
<th style="padding: 1rem;">Instrument</th>
|
| 520 |
-
<th style="padding: 1rem;">Event</th>
|
| 521 |
-
<th style="padding: 1rem;">Price</th>
|
| 522 |
-
<th style="padding: 1rem;">Type</th>
|
| 523 |
-
<th style="padding: 1rem;">Entry Price</th>
|
| 524 |
-
</tr>
|
| 525 |
-
</thead>
|
| 526 |
-
<tbody>
|
| 527 |
-
`;
|
| 528 |
-
|
| 529 |
-
cachedHistory.slice().reverse().forEach(log => {
|
| 530 |
-
const eventClass = log.event.includes('HIT') ? (log.event.includes('SL') ? 'bearish' : 'bullish') : 'neutral';
|
| 531 |
-
const typeClass = log.type === 'BUY' ? 'bullish' : (log.type === 'SELL' ? 'bearish' : '');
|
| 532 |
-
|
| 533 |
-
html += `
|
| 534 |
-
<tr style="border-bottom: 1px solid var(--border); font-size: 0.9375rem;">
|
| 535 |
-
<td style="padding: 1rem; color: var(--text-secondary); white-space: nowrap;">${log.entry_time ? formatDate(log.entry_time) : '-'}</td>
|
| 536 |
-
<td style="padding: 1rem; color: var(--text-secondary); white-space: nowrap;">${formatDate(log.time)}</td>
|
| 537 |
-
<td style="padding: 1rem; font-weight: 600;">${log.instrument}</td>
|
| 538 |
-
<td style="padding: 1rem;">
|
| 539 |
-
<span class="status-badge ${eventClass}">${log.event.replace(/_/g, ' ')}</span>
|
| 540 |
-
</td>
|
| 541 |
-
<td style="padding: 1rem; font-family: monospace;">${log.price.toFixed(log.instrument.includes('JPY') ? 3 : 2)}</td>
|
| 542 |
-
<td style="padding: 1rem;">
|
| 543 |
-
${log.type ? `<span class="status-badge ${typeClass}">${log.type}</span>` : '-'}
|
| 544 |
-
</td>
|
| 545 |
-
<td style="padding: 1rem; font-family: monospace; color: var(--text-secondary);">
|
| 546 |
-
${log.entry_price ? log.entry_price.toFixed(log.instrument.includes('JPY') ? 3 : 2) : '-'}
|
| 547 |
-
</td>
|
| 548 |
-
</tr>
|
| 549 |
-
`;
|
| 550 |
-
});
|
| 551 |
|
| 552 |
-
html += `
|
| 553 |
-
</tbody>
|
| 554 |
-
</table>
|
| 555 |
-
</div>
|
| 556 |
-
</div>
|
| 557 |
-
`;
|
| 558 |
-
dashboard.innerHTML = html;
|
| 559 |
-
}
|
| 560 |
|
| 561 |
fetchData();
|
| 562 |
setInterval(fetchData, 30000);
|
|
|
|
| 275 |
<button class="tab-btn" onclick="filterCategory('Forex')">Forex Pairs</button>
|
| 276 |
<button class="tab-btn" onclick="filterCategory('Metals/Energy')">Metals & Energy</button>
|
| 277 |
<button class="tab-btn" onclick="filterCategory('Cryptos')">Cryptocurrencies</button>
|
| 278 |
+
<button class="tab-btn" onclick="filterCategory('Crypto Scalping')">Scalping</button>
|
| 279 |
<button class="tab-btn" onclick="filterCategory('Intraday IndianMarket')">Intraday IndianMarket</button>
|
|
|
|
| 280 |
</div>
|
| 281 |
|
| 282 |
<div id="dashboard" class="grid">
|
|
|
|
| 315 |
|
| 316 |
let currentCategory = 'Active';
|
| 317 |
let cachedData = null;
|
|
|
|
| 318 |
|
| 319 |
async function fetchData() {
|
| 320 |
try {
|
| 321 |
+
const signalsRes = await fetch('forex_macd_signals.json');
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
if (signalsRes.ok) {
|
| 324 |
cachedData = await signalsRes.json();
|
| 325 |
}
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
renderDashboard();
|
| 328 |
} catch (error) {
|
| 329 |
console.error('Error fetching data:', error);
|
|
|
|
| 336 |
// Update active tab button
|
| 337 |
const buttons = document.querySelectorAll('.tab-btn');
|
| 338 |
buttons.forEach(btn => {
|
| 339 |
+
const btnText = btn.textContent.trim();
|
| 340 |
+
if (btnText === category ||
|
| 341 |
+
(category === 'Active' && btnText === 'Active Signals') ||
|
| 342 |
+
(category === 'All' && btnText === 'All Assets') ||
|
| 343 |
+
(category === 'Crypto Scalping' && btnText === 'Scalping') ||
|
| 344 |
+
(category === 'Intraday IndianMarket' && btnText === 'Intraday IndianMarket') ||
|
| 345 |
+
(category === 'Metals/Energy' && btnText === 'Metals & Energy')) {
|
| 346 |
btn.classList.add('active');
|
| 347 |
} else {
|
| 348 |
btn.classList.remove('active');
|
|
|
|
| 358 |
const container = document.getElementById('dashboard');
|
| 359 |
const lastUpdated = document.getElementById('lastUpdated');
|
| 360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
container.innerHTML = '';
|
| 362 |
lastUpdated.textContent = `Last Updated: ${new Date(data.last_updated).toLocaleString()}`;
|
| 363 |
|
|
|
|
| 487 |
});
|
| 488 |
}
|
| 489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
|
| 492 |
fetchData();
|
| 493 |
setInterval(fetchData, 30000);
|
forex_macd_strategy.py
CHANGED
|
@@ -40,8 +40,13 @@ CONFIG = {
|
|
| 40 |
{"name": "EUR/GBP", "symbol": "EURGBP=X", "pip_size": 0.0001, "flag": "๐ช๐บ๐ฌ๐ง", "category": "Forex"},
|
| 41 |
{"name": "EUR/JPY", "symbol": "EURJPY=X", "pip_size": 0.01, "flag": "๐ช๐บ๐ฏ๐ต", "category": "Forex"},
|
| 42 |
{"name": "GBP/JPY", "symbol": "GBPJPY=X", "pip_size": 0.01, "flag": "๐ฌ๐ง๐ฏ๐ต", "category": "Forex"},
|
| 43 |
-
{"name": "Bitcoin", "symbol": "BTC-USD", "pip_size": 1.0, "flag": "โฟ", "category": "
|
| 44 |
-
{"name": "Ethereum", "symbol": "ETH-USD", "pip_size": 0.1, "flag": "ฮ", "category": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
{"name": "Nifty 50", "symbol": "^NSEI", "pip_size": 0.05, "flag": "๐ฎ๐ณ", "category": "Intraday IndianMarket"},
|
| 46 |
{"name": "Bank Nifty", "symbol": "^NSEBANK", "pip_size": 0.05, "flag": "๐ฎ๐ณ๐ฆ", "category": "Intraday IndianMarket"},
|
| 47 |
{"name": "Sensex", "symbol": "^BSESN", "pip_size": 0.05, "flag": "๐ฎ๐ณ๐", "category": "Intraday IndianMarket"}
|
|
@@ -175,6 +180,25 @@ def analyze_instrument(instrument: Dict) -> Dict:
|
|
| 175 |
'Open': 'first', 'High': 'max', 'Low': 'min', 'Close': 'last', 'Volume': 'sum'
|
| 176 |
}).dropna()
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
trend_label = "4H Trend"
|
| 179 |
mom_label = "1H MOM"
|
| 180 |
entry_label = "15m Entry"
|
|
@@ -232,16 +256,24 @@ def analyze_instrument(instrument: Dict) -> Dict:
|
|
| 232 |
print(f" โ ๏ธ Conversion failed: {e}")
|
| 233 |
|
| 234 |
# 3. Apply Rules
|
| 235 |
-
# Trend: MACD Line > 0 AND Price > EMA 200
|
| 236 |
trend_ema_200 = t_last.get('EMA_200', None)
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
trend_bias = "BULLISH" if trend_bullish else ("BEARISH" if trend_bearish else "NEUTRAL")
|
| 241 |
|
| 242 |
-
# Momentum: Histogram > 0 AND Histogram is increasing
|
| 243 |
-
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
mom_bias = "BULLISH" if mom_bullish else ("BEARISH" if mom_bearish else "NEUTRAL")
|
| 247 |
|
|
@@ -256,12 +288,21 @@ def analyze_instrument(instrument: Dict) -> Dict:
|
|
| 256 |
is_above_ema = True if ema_200 is None or e_last['Close'] > ema_200 else False
|
| 257 |
is_below_ema = True if ema_200 is None or e_last['Close'] < ema_200 else False
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
-
# Stricter MACD: Both lines must be on the same side of zero
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
if e_prev['Histogram'] < 0 and e_last['Histogram'] > 0:
|
| 267 |
e_signal = "BUY_CROSS"
|
|
|
|
| 40 |
{"name": "EUR/GBP", "symbol": "EURGBP=X", "pip_size": 0.0001, "flag": "๐ช๐บ๐ฌ๐ง", "category": "Forex"},
|
| 41 |
{"name": "EUR/JPY", "symbol": "EURJPY=X", "pip_size": 0.01, "flag": "๐ช๐บ๐ฏ๐ต", "category": "Forex"},
|
| 42 |
{"name": "GBP/JPY", "symbol": "GBPJPY=X", "pip_size": 0.01, "flag": "๐ฌ๐ง๐ฏ๐ต", "category": "Forex"},
|
| 43 |
+
{"name": "Bitcoin", "symbol": "BTC-USD", "pip_size": 1.0, "flag": "โฟ", "category": "Crypto Scalping"},
|
| 44 |
+
{"name": "Ethereum", "symbol": "ETH-USD", "pip_size": 0.1, "flag": "ฮ", "category": "Crypto Scalping"},
|
| 45 |
+
{"name": "Solana", "symbol": "SOL-USD", "pip_size": 0.01, "flag": "โ๏ธ", "category": "Crypto Scalping"},
|
| 46 |
+
{"name": "Ripple", "symbol": "XRP-USD", "pip_size": 0.0001, "flag": "๐ง", "category": "Crypto Scalping"},
|
| 47 |
+
{"name": "Cardano", "symbol": "ADA-USD", "pip_size": 0.0001, "flag": "โณ", "category": "Crypto Scalping"},
|
| 48 |
+
{"name": "Dogecoin", "symbol": "DOGE-USD", "pip_size": 0.00001, "flag": "๐", "category": "Crypto Scalping"},
|
| 49 |
+
{"name": "Polkadot", "symbol": "DOT-USD", "pip_size": 0.01, "flag": "โซ", "category": "Crypto Scalping"},
|
| 50 |
{"name": "Nifty 50", "symbol": "^NSEI", "pip_size": 0.05, "flag": "๐ฎ๐ณ", "category": "Intraday IndianMarket"},
|
| 51 |
{"name": "Bank Nifty", "symbol": "^NSEBANK", "pip_size": 0.05, "flag": "๐ฎ๐ณ๐ฆ", "category": "Intraday IndianMarket"},
|
| 52 |
{"name": "Sensex", "symbol": "^BSESN", "pip_size": 0.05, "flag": "๐ฎ๐ณ๐", "category": "Intraday IndianMarket"}
|
|
|
|
| 180 |
'Open': 'first', 'High': 'max', 'Low': 'min', 'Close': 'last', 'Volume': 'sum'
|
| 181 |
}).dropna()
|
| 182 |
|
| 183 |
+
trend_label = "4H Trend"
|
| 184 |
+
mom_label = "1H MOM"
|
| 185 |
+
entry_label = "15m Entry"
|
| 186 |
+
elif category == "Crypto Scalping":
|
| 187 |
+
# Scalping: 4H Trend (from 1H), 1H Momentum, 15m Entry
|
| 188 |
+
trend_df_raw = fetch_data(symbol, "1h", "1y")
|
| 189 |
+
mom_df = trend_df_raw.copy()
|
| 190 |
+
entry_df = fetch_data(symbol, "15m", "30d")
|
| 191 |
+
|
| 192 |
+
if trend_df_raw.empty or entry_df.empty:
|
| 193 |
+
print(" โ ๏ธ Insufficient data for scalping")
|
| 194 |
+
return None
|
| 195 |
+
|
| 196 |
+
# Resample 1H to 4H for Trend
|
| 197 |
+
trend_df_raw.index = pd.to_datetime(trend_df_raw.index)
|
| 198 |
+
trend_df = trend_df_raw.resample('4h').agg({
|
| 199 |
+
'Open': 'first', 'High': 'max', 'Low': 'min', 'Close': 'last', 'Volume': 'sum'
|
| 200 |
+
}).dropna()
|
| 201 |
+
|
| 202 |
trend_label = "4H Trend"
|
| 203 |
mom_label = "1H MOM"
|
| 204 |
entry_label = "15m Entry"
|
|
|
|
| 256 |
print(f" โ ๏ธ Conversion failed: {e}")
|
| 257 |
|
| 258 |
# 3. Apply Rules
|
| 259 |
+
# Trend: MACD Line > 0 AND Price > EMA 200 (Relaxed for BTC/ETH)
|
| 260 |
trend_ema_200 = t_last.get('EMA_200', None)
|
| 261 |
+
if name in ["Bitcoin", "Ethereum"]:
|
| 262 |
+
trend_bullish = t_last['MACD_Line'] > 0
|
| 263 |
+
trend_bearish = t_last['MACD_Line'] < 0
|
| 264 |
+
else:
|
| 265 |
+
trend_bullish = t_last['MACD_Line'] > 0 and (trend_ema_200 is None or t_last['Close'] > trend_ema_200)
|
| 266 |
+
trend_bearish = t_last['MACD_Line'] < 0 and (trend_ema_200 is None or t_last['Close'] < trend_ema_200)
|
| 267 |
|
| 268 |
trend_bias = "BULLISH" if trend_bullish else ("BEARISH" if trend_bearish else "NEUTRAL")
|
| 269 |
|
| 270 |
+
# Momentum: Histogram > 0 AND Histogram is increasing (Relaxed for BTC/ETH)
|
| 271 |
+
if name in ["Bitcoin", "Ethereum"]:
|
| 272 |
+
mom_bullish = m_last['Histogram'] > 0
|
| 273 |
+
mom_bearish = m_last['Histogram'] < 0
|
| 274 |
+
else:
|
| 275 |
+
mom_bullish = m_last['Histogram'] > 0 and m_last['Histogram'] > m_prev['Histogram']
|
| 276 |
+
mom_bearish = m_last['Histogram'] < 0 and m_last['Histogram'] < m_prev['Histogram']
|
| 277 |
|
| 278 |
mom_bias = "BULLISH" if mom_bullish else ("BEARISH" if mom_bearish else "NEUTRAL")
|
| 279 |
|
|
|
|
| 288 |
is_above_ema = True if ema_200 is None or e_last['Close'] > ema_200 else False
|
| 289 |
is_below_ema = True if ema_200 is None or e_last['Close'] < ema_200 else False
|
| 290 |
|
| 291 |
+
# Relaxed RSI for BTC/ETH
|
| 292 |
+
if name in ["Bitcoin", "Ethereum"]:
|
| 293 |
+
rsi_bullish = True if rsi is None or rsi > 45 else False
|
| 294 |
+
rsi_bearish = True if rsi is None or rsi < 55 else False
|
| 295 |
+
else:
|
| 296 |
+
rsi_bullish = True if rsi is None or rsi > 50 else False
|
| 297 |
+
rsi_bearish = True if rsi is None or rsi < 50 else False
|
| 298 |
|
| 299 |
+
# Stricter MACD: Both lines must be on the same side of zero (Relaxed for BTC/ETH)
|
| 300 |
+
if name in ["Bitcoin", "Ethereum"]:
|
| 301 |
+
macd_bullish = e_last['MACD_Line'] > 0
|
| 302 |
+
macd_bearish = e_last['MACD_Line'] < 0
|
| 303 |
+
else:
|
| 304 |
+
macd_bullish = e_last['MACD_Line'] > 0 and e_last['Signal_Line'] > 0
|
| 305 |
+
macd_bearish = e_last['MACD_Line'] < 0 and e_last['Signal_Line'] < 0
|
| 306 |
|
| 307 |
if e_prev['Histogram'] < 0 and e_last['Histogram'] > 0:
|
| 308 |
e_signal = "BUY_CROSS"
|