-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdashboard.html
More file actions
1383 lines (1256 loc) · 88.2 KB
/
dashboard.html
File metadata and controls
1383 lines (1256 loc) · 88.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MSA | Terminal</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Outfit:wght@300;500;700;900&display=swap" rel="stylesheet">
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
bg: '#050507',
panel: '#0e0e11',
border: '#1e1e24',
bull: '#00ff88',
bear: '#ff0055',
warn: '#f59e0b',
},
fontFamily: {
sans: ['Outfit', 'sans-serif'],
mono: ['JetBrains Mono', 'monospace'],
},
boxShadow: {
'glow-bull': '0 0 20px rgba(0, 255, 136, 0.2)',
'glow-bear': '0 0 20px rgba(255, 0, 85, 0.2)',
}
}
}
}
</script>
<style>
body { background-color: #050507; color: #e2e8f0; cursor: crosshair; }
button, a, .glass-panel, input { cursor: pointer; }
.glass-box {
background: rgba(14, 14, 17, 0.7);
border: 1px solid #1e1e24;
backdrop-filter: blur(12px);
transition: border-color 0.3s ease;
}
.glass-box:hover { border-color: rgba(255,255,255,0.1); }
/* Tooltips */
[data-tooltip] { position: relative; }
[data-tooltip]:hover { z-index: 9999; }
[data-tooltip]::after {
content: attr(data-tooltip);
position: absolute; bottom: calc(100% + 8px); left: 50%;
transform: translateX(-50%) scale(0.95); transform-origin: bottom center;
background: rgba(10,10,14,0.97); color: #aaa;
font-family: 'JetBrains Mono', monospace; font-size: 11px; line-height: 1.5;
padding: 10px 14px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1);
white-space: pre-line; max-width: 280px; width: max-content;
pointer-events: none; opacity: 0; z-index: 99999;
transition: opacity 0.2s ease, transform 0.2s ease;
box-shadow: 0 8px 30px rgba(0,0,0,0.8);
}
[data-tooltip]:hover::after {
opacity: 1; transform: translateX(-50%) scale(1);
}
/* Bottom-positioned tooltips for top-row panels */
[data-tooltip].tooltip-bottom::after {
bottom: auto; top: calc(100% + 8px);
transform-origin: top center;
}
.gauge-circle {
transition: stroke-dashoffset 1s ease-in-out, stroke 0.5s ease;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #050507; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
.animate-fade-in { animation: fadeIn 0.5s ease-out forwards; opacity: 0; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.spinner {
border: 3px solid #1e1e24;
border-top: 3px solid #00ff88;
border-radius: 50%;
width: 20px; height: 20px;
animation: spin 0.8s linear infinite;
display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loader-screen {
position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
z-index: 9999; background: #050507;
flex-direction: column;
align-items: center; justify-content: center;
transition: opacity 0.5s ease-out, visibility 0.5s;
}
#loader-screen:not(.hidden) { display: flex; }
#loader-screen:not(.hidden) { display: flex; }
#loading-canvas {
position: absolute; top: 0; left: 0;
width: 100%; height: 100%; z-index: 1;
}
.flying-text {
position: absolute; font-family: 'JetBrains Mono', monospace;
font-size: 11px; font-weight: bold; pointer-events: none;
white-space: nowrap; text-shadow: 0 2px 4px rgba(0,0,0,0.8);
z-index: 2; opacity: 0;
}
.center-status {
position: relative; z-index: 10;
background: rgba(0,0,0,0.9); padding: 15px 30px;
border: 1px solid rgba(255,255,255,0.1);
border-radius: 12px; text-align: center;
backdrop-filter: blur(10px);
box-shadow: 0 0 50px rgba(0,0,0,0.8);
}
.blink { animation: blinker 0.5s linear infinite alternate; }
@keyframes blinker { from { opacity: 1; } to { opacity: 0.3; } }
</style>
</head>
<body class="h-screen flex overflow-hidden selection:bg-bull selection:text-black font-sans">
<div id="loader-screen" class="hidden">
<canvas id="loading-canvas"></canvas>
<div id="flying-text-container"></div>
<div class="center-status">
<div class="text-xs text-gray-400 font-mono tracking-widest mb-1">MSA INTELLIGENCE</div>
<div class="text-4xl font-black text-white tracking-tighter" id="loader-ticker">--</div>
<div class="text-[10px] text-bull mt-2 font-mono flex items-center justify-center gap-2">
<span class="blink w-2 h-2 bg-bull rounded-full"></span>
<span>ESTABLISHING NEURAL LINK</span>
</div>
</div>
</div>
<aside class="w-20 lg:w-64 border-r border-border bg-panel flex flex-col justify-between hidden md:flex">
<div>
<div class="h-16 flex items-center justify-center lg:justify-start lg:px-6 border-b border-border">
<div class="w-3 h-3 bg-bull rounded-sm mr-3 shadow-[0_0_10px_#00ff88]"></div>
<span class="font-mono font-bold text-lg hidden lg:block tracking-tighter">MSA_CORE</span>
</div>
<nav class="mt-8 space-y-2 px-3">
<a href="#" class="flex items-center px-4 py-3 bg-white/5 text-white rounded-lg border border-white/5 transition">
<span class="text-xl">📊</span>
<span class="ml-3 text-sm font-bold hidden lg:block">Terminal</span>
</a>
<a href="compare.html" class="flex items-center px-4 py-3 text-gray-500 hover:text-white hover:bg-white/5 rounded-lg transition">
<span class="text-xl">⚔️</span>
<span class="ml-3 text-sm font-bold hidden lg:block">Compare</span>
</a>
<a href="index.html" class="flex items-center px-4 py-3 text-gray-500 hover:text-white hover:bg-white/5 rounded-lg transition">
<span class="text-xl">🏠</span>
<span class="ml-3 text-sm font-bold hidden lg:block">Home</span>
</a>
</nav>
</div>
<div class="p-4">
<div class="glass-box p-3 rounded text-[10px] text-gray-500 font-mono text-center lg:text-left">
<div class="mb-1">STATUS: <span class="text-bull" id="api-status">READY</span></div>
<div>API: v3.0.0</div>
</div>
</div>
</aside>
<main class="flex-1 flex flex-col min-w-0 overflow-hidden">
<header class="h-16 border-b border-border bg-bg/80 backdrop-blur flex items-center justify-between px-6 gap-4">
<form id="search-form" class="flex items-center gap-3 flex-1 max-w-md">
<div class="relative flex-1">
<input
type="text"
id="ticker-input"
placeholder="Enter ticker (e.g. AAPL, TSLA, PLTR)"
maxlength="10"
class="w-full bg-black/40 border border-border rounded-lg px-4 py-2 text-sm font-mono text-white placeholder-gray-600 focus:outline-none focus:border-bull/50 focus:shadow-[0_0_10px_rgba(0,255,136,0.1)] transition"
>
</div>
<button type="submit" id="search-btn" class="bg-bull/10 border border-bull/30 text-bull px-5 py-2 rounded-lg text-sm font-bold hover:bg-bull/20 hover:shadow-glow-bull transition flex items-center gap-2">
<span id="search-btn-text">Analyze</span>
<span id="search-spinner" class="spinner hidden"></span>
</button>
</form>
<div class="flex items-center gap-4">
<span class="w-2 h-2 rounded-full bg-bull animate-pulse" id="status-dot"></span>
<span class="text-xs font-mono text-gray-500" id="timestamp-display">WAITING FOR INPUT</span>
</div>
</header>
<div class="flex-1 overflow-y-auto p-6">
<div class="max-w-7xl mx-auto space-y-6">
<div id="welcome-state" class="flex flex-col items-center justify-center py-32 text-center">
<div class="text-6xl mb-6">📊</div>
<h2 class="text-2xl font-bold text-white mb-3">Enter a Ticker to Begin</h2>
<p class="text-gray-500 max-w-md">Type any stock symbol above and hit Analyze. We'll fetch live data, calculate SMAs, pull market sentiment, and run GPT-4 analysis.</p>
<div class="flex gap-3 mt-8">
<button onclick="runAnalysis('AAPL')" class="px-4 py-2 glass-box rounded-lg text-sm font-mono text-gray-400 hover:text-bull hover:border-bull/30 transition">AAPL</button>
<button onclick="runAnalysis('TSLA')" class="px-4 py-2 glass-box rounded-lg text-sm font-mono text-gray-400 hover:text-bull hover:border-bull/30 transition">TSLA</button>
<button onclick="runAnalysis('PLTR')" class="px-4 py-2 glass-box rounded-lg text-sm font-mono text-gray-400 hover:text-bull hover:border-bull/30 transition">PLTR</button>
<button onclick="runAnalysis('NVDA')" class="px-4 py-2 glass-box rounded-lg text-sm font-mono text-gray-400 hover:text-bull hover:border-bull/30 transition">NVDA</button>
<button onclick="runAnalysis('MSFT')" class="px-4 py-2 glass-box rounded-lg text-sm font-mono text-gray-400 hover:text-bull hover:border-bull/30 transition">MSFT</button>
</div>
</div>
<div id="loading-state" class="hidden flex flex-col items-center justify-center py-32 text-center">
<div class="spinner mb-6" style="width:40px;height:40px;border-width:4px;"></div>
<h2 class="text-xl font-bold text-white mb-2" id="loading-ticker">Analyzing...</h2>
<p class="text-gray-500 text-sm font-mono">Fetching data, calculating SMAs, running GPT-4...</p>
</div>
<div id="error-state" class="hidden flex flex-col items-center justify-center py-32 text-center">
<div class="text-6xl mb-6">⚠️</div>
<h2 class="text-xl font-bold text-bear mb-2">Analysis Failed</h2>
<p class="text-gray-500 text-sm max-w-md" id="error-message">Something went wrong.</p>
<button onclick="document.getElementById('ticker-input').focus()" class="mt-6 px-6 py-2 glass-box rounded-lg text-sm font-mono text-gray-400 hover:text-bull transition">Try Again</button>
</div>
<div id="dashboard-content" class="hidden space-y-6">
<div class="grid grid-cols-1 md:grid-cols-12 gap-6">
<div class="md:col-span-8 glass-box p-6 rounded-xl relative overflow-visible group animate-fade-in" style="animation-delay: 0.1s;">
<div class="absolute top-0 right-0 p-6 opacity-10 font-black text-9xl text-white select-none pointer-events-none group-hover:scale-110 transition duration-700 overflow-hidden" id="ticker-bg" style="inset:0; text-align:right; padding-top:24px;">--</div>
<div class="relative z-10 flex justify-between items-start">
<div>
<div class="flex items-center gap-3 mb-1">
<h1 class="text-5xl font-black text-white tracking-tight" id="ticker-symbol">--</h1>
<span class="text-3xl font-bold font-mono" id="live-price">--</span>
<span class="text-sm font-mono font-bold" id="price-arrow"></span>
</div>
<div id="ai-badge" class="hidden inline-flex items-center gap-3 mt-2 px-5 py-2.5 rounded-full border backdrop-blur-md">
<span class="text-base">🤖</span>
<span class="text-sm font-black font-mono uppercase tracking-wider" id="ai-badge-text">--</span>
<span class="text-xs font-mono opacity-70" id="ai-badge-conf">--</span>
</div>
</div>
<div class="text-right tooltip-bottom" data-tooltip="SMA Crossover Signal Golden Cross: SMA 50 > SMA 200 Bullish — uptrend forming Death Cross: SMA 50 < SMA 200 Bearish — downtrend forming">
<div id="signal-badge" class="inline-flex items-center gap-2 px-4 py-2 rounded-full backdrop-blur-md">
<span class="w-2 h-2 rounded-full animate-pulse" id="signal-dot"></span>
<span class="text-sm font-bold tracking-wider uppercase" id="signal-text">--</span>
</div>
<div class="mt-2 text-xs text-gray-500 font-mono">TECHNICAL SIGNAL</div>
</div>
</div>
<div class="relative z-10 mt-8 grid grid-cols-2 gap-4">
<div class="bg-black/20 p-4 rounded-lg border border-white/5" data-tooltip="50-Day Simple Moving Average Average closing price over the last 50 days. Used to gauge short-term trend direction. Price above SMA 50 = bullish momentum.">
<div class="text-xs text-gray-500 uppercase tracking-widest mb-1">SMA 50</div>
<div class="text-2xl font-mono font-bold text-bull" id="sma-50">--</div>
</div>
<div class="bg-black/20 p-4 rounded-lg border border-white/5" data-tooltip="200-Day Simple Moving Average Average closing price over the last 200 days. The key long-term trend indicator. SMA 50 crossing above SMA 200 = Golden Cross (bullish). SMA 50 crossing below SMA 200 = Death Cross (bearish).">
<div class="text-xs text-gray-500 uppercase tracking-widest mb-1">SMA 200</div>
<div class="text-2xl font-mono font-bold text-gray-300" id="sma-200">--</div>
</div>
</div>
</div>
<div class="md:col-span-4 glass-box p-6 rounded-xl flex flex-col justify-between items-center text-center animate-fade-in tooltip-bottom" style="animation-delay: 0.2s;" data-tooltip="CNN Fear & Greed Index Measures overall market sentiment. 0-25: Extreme Fear (potential buying opportunity) 25-45: Fear 45-55: Neutral 55-75: Greed 75-100: Extreme Greed (market may be overvalued)">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest w-full text-left">Market Sentiment</h3>
<div class="relative w-40 h-40 mt-4">
<svg class="w-full h-full transform -rotate-90">
<circle cx="80" cy="80" r="70" stroke="#1e1e24" stroke-width="12" fill="transparent"/>
<circle id="gauge-arc" cx="80" cy="80" r="70" stroke="#f59e0b" stroke-width="12" fill="transparent"
stroke-dasharray="440" stroke-dashoffset="440" stroke-linecap="round" class="gauge-circle"/>
</svg>
<div class="absolute inset-0 flex flex-col items-center justify-center">
<span class="text-4xl font-black text-white" id="fear-val">--</span>
<span class="text-xs font-bold uppercase mt-1" id="fear-label">--</span>
</div>
</div>
<div class="w-full text-xs text-gray-600 font-mono mt-2">INDEX: FEAR & GREED</div>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<!-- Technicals Gauge -->
<div class="glass-box p-6 rounded-xl animate-fade-in flex flex-col items-center" style="animation-delay: 0.25s;" data-tooltip="Technical Indicators Score Combines RSI and MACD into one gauge. RSI (14): Relative Strength Index Below 30 = Oversold (buy signal) 30-70 = Neutral Above 70 = Overbought (sell signal) MACD: Moving Average Convergence/Divergence Histogram > 0 = Bullish momentum Histogram < 0 = Bearish momentum Gauge: 0 = Strong Sell → 100 = Strong Buy">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest w-full text-left mb-2">Technicals</h3>
<div class="relative w-52 h-28 mt-2">
<svg viewBox="0 0 200 110" class="w-full h-full">
<defs>
<linearGradient id="techGrad" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stop-color="#ff0055"/>
<stop offset="25%" stop-color="#ff4466"/>
<stop offset="45%" stop-color="#888"/>
<stop offset="55%" stop-color="#888"/>
<stop offset="75%" stop-color="#44dd88"/>
<stop offset="100%" stop-color="#00ff88"/>
</linearGradient>
</defs>
<path d="M 20 100 A 80 80 0 0 1 180 100" fill="none" stroke="#1e1e24" stroke-width="14" stroke-linecap="round"/>
<path d="M 20 100 A 80 80 0 0 1 180 100" fill="none" stroke="url(#techGrad)" stroke-width="14" stroke-linecap="round" opacity="0.7"/>
<!-- Needle -->
<line id="tech-needle" x1="100" y1="100" x2="100" y2="30" stroke="white" stroke-width="2.5" stroke-linecap="round" style="transform-origin: 100px 100px; transition: transform 1s ease-out;"/>
<circle cx="100" cy="100" r="5" fill="white"/>
<!-- Labels -->
<text x="8" y="80" fill="#666" font-size="7" font-family="monospace">Strong</text>
<text x="12" y="88" fill="#666" font-size="7" font-family="monospace">sell</text>
<text x="42" y="52" fill="#666" font-size="7" font-family="monospace">Sell</text>
<text x="82" y="38" fill="#666" font-size="7" font-family="monospace">Neutral</text>
<text x="142" y="52" fill="#666" font-size="7" font-family="monospace">Buy</text>
<text x="158" y="80" fill="#666" font-size="7" font-family="monospace">Strong</text>
<text x="166" y="88" fill="#666" font-size="7" font-family="monospace">buy</text>
</svg>
</div>
<div class="text-xl font-black mt-1" id="tech-label">--</div>
<div class="mt-3 w-full grid grid-cols-2 gap-2 text-[10px] font-mono">
<div class="bg-black/20 rounded p-2 border border-white/5 text-center">
<div class="text-gray-500">RSI (14)</div>
<div class="text-white font-bold" id="rsi-val">--</div>
<div id="rsi-badge" class="text-gray-400">--</div>
</div>
<div class="bg-black/20 rounded p-2 border border-white/5 text-center">
<div class="text-gray-500">MACD</div>
<div class="text-white font-bold" id="macd-val">--</div>
<div id="macd-badge" class="text-gray-400">--</div>
</div>
</div>
</div>
<!-- Analyst Rating Gauge -->
<div class="glass-box p-6 rounded-xl animate-fade-in flex flex-col items-center" style="animation-delay: 0.25s;" data-tooltip="Wall Street Analyst Consensus Aggregates ratings from institutional analysts. Strong Buy / Buy / Hold / Sell / Strong Sell Gauge is weighted: Strong Buy = 5 pts, Buy = 4, Hold = 3 Sell = 2, Strong Sell = 1 Score: 0 = All Strong Sell → 100 = All Strong Buy">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest w-full text-left mb-2">Analyst Rating</h3>
<div class="relative w-52 h-28 mt-2">
<svg viewBox="0 0 200 110" class="w-full h-full">
<defs>
<linearGradient id="analystGrad" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stop-color="#ff0055"/>
<stop offset="25%" stop-color="#ff4466"/>
<stop offset="45%" stop-color="#888"/>
<stop offset="55%" stop-color="#888"/>
<stop offset="75%" stop-color="#44dd88"/>
<stop offset="100%" stop-color="#00ff88"/>
</linearGradient>
</defs>
<path d="M 20 100 A 80 80 0 0 1 180 100" fill="none" stroke="#1e1e24" stroke-width="14" stroke-linecap="round"/>
<path d="M 20 100 A 80 80 0 0 1 180 100" fill="none" stroke="url(#analystGrad)" stroke-width="14" stroke-linecap="round" opacity="0.7"/>
<line id="analyst-needle" x1="100" y1="100" x2="100" y2="30" stroke="white" stroke-width="2.5" stroke-linecap="round" style="transform-origin: 100px 100px; transition: transform 1s ease-out;"/>
<circle cx="100" cy="100" r="5" fill="white"/>
<text x="8" y="80" fill="#666" font-size="7" font-family="monospace">Strong</text>
<text x="12" y="88" fill="#666" font-size="7" font-family="monospace">sell</text>
<text x="42" y="52" fill="#666" font-size="7" font-family="monospace">Sell</text>
<text x="82" y="38" fill="#666" font-size="7" font-family="monospace">Neutral</text>
<text x="142" y="52" fill="#666" font-size="7" font-family="monospace">Buy</text>
<text x="158" y="80" fill="#666" font-size="7" font-family="monospace">Strong</text>
<text x="166" y="88" fill="#666" font-size="7" font-family="monospace">buy</text>
</svg>
</div>
<div class="text-xl font-black mt-1" id="analyst-label">--</div>
<div class="mt-3 w-full space-y-1">
<div class="flex items-center gap-2 text-[10px] font-mono">
<span class="text-gray-500 w-16 text-right">Strong Buy</span>
<div class="flex-1 h-2 bg-gray-800 rounded-full overflow-hidden"><div class="h-full bg-bull rounded-full transition-all duration-700" id="bar-sb" style="width:0%"></div></div>
<span class="text-gray-400 w-6 text-right" id="cnt-sb">0</span>
</div>
<div class="flex items-center gap-2 text-[10px] font-mono">
<span class="text-gray-500 w-16 text-right">Buy</span>
<div class="flex-1 h-2 bg-gray-800 rounded-full overflow-hidden"><div class="h-full bg-bull/70 rounded-full transition-all duration-700" id="bar-b" style="width:0%"></div></div>
<span class="text-gray-400 w-6 text-right" id="cnt-b">0</span>
</div>
<div class="flex items-center gap-2 text-[10px] font-mono">
<span class="text-gray-500 w-16 text-right">Hold</span>
<div class="flex-1 h-2 bg-gray-800 rounded-full overflow-hidden"><div class="h-full bg-gray-500 rounded-full transition-all duration-700" id="bar-h" style="width:0%"></div></div>
<span class="text-gray-400 w-6 text-right" id="cnt-h">0</span>
</div>
<div class="flex items-center gap-2 text-[10px] font-mono">
<span class="text-gray-500 w-16 text-right">Sell</span>
<div class="flex-1 h-2 bg-gray-800 rounded-full overflow-hidden"><div class="h-full bg-bear/70 rounded-full transition-all duration-700" id="bar-s" style="width:0%"></div></div>
<span class="text-gray-400 w-6 text-right" id="cnt-s">0</span>
</div>
<div class="flex items-center gap-2 text-[10px] font-mono">
<span class="text-gray-500 w-16 text-right">Strong Sell</span>
<div class="flex-1 h-2 bg-gray-800 rounded-full overflow-hidden"><div class="h-full bg-bear rounded-full transition-all duration-700" id="bar-ss" style="width:0%"></div></div>
<span class="text-gray-400 w-6 text-right" id="cnt-ss">0</span>
</div>
</div>
</div>
<!-- Price Target -->
<div class="glass-box p-6 rounded-xl animate-fade-in flex flex-col justify-between" style="animation-delay: 0.25s;" data-tooltip="1-Year Analyst Price Target Where analysts expect the stock to be in 12 months. Mean: Average of all analyst targets High/Low: Most optimistic / pessimistic targets Upside %%: How far the mean target is above (or below) the current price. Green = upside potential, Red = downside risk">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest mb-4">1 Year Price Target</h3>
<div class="flex-1 flex flex-col justify-center items-center">
<div class="text-4xl font-black text-white" id="pt-mean">--</div>
<div class="flex items-center gap-2 mt-2" id="pt-upside-wrap">
<span class="text-sm font-bold font-mono" id="pt-upside">--</span>
</div>
</div>
<div class="mt-4 space-y-2">
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Current</span>
<span class="text-white" id="pt-current">--</span>
</div>
<div class="w-full h-2 bg-gray-800 rounded-full relative overflow-hidden">
<div class="absolute h-full bg-gradient-to-r from-bear via-gray-500 to-bull rounded-full" style="width:100%"></div>
<div class="absolute h-full w-1 bg-white rounded-full" id="pt-marker" style="left:50%"></div>
</div>
<div class="flex justify-between text-[10px] font-mono text-gray-500">
<span id="pt-low">--</span>
<span id="pt-high">--</span>
</div>
</div>
</div>
</div>
<!-- Bollinger / OBV / Volume Row -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<!-- Bollinger Bands -->
<div class="glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.28s;" data-tooltip="Bollinger Bands (20, 2) Price channel: SMA(20) ± 2 standard deviations. Upper Band: Overbought zone Lower Band: Oversold zone Squeeze: Bands narrowing = low volatility, often signals a big move is coming. Bandwidth shows how wide the bands are as %%.">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest mb-3">Bollinger Bands</h3>
<div class="space-y-2">
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Upper</span>
<span class="text-bear font-bold" id="bb-upper">--</span>
</div>
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Middle (SMA 20)</span>
<span class="text-white font-bold" id="bb-middle">--</span>
</div>
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Lower</span>
<span class="text-bull font-bold" id="bb-lower">--</span>
</div>
<div class="border-t border-white/5 pt-2 mt-2">
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Bandwidth</span>
<span class="text-white" id="bb-bandwidth">--</span>
</div>
<div class="flex justify-between text-xs font-mono mt-1">
<span class="text-gray-500">Position</span>
<span class="font-bold" id="bb-position">--</span>
</div>
</div>
<div id="bb-squeeze-badge" class="hidden mt-2 text-center">
<span class="text-[10px] font-mono font-black px-3 py-1 rounded-full bg-yellow-500/20 text-yellow-400 border border-yellow-500/30 animate-pulse">⚡ SQUEEZE DETECTED</span>
</div>
</div>
</div>
<!-- OBV Analysis -->
<div class="glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.28s;" data-tooltip="On-Balance Volume (OBV) Cumulative volume indicator. OBV Rising + Price Flat = Accumulation (Smart money quietly buying) OBV Falling + Price Rising = Distribution (Smart money selling into rally) Confirmation = OBV and price moving together.">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest mb-3">On-Balance Volume</h3>
<div class="space-y-2">
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">OBV Trend</span>
<span class="font-bold" id="obv-trend">--</span>
</div>
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Price Trend (20d)</span>
<span class="font-bold" id="obv-price-trend">--</span>
</div>
<div class="border-t border-white/5 pt-2 mt-2">
<div class="text-center py-3">
<div class="text-[10px] text-gray-500 uppercase tracking-widest mb-1">Signal</div>
<div class="text-lg font-black" id="obv-divergence">--</div>
</div>
</div>
</div>
</div>
<!-- Volume Profile -->
<div class="glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.28s;" data-tooltip="Volume Profile Compares latest volume to 20-day average. Ratio > 1.5x = Volume Spike (Institutional activity likely) Spike + price move = Trend confirmation Spike + no move = Absorption (big player absorbing selling pressure) Dry volume = Low interest / consolidation.">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest mb-3">Volume Profile</h3>
<div class="space-y-2">
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">20d Avg Volume</span>
<span class="text-white font-bold" id="vol-avg">--</span>
</div>
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Latest Volume</span>
<span class="text-white font-bold" id="vol-latest">--</span>
</div>
<div class="border-t border-white/5 pt-2 mt-2">
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Ratio</span>
<span class="font-bold" id="vol-ratio">--</span>
</div>
<div class="flex justify-between text-xs font-mono mt-1">
<span class="text-gray-500">Spike Days (20d)</span>
<span class="text-white" id="vol-spike-days">--</span>
</div>
</div>
<div id="vol-spike-badge" class="hidden mt-2 text-center">
<span class="text-[10px] font-mono font-black px-3 py-1 rounded-full bg-purple-500/20 text-purple-400 border border-purple-500/30">📊 VOLUME SPIKE</span>
</div>
</div>
</div>
</div>
<!-- Quant Signals Row -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<!-- Denoised Trend -->
<div class="glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.32s;" data-tooltip="Savitzky-Golay Denoised Trend Polynomial smoothing (window=21, order=3) removes market noise to reveal true velocity. Slope: Denoised price change per day (%) Acceleration: Is the trend speeding up or slowing? Momentum Exhaustion: When slope diverges from RSI, the current move is running out of steam mathematically.">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest mb-3">Denoised Trend <span class="text-[9px] text-gray-600 normal-case">(Savitzky-Golay)</span></h3>
<div class="text-center py-3">
<div class="text-3xl font-black font-mono" id="sg-slope">--</div>
<div class="text-[10px] text-gray-500 uppercase tracking-widest mt-1">VELOCITY / DAY</div>
</div>
<div class="space-y-2 mt-2">
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Direction</span>
<span class="font-bold" id="sg-direction">--</span>
</div>
<div class="flex justify-between text-xs font-mono">
<span class="text-gray-500">Acceleration</span>
<span class="font-bold" id="sg-accel">--</span>
</div>
</div>
<div id="sg-exhaustion-badge" class="hidden mt-3 text-center">
<span class="text-[10px] font-mono font-black px-3 py-1 rounded-full" id="sg-exhaustion-text"></span>
</div>
</div>
<!-- Z-Score -->
<div class="glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.32s;" data-tooltip="20-Day Statistical Z-Score How far the price is from its 20-day mean measured in standard deviations (σ). Z > +2.0: 95.4%% pullback probability Z > +1.5: 86.6%% — stretched Z < -1.5: 86.6%% — compressed Z < -2.0: 95.4%% bounce probability Based on normal distribution statistics. This is pure math, not opinion.">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest mb-3">Z-Score <span class="text-[9px] text-gray-600 normal-case">(Mean Reversion)</span></h3>
<div class="text-center py-3">
<div class="text-4xl font-black font-mono" id="zscore-val">--</div>
<div class="text-xs font-mono mt-2 font-bold" id="zscore-signal">--</div>
</div>
<div class="mt-3">
<div class="flex justify-between text-[10px] font-mono text-gray-500 mb-1">
<span>Reversal Probability</span>
<span id="zscore-prob">--%</span>
</div>
<div class="w-full h-2 bg-gray-800 rounded-full overflow-hidden">
<div class="h-full rounded-full transition-all duration-700" id="zscore-prob-bar" style="width:0%"></div>
</div>
</div>
<div class="mt-3 grid grid-cols-2 gap-2 text-[10px] font-mono">
<div class="bg-black/20 rounded p-2 border border-white/5 text-center">
<div class="text-gray-500">20d Mean</div>
<div class="text-white font-bold" id="zscore-mean">--</div>
</div>
<div class="bg-black/20 rounded p-2 border border-white/5 text-center">
<div class="text-gray-500">20d σ</div>
<div class="text-white font-bold" id="zscore-stddev">--</div>
</div>
</div>
</div>
<!-- Inference Weights -->
<div class="glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.32s;" data-tooltip="Inference Weighting Engine Pre-calculated composite from 4 pillars: Technical (35%%): SG slope + Z-Score + RSI/MACD Sentiment (25%%): Fear & Greed (contrarian) + news NLP Analyst (20%%): Wall Street consensus score Volume (20%%): OBV divergence + volume spikes Composite > 70 = Buy 55-70 = Hold, 40-55 = Watch, < 40 = Sell This score is fed directly to GPT as a baseline.">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest mb-3">Inference Weights</h3>
<div class="text-center py-2">
<div class="text-3xl font-black font-mono" id="iw-composite">--</div>
<div class="text-xs font-mono font-bold mt-1" id="iw-signal">--</div>
</div>
<div class="space-y-2.5 mt-3">
<div>
<div class="flex justify-between text-[10px] font-mono mb-1">
<span class="text-gray-500">Technical <span class="text-gray-600">(35%)</span></span>
<span class="text-white" id="iw-tech">--</span>
</div>
<div class="w-full h-1.5 bg-gray-800 rounded-full overflow-hidden">
<div class="h-full bg-blue-500 rounded-full transition-all duration-700" id="iw-tech-bar" style="width:0%"></div>
</div>
</div>
<div>
<div class="flex justify-between text-[10px] font-mono mb-1">
<span class="text-gray-500">Sentiment <span class="text-gray-600">(25%)</span></span>
<span class="text-white" id="iw-sent">--</span>
</div>
<div class="w-full h-1.5 bg-gray-800 rounded-full overflow-hidden">
<div class="h-full bg-purple-500 rounded-full transition-all duration-700" id="iw-sent-bar" style="width:0%"></div>
</div>
</div>
<div>
<div class="flex justify-between text-[10px] font-mono mb-1">
<span class="text-gray-500">Analyst <span class="text-gray-600">(20%)</span></span>
<span class="text-white" id="iw-analyst">--</span>
</div>
<div class="w-full h-1.5 bg-gray-800 rounded-full overflow-hidden">
<div class="h-full bg-cyan-500 rounded-full transition-all duration-700" id="iw-analyst-bar" style="width:0%"></div>
</div>
</div>
<div>
<div class="flex justify-between text-[10px] font-mono mb-1">
<span class="text-gray-500">Volume <span class="text-gray-600">(20%)</span></span>
<span class="text-white" id="iw-vol">--</span>
</div>
<div class="w-full h-1.5 bg-gray-800 rounded-full overflow-hidden">
<div class="h-full bg-amber-500 rounded-full transition-all duration-700" id="iw-vol-bar" style="width:0%"></div>
</div>
</div>
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div class="lg:col-span-2 glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.3s;" data-tooltip="Price Action Chart Real closing prices over the last 30 days. Green segments = price moving up Red segments = price moving down SMA 50 (green dashed): Short-term trend SMA 200 (amber dashed): Long-term trend">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest">Price Action</h3>
<div class="flex gap-2 items-center">
<span class="w-2 h-2 bg-bull rounded-full"></span>
<span class="text-[10px] text-bull font-mono">UP</span>
<span class="w-2 h-2 bg-bear rounded-full ml-1"></span>
<span class="text-[10px] text-bear font-mono">DOWN</span>
<span class="w-3 h-0.5 bg-bull inline-block ml-2" style="border-top:2px dashed #00ff88"></span>
<span class="text-[10px] text-bull font-mono font-bold">SMA 50</span>
<span class="w-3 h-0.5 inline-block ml-1" style="border-top:2px dashed #f59e0b"></span>
<span class="text-[10px] font-mono font-bold" style="color:#f59e0b">SMA 200</span>
<span class="w-3 h-0.5 inline-block ml-2" style="border-top:2px dashed rgba(255,0,85,0.5)"></span>
<span class="text-[10px] font-mono" style="color:rgba(255,0,85,0.6)">BB</span>
<span class="w-3 h-0.5 inline-block ml-2" style="border-top:2px dashed #a78bfa"></span>
<span class="text-[10px] font-mono font-bold" style="color:#a78bfa">SG</span>
</div>
</div>
<div class="h-96 w-full">
<canvas id="stockChart"></canvas>
</div>
</div>
<div id="gpt-card" class="glass-box p-6 rounded-xl flex flex-col animate-fade-in" style="animation-delay: 0.4s;" data-tooltip="AI-Powered Analysis (GPT-4o) Synthesizes all data points: SMAs, RSI, MACD, Fear & Greed, analyst ratings, and latest news. Confidence: 0-100%% 80-100 = High conviction 50-79 = Moderate conviction Below 50 = Low conviction">
<div class="flex justify-between items-center mb-4">
<div class="flex items-center gap-2">
<span class="text-xl">🤖</span>
<h3 class="text-base font-bold text-white uppercase tracking-widest">AI Analysis</h3>
</div>
<span class="text-xs font-mono font-bold bg-bull/10 px-2.5 py-1 rounded" id="gpt-score">CONF: --%</span>
</div>
<div class="flex-1 flex flex-col justify-center">
<h4 class="text-lg font-bold text-white mb-2" id="gpt-action">--</h4>
<p class="text-sm text-gray-400 leading-relaxed" id="gpt-reason">--</p>
</div>
<div class="mt-4 pt-4 border-t border-white/5">
<div class="text-[10px] text-gray-500 font-mono uppercase">AI Recommendation</div>
</div>
</div>
</div>
<div class="glass-box p-6 rounded-xl animate-fade-in" style="animation-delay: 0.5s;" data-tooltip="FinBERT NLP News Sentiment Each headline analyzed by ProsusAI/finbert (financial BERT transformer model). Green dot = positive sentiment Red dot = negative sentiment Gray dot = neutral Aggregate score: 0 = very bearish, 1 = very bullish">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-widest">Latest Intelligence</h3>
<div class="flex items-center gap-3" id="finbert-summary">
<span class="text-[10px] font-mono text-gray-500">FinBERT:</span>
<span class="text-xs font-mono font-bold" id="finbert-label">--</span>
<span class="text-[10px] font-mono text-gray-500" id="finbert-breakdown">--</span>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4" id="news-container"></div>
</div>
<!-- Compare CTA -->
<div class="glass-box p-8 rounded-xl text-center animate-fade-in" style="animation-delay: 0.6s; border-color: rgba(245,158,11,0.15);" id="compare-cta">
<div class="text-2xl mb-3">⚔️</div>
<h3 class="text-lg font-black text-white mb-2">Not sure? Compare it.</h3>
<p class="text-sm text-gray-500 font-mono max-w-md mx-auto mb-5">Put this ticker head-to-head against another option. We'll compare every signal and tell you which one's stronger.</p>
<a id="compare-link" href="compare.html" class="inline-flex items-center gap-2 bg-warn/10 text-warn border border-warn/30 px-6 py-3 rounded-full font-bold text-sm uppercase tracking-wider hover:bg-warn/20 hover:shadow-[0_0_20px_rgba(245,158,11,0.2)] transition">
⚔️ Compare with another ticker
</a>
</div>
</div>
</div>
</div>
</main>
<script>
const API_BASE = 'https://vd2mi-msa.hf.space';
let currentChart = null;
// --- Loader Engine ---
const loaderCanvas = document.getElementById('loading-canvas');
const loaderCtx = loaderCanvas.getContext('2d');
const loaderScreen = document.getElementById('loader-screen');
const loaderTicker = document.getElementById('loader-ticker');
const textContainer = document.getElementById('flying-text-container');
let loaderW, loaderH, isLoading = false, loaderAnimId;
let pathData = [];
const xStep = 10;
const sysLogs = [
"FETCHING_RSI", "PARSING_MACD", "SCANNING_NEWS", "CALCULATING_VOLATILITY",
"CHECKING_RESISTANCE", "DETECTING_WHALES", "NLP_SENTIMENT_ANALYSIS",
"SMA_CROSSOVER_CHECK", "LOADING_HISTORICAL_DATA", "ANALYZING_ORDER_BOOK"
];
const LOADER_UP_WORDS = ["BREAKOUT", "ACCUMULATION", "MOMENTUM", "BUY", "RALLY", "LONG", "BULLISH", "SUPPORT"];
const LOADER_DOWN_WORDS = ["DUMP", "DISTRIBUTION", "CRASH", "SELL", "RESISTANCE", "SHORT", "BEARISH", "PANIC"];
function resizeLoaderCanvas() {
loaderW = loaderCanvas.width = window.innerWidth;
loaderH = loaderCanvas.height = window.innerHeight;
const needed = Math.ceil(loaderW / xStep) + 5;
let lastY = pathData.length > 0 ? pathData[pathData.length - 1] : loaderH / 2;
while (pathData.length < needed) {
let nextY = lastY + (Math.random() - 0.5) * 100;
if (nextY < loaderH * 0.2) nextY += 50;
if (nextY > loaderH * 0.8) nextY -= 50;
pathData.push(nextY);
lastY = nextY;
}
}
function startLoader(ticker) {
loaderTicker.innerText = ticker;
loaderScreen.classList.remove('hidden');
loaderScreen.style.opacity = '1';
loaderScreen.style.visibility = 'visible';
isLoading = true;
resizeLoaderCanvas();
animateLoader();
}
function stopLoader() {
isLoading = false;
cancelAnimationFrame(loaderAnimId);
textContainer.innerHTML = '';
loaderScreen.style.opacity = '0';
setTimeout(() => {
loaderScreen.classList.add('hidden');
loaderScreen.style.visibility = 'hidden';
}, 500);
}
function animateLoader() {
if (!isLoading) return;
let lastY = pathData[pathData.length - 1];
let nextY = lastY + (Math.random() - 0.5) * 150;
if (nextY < loaderH * 0.1) nextY = loaderH * 0.2;
if (nextY > loaderH * 0.9) nextY = loaderH * 0.8;
pathData.push(nextY);
pathData.shift();
loaderCtx.clearRect(0, 0, loaderW, loaderH);
loaderCtx.lineWidth = 3;
loaderCtx.lineJoin = 'round';
loaderCtx.lineCap = 'round';
for (let i = 1; i < pathData.length; i++) {
let x1 = (i - 1) * xStep, y1 = pathData[i - 1];
let x2 = i * xStep, y2 = pathData[i];
loaderCtx.beginPath();
loaderCtx.moveTo(x1, y1);
loaderCtx.lineTo(x2, y2);
loaderCtx.strokeStyle = y2 < y1 ? '#00ff88' : '#ff0055';
loaderCtx.shadowColor = loaderCtx.strokeStyle;
loaderCtx.shadowBlur = 10;
loaderCtx.stroke();
}
let headX = (pathData.length - 1) * xStep;
let headY = pathData[pathData.length - 1];
loaderCtx.beginPath();
loaderCtx.arc(headX, headY, 5, 0, Math.PI * 2);
loaderCtx.fillStyle = '#fff';
loaderCtx.shadowColor = '#fff';
loaderCtx.fill();
// system log text (white, from the head of the line)
if (Math.random() < 0.04) {
const el = document.createElement('div');
el.className = 'flying-text';
el.innerText = sysLogs[Math.floor(Math.random() * sysLogs.length)];
el.style.left = (headX - 20) + 'px';
el.style.top = (headY - 30) + 'px';
el.style.color = '#fff';
el.animate([
{ opacity: 1, transform: 'translateY(0) scale(1)' },
{ opacity: 0, transform: 'translateY(-40px) scale(0.9)' }
], { duration: 1200, easing: 'ease-out', fill: 'forwards' }).onfinish = () => el.remove();
textContainer.appendChild(el);
}
// market words (green/red, spawn along the chart line)
if (Math.random() < 0.08) {
const randIdx = Math.floor(Math.random() * (pathData.length - 2)) + 1;
const py = pathData[randIdx];
const prevY = pathData[randIdx - 1];
const isUp = py < prevY;
const words = isUp ? LOADER_UP_WORDS : LOADER_DOWN_WORDS;
const word = words[Math.floor(Math.random() * words.length)];
const clr = isUp ? '#00ff88' : '#ff0055';
const el = document.createElement('div');
el.className = 'flying-text';
el.innerText = word;
el.style.left = (randIdx * xStep) + 'px';
el.style.top = (py - 20) + 'px';
el.style.color = clr;
el.style.fontSize = '11px';
el.style.fontWeight = '800';
el.style.textShadow = `0 0 8px ${clr}`;
el.animate([
{ opacity: 0.9, transform: 'translateY(0) scale(1)' },
{ opacity: 0, transform: `translateY(${isUp ? '-60' : '60'}px) scale(0.7)` }
], { duration: 1800, easing: 'ease-out', fill: 'forwards' }).onfinish = () => el.remove();
textContainer.appendChild(el);
}
loaderAnimId = requestAnimationFrame(animateLoader);
}
window.addEventListener('resize', () => { if (isLoading) resizeLoaderCanvas(); });
// --- App Logic ---
function showState(state) {
document.getElementById('welcome-state').classList.add('hidden');
document.getElementById('loading-state').classList.add('hidden');
document.getElementById('error-state').classList.add('hidden');
document.getElementById('dashboard-content').classList.add('hidden');
document.getElementById(state).classList.remove('hidden');
}
function setSearchLoading(loading) {
const btn = document.getElementById('search-btn');
const text = document.getElementById('search-btn-text');
const spinner = document.getElementById('search-spinner');
const input = document.getElementById('ticker-input');
if (loading) {
btn.disabled = true;
btn.classList.add('opacity-50');
input.disabled = true;
text.textContent = '';
spinner.classList.remove('hidden');
} else {
btn.disabled = false;
btn.classList.remove('opacity-50');
input.disabled = false;
text.textContent = 'Analyze';
spinner.classList.add('hidden');
}
}
async function runAnalysis(ticker) {
ticker = ticker.trim().toUpperCase();
if (!ticker) return;
document.getElementById('ticker-input').value = ticker;
document.getElementById('api-status').textContent = 'FETCHING';
document.getElementById('api-status').className = 'text-warn';
showState('loading-state');
startLoader(ticker);
setSearchLoading(true);
try {
const resp = await fetch(`${API_BASE}/analyze?ticker=${encodeURIComponent(ticker)}`);
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
throw new Error(err.detail || `API returned ${resp.status}`);
}
const data = await resp.json();
stopLoader();
document.getElementById('api-status').textContent = 'CONNECTED';
document.getElementById('api-status').className = 'text-bull';
renderDashboard(data);
showState('dashboard-content');
} catch (err) {
stopLoader();
document.getElementById('error-message').textContent = err.message;
document.getElementById('api-status').textContent = 'ERROR';
document.getElementById('api-status').className = 'text-bear';
showState('error-state');
} finally {
setSearchLoading(false);
}
}
function renderDashboard(data) {
document.title = `MSA | ${data.ticker}`;
document.getElementById('ticker-symbol').textContent = data.ticker;
document.getElementById('ticker-bg').textContent = data.ticker;
document.getElementById('timestamp-display').textContent = new Date(data.timestamp).toLocaleString();
const livePrice = document.getElementById('live-price');
const priceArrow = document.getElementById('price-arrow');
const pt0 = data.price_target || {};
const dayUp = (pt0.daily_change_pct || 0) >= 0;
if (pt0.current) {
livePrice.textContent = '$' + pt0.current.toFixed(2);
livePrice.className = `text-3xl font-bold font-mono ${dayUp ? 'text-bull' : 'text-bear'}`;
const chgStr = pt0.daily_change_pct != null ? ` ${dayUp ? '+' : ''}${pt0.daily_change_pct.toFixed(2)}%` : '';
priceArrow.textContent = (dayUp ? '▲' : '▼') + chgStr;
priceArrow.className = `text-sm font-mono font-bold ${dayUp ? 'text-bull' : 'text-bear'}`;
} else {
livePrice.textContent = '';
priceArrow.textContent = '';
}
// cached responses still work, badge removed for cleaner UI
const signal = data.moving_averages.signal;
const isBull = signal === 'Golden Cross';
document.getElementById('signal-text').textContent = signal || 'N/A';
const signalBadge = document.getElementById('signal-badge');
const signalDot = document.getElementById('signal-dot');
signalBadge.className = `inline-flex items-center gap-2 px-4 py-2 rounded-full backdrop-blur-md ${isBull ? 'bg-bull/10 border border-bull/20 shadow-glow-bull' : 'bg-bear/10 border border-bear/20 shadow-glow-bear'}`;
signalDot.className = `w-2 h-2 rounded-full animate-pulse ${isBull ? 'bg-bull' : 'bg-bear'}`;
document.getElementById('signal-text').className = `text-sm font-bold tracking-wider uppercase ${isBull ? 'text-bull' : 'text-bear'}`;
const sma50 = data.moving_averages.sma_50;
const sma200 = data.moving_averages.sma_200;
document.getElementById('sma-50').textContent = sma50 != null ? sma50.toFixed(2) : 'N/A';
document.getElementById('sma-200').textContent = sma200 != null ? sma200.toFixed(2) : 'N/A';
const fearVal = data.fear_greed.value;
document.getElementById('fear-val').textContent = fearVal;
document.getElementById('fear-label').textContent = data.fear_greed.label;
const offset = 440 - (440 * (fearVal / 100));
const gaugeArc = document.getElementById('gauge-arc');
gaugeArc.style.strokeDashoffset = '440';
setTimeout(() => { gaugeArc.style.strokeDashoffset = offset; }, 100);
let gaugeColor, labelColor;
if (fearVal <= 25) { gaugeColor = '#ff0055'; labelColor = 'text-bear'; }
else if (fearVal <= 45) { gaugeColor = '#f59e0b'; labelColor = 'text-warn'; }
else if (fearVal <= 55) { gaugeColor = '#888'; labelColor = 'text-gray-400'; }
else if (fearVal <= 75) { gaugeColor = '#00ff88'; labelColor = 'text-bull'; }
else { gaugeColor = '#00ff88'; labelColor = 'text-bull'; }
gaugeArc.style.stroke = gaugeColor;
document.getElementById('fear-label').className = `text-xs font-bold uppercase mt-1 ${labelColor}`;
// Gauge needle helper: score 0-100 → rotation -90° to +90°
function setNeedle(id, score) {
const angle = -90 + (score / 100) * 180;
const needle = document.getElementById(id);
needle.style.transform = `rotate(${angle}deg)`;
}
function scoreToColor(score) {
if (score <= 20) return 'text-bear';
if (score <= 40) return 'text-bear';
if (score <= 60) return 'text-gray-300';
if (score <= 80) return 'text-bull';
return 'text-bull';
}
// Technical Indicators Gauge
const tech = data.technicals;
if (tech) {
setTimeout(() => setNeedle('tech-needle', tech.score), 200);
const techLabel = document.getElementById('tech-label');
techLabel.textContent = tech.overall_signal || 'Neutral';
techLabel.className = `text-xl font-black mt-1 ${scoreToColor(tech.score)}`;
document.getElementById('rsi-val').textContent = tech.rsi_14 != null ? tech.rsi_14.toFixed(1) : 'N/A';
const rsiBadge = document.getElementById('rsi-badge');
if (tech.rsi_signal === 'Oversold') {
rsiBadge.textContent = 'OVERSOLD'; rsiBadge.className = 'text-bull';
} else if (tech.rsi_signal === 'Overbought') {
rsiBadge.textContent = 'OVERBOUGHT'; rsiBadge.className = 'text-bear';
} else {
rsiBadge.textContent = 'NEUTRAL'; rsiBadge.className = 'text-gray-400';
}
document.getElementById('macd-val').textContent = tech.macd != null ? tech.macd.toFixed(2) : 'N/A';
const macdBadge = document.getElementById('macd-badge');
if (tech.macd_trend === 'Bullish') {
macdBadge.textContent = 'BULLISH'; macdBadge.className = 'text-bull';
} else if (tech.macd_trend === 'Bearish') {
macdBadge.textContent = 'BEARISH'; macdBadge.className = 'text-bear';
} else {
macdBadge.textContent = '--'; macdBadge.className = 'text-gray-400';
}
}
// Analyst Ratings Gauge
const ar = data.analyst_ratings;
if (ar) {
setTimeout(() => setNeedle('analyst-needle', ar.score), 400);
const alLabel = document.getElementById('analyst-label');
alLabel.textContent = ar.recommendation || 'No Data';
alLabel.className = `text-xl font-black mt-1 ${scoreToColor(ar.score)}`;
if (ar.total > 0) {
const max = Math.max(ar.strong_buy, ar.buy, ar.hold, ar.sell, ar.strong_sell, 1);
document.getElementById('cnt-sb').textContent = ar.strong_buy;
document.getElementById('cnt-b').textContent = ar.buy;
document.getElementById('cnt-h').textContent = ar.hold;
document.getElementById('cnt-s').textContent = ar.sell;
document.getElementById('cnt-ss').textContent = ar.strong_sell;
setTimeout(() => {
document.getElementById('bar-sb').style.width = ((ar.strong_buy / max) * 100) + '%';
document.getElementById('bar-b').style.width = ((ar.buy / max) * 100) + '%';
document.getElementById('bar-h').style.width = ((ar.hold / max) * 100) + '%';
document.getElementById('bar-s').style.width = ((ar.sell / max) * 100) + '%';
document.getElementById('bar-ss').style.width = ((ar.strong_sell / max) * 100) + '%';
}, 100);