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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="id">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Asset Trading Simulator</title>
7
+ <style>
8
+ :root {
9
+ --bg-main: #0b0e11;
10
+ --bg-card: #181a20;
11
+ --text-main: #eaecef;
12
+ --text-muted: #848e9c;
13
+ --up-color: #0ecb81;
14
+ --down-color: #f6465d;
15
+ --accent: #f0b90b;
16
+ }
17
+
18
+ * {
19
+ box-sizing: border-box;
20
+ margin: 0;
21
+ padding: 0;
22
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
23
+ -webkit-tap-highlight-color: transparent;
24
+ }
25
+
26
+ html, body {
27
+ height: 100%;
28
+ }
29
+
30
+ body {
31
+ background-color: #000;
32
+ color: var(--text-main);
33
+ display: flex;
34
+ justify-content: center;
35
+ align-items: center;
36
+ min-height: 100vh;
37
+ min-height: 100dvh;
38
+ }
39
+
40
+ .phone-container {
41
+ width: 100%;
42
+ max-width: 412px;
43
+ height: 100vh;
44
+ height: 100dvh;
45
+ max-height: 892px;
46
+ background-color: var(--bg-main);
47
+ display: flex;
48
+ flex-direction: column;
49
+ overflow: hidden;
50
+ position: relative;
51
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
52
+ }
53
+
54
+ .header {
55
+ background-color: var(--bg-card);
56
+ padding: 12px;
57
+ border-bottom: 1px solid #2b3139;
58
+ }
59
+
60
+ .header-title-row {
61
+ display: flex;
62
+ justify-content: space-between;
63
+ align-items: center;
64
+ margin-bottom: 4px;
65
+ }
66
+
67
+ .header-title {
68
+ font-size: 14px;
69
+ color: var(--text-muted);
70
+ }
71
+
72
+ .mode-link {
73
+ font-size: 12px;
74
+ font-weight: 700;
75
+ color: var(--accent);
76
+ text-decoration: none;
77
+ padding: 2px 8px;
78
+ border: 1px solid var(--accent);
79
+ border-radius: 4px;
80
+ transition: background-color 0.2s, color 0.2s;
81
+ }
82
+
83
+ .mode-link:hover,
84
+ .mode-link:active {
85
+ background-color: var(--accent);
86
+ color: #000;
87
+ }
88
+
89
+ .balance-row {
90
+ display: flex;
91
+ justify-content: space-between;
92
+ align-items: baseline;
93
+ margin-bottom: 8px;
94
+ }
95
+
96
+ .balance-value {
97
+ font-size: 24px;
98
+ font-weight: 700;
99
+ color: var(--text-main);
100
+ }
101
+
102
+ .pnl-badge {
103
+ font-size: 14px;
104
+ font-weight: 600;
105
+ padding: 2px 8px;
106
+ border-radius: 4px;
107
+ transition: background-color .2s, color .2s;
108
+ }
109
+
110
+ .stats-grid {
111
+ display: grid;
112
+ grid-template-columns: 1fr 1fr;
113
+ gap: 12px;
114
+ margin-top: 12px;
115
+ font-size: 12px;
116
+ }
117
+
118
+ .stat-box {
119
+ background: rgba(255, 255, 255, 0.03);
120
+ padding: 8px;
121
+ border-radius: 6px;
122
+ }
123
+
124
+ .stat-label {
125
+ color: var(--text-muted);
126
+ margin-bottom: 2px;
127
+ }
128
+
129
+ .stat-val {
130
+ font-weight: 600;
131
+ }
132
+
133
+ .ticker-bar {
134
+ display: flex;
135
+ justify-content: space-between;
136
+ padding: 8px 12px;
137
+ background: #12161a;
138
+ font-size: 13px;
139
+ border-bottom: 1px solid #2b3139;
140
+ }
141
+
142
+ .indicator-bar {
143
+ display: flex;
144
+ gap: 6px;
145
+ padding: 6px 8px;
146
+ background: #12161a;
147
+ border-bottom: 1px solid #2b3139;
148
+ position: relative;
149
+ z-index: 50;
150
+ }
151
+
152
+ .ind-select {
153
+ flex: 1 1 0;
154
+ min-width: 0;
155
+ background-color: #2b3139;
156
+ color: var(--text-main);
157
+ border: 1px solid #3a4048;
158
+ border-radius: 5px;
159
+ padding: 5px 16px 5px 6px;
160
+ font-size: 11px;
161
+ font-family: inherit;
162
+ cursor: pointer;
163
+ outline: none;
164
+ -webkit-appearance: none;
165
+ -moz-appearance: none;
166
+ appearance: none;
167
+ background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'><path d='M0 2 L4 6 L8 2 Z' fill='%23848e9c'/></svg>");
168
+ background-repeat: no-repeat;
169
+ background-position: right 5px center;
170
+ }
171
+
172
+ .ind-select:focus {
173
+ border-color: var(--accent);
174
+ }
175
+
176
+ .ind-wrap {
177
+ flex: 1 1 0;
178
+ min-width: 0;
179
+ display: flex;
180
+ }
181
+
182
+ .ind-select.ind-native-hidden {
183
+ display: none !important;
184
+ }
185
+
186
+ .ind-trigger {
187
+ flex: 1 1 0;
188
+ min-width: 0;
189
+ background-color: #2b3139;
190
+ color: var(--text-main);
191
+ border: 1px solid #3a4048;
192
+ border-radius: 5px;
193
+ padding: 5px 16px 5px 6px;
194
+ font-size: 11px;
195
+ font-family: inherit;
196
+ text-align: left;
197
+ cursor: pointer;
198
+ outline: none;
199
+ white-space: nowrap;
200
+ overflow: hidden;
201
+ text-overflow: ellipsis;
202
+ -webkit-appearance: none;
203
+ appearance: none;
204
+ background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'><path d='M0 2 L4 6 L8 2 Z' fill='%23848e9c'/></svg>");
205
+ background-repeat: no-repeat;
206
+ background-position: right 5px center;
207
+ user-select: none;
208
+ -webkit-user-select: none;
209
+ }
210
+
211
+ .ind-trigger:focus {
212
+ border-color: var(--accent);
213
+ }
214
+
215
+ .ind-panel {
216
+ position: absolute;
217
+ top: 100%;
218
+ left: 8px;
219
+ width: 220px;
220
+ z-index: 200;
221
+ background: #1e2329;
222
+ border: 1px solid #3a4048;
223
+ border-radius: 6px;
224
+ box-shadow: 0 10px 24px rgba(0, 0, 0, 0.65);
225
+ padding: 8px;
226
+ display: flex;
227
+ flex-direction: column;
228
+ gap: 6px;
229
+ max-height: 340px;
230
+ overflow: hidden;
231
+ }
232
+
233
+ .ind-panel[hidden] {
234
+ display: none;
235
+ }
236
+
237
+ .ind-search {
238
+ flex: 0 0 auto;
239
+ width: 100%;
240
+ background-color: #2b3139;
241
+ color: var(--text-main);
242
+ border: 1px solid #3a4048;
243
+ border-radius: 4px;
244
+ padding: 8px 10px;
245
+ font-size: 13px;
246
+ font-family: inherit;
247
+ outline: none;
248
+ }
249
+
250
+ .ind-search:focus {
251
+ border-color: var(--accent);
252
+ }
253
+
254
+ .ind-list {
255
+ flex: 1 1 auto;
256
+ min-height: 0;
257
+ overflow-y: auto;
258
+ display: flex;
259
+ flex-direction: column;
260
+ gap: 2px;
261
+ -webkit-overflow-scrolling: touch;
262
+ }
263
+
264
+ .ind-opt {
265
+ flex: 0 0 auto;
266
+ padding: 8px 10px;
267
+ font-size: 13px;
268
+ line-height: 1.45;
269
+ border-radius: 4px;
270
+ cursor: pointer;
271
+ color: var(--text-main);
272
+ white-space: nowrap;
273
+ overflow: hidden;
274
+ text-overflow: ellipsis;
275
+ }
276
+
277
+ .ind-opt:hover,
278
+ .ind-opt.highlight {
279
+ background-color: #2b3139;
280
+ }
281
+
282
+ .ind-opt.selected {
283
+ color: var(--accent);
284
+ font-weight: 700;
285
+ }
286
+
287
+ .ind-opt.disabled {
288
+ color: #5b636e;
289
+ font-style: italic;
290
+ cursor: default;
291
+ pointer-events: none;
292
+ }
293
+
294
+ .ind-empty {
295
+ flex: 0 0 auto;
296
+ padding: 10px;
297
+ font-size: 13px;
298
+ color: var(--text-muted);
299
+ text-align: center;
300
+ }
301
+
302
+ .fee-row {
303
+ display: flex;
304
+ gap: 12px;
305
+ padding: 6px 12px;
306
+ background: #12161a;
307
+ border-bottom: 1px solid #2b3139;
308
+ font-size: 12px;
309
+ color: var(--text-muted);
310
+ align-items: center;
311
+ }
312
+
313
+ .fee-row label {
314
+ display: flex;
315
+ align-items: center;
316
+ gap: 6px;
317
+ flex: 1;
318
+ }
319
+
320
+ .fee-row input {
321
+ width: 60px;
322
+ background-color: #2b3139;
323
+ color: var(--text-main);
324
+ border: 1px solid #3a4048;
325
+ border-radius: 4px;
326
+ padding: 4px 6px;
327
+ font-size: 12px;
328
+ font-family: inherit;
329
+ outline: none;
330
+ }
331
+
332
+ .fee-row input:focus {
333
+ border-color: var(--accent);
334
+ }
335
+
336
+ /* ====== Baris brand + pilihan sumber data ====== */
337
+ .brand-bar {
338
+ display: flex;
339
+ justify-content: space-between;
340
+ align-items: center;
341
+ padding: 6px 12px;
342
+ background: rgba(18, 22, 26, 0.92);
343
+ border-bottom: 1px solid #2b3139;
344
+ border-top: 1px solid #2b3139;
345
+ backdrop-filter: blur(4px);
346
+ -webkit-backdrop-filter: blur(4px);
347
+ gap: 8px;
348
+ }
349
+
350
+ .brand-link {
351
+ display: inline-flex;
352
+ align-items: center;
353
+ gap: 6px;
354
+ font-size: 12px;
355
+ font-weight: 700;
356
+ letter-spacing: 0.3px;
357
+ color: var(--accent);
358
+ text-decoration: none;
359
+ padding: 3px 8px;
360
+ border-radius: 4px;
361
+ transition: background-color 0.2s, color 0.2s;
362
+ flex-shrink: 0;
363
+ }
364
+
365
+ .brand-link:hover,
366
+ .brand-link:active {
367
+ background-color: var(--accent);
368
+ color: #000;
369
+ }
370
+
371
+ .brand-link .x-logo {
372
+ display: inline-block;
373
+ width: 13px;
374
+ height: 13px;
375
+ flex-shrink: 0;
376
+ }
377
+
378
+ .datasource-group {
379
+ display: flex;
380
+ gap: 0;
381
+ background: #2b3139;
382
+ border-radius: 5px;
383
+ padding: 2px;
384
+ flex-shrink: 0;
385
+ }
386
+
387
+ .ds-btn {
388
+ background: transparent;
389
+ color: var(--text-muted);
390
+ border: none;
391
+ padding: 4px 9px;
392
+ font-size: 11px;
393
+ font-weight: 700;
394
+ border-radius: 4px;
395
+ cursor: pointer;
396
+ font-family: inherit;
397
+ letter-spacing: 0.3px;
398
+ transition: background-color 0.15s, color 0.15s;
399
+ user-select: none;
400
+ -webkit-user-select: none;
401
+ }
402
+
403
+ .ds-btn:hover:not(.active) {
404
+ color: var(--text-main);
405
+ background: rgba(255, 255, 255, 0.06);
406
+ }
407
+
408
+ .ds-btn.active {
409
+ background: var(--accent);
410
+ color: #000;
411
+ }
412
+
413
+ .chart-container {
414
+ flex: 1.8 1 0;
415
+ position: relative;
416
+ background-color: var(--bg-main);
417
+ width: 100%;
418
+ min-height: 100px;
419
+ overflow: hidden;
420
+ }
421
+
422
+ .subchart-container {
423
+ flex: 0.9 1 0;
424
+ position: relative;
425
+ background-color: var(--bg-main);
426
+ width: 100%;
427
+ min-height: 50px;
428
+ border-top: 1px solid #2b3139;
429
+ overflow: hidden;
430
+ }
431
+
432
+ canvas {
433
+ position: absolute;
434
+ top: 0;
435
+ left: 0;
436
+ width: 100%;
437
+ height: 100%;
438
+ display: block;
439
+ }
440
+
441
+ .control-panel {
442
+ background-color: var(--bg-card);
443
+ padding: 12px;
444
+ border-top: 1px solid #2b3139;
445
+ }
446
+
447
+ .playback-controls {
448
+ display: flex;
449
+ gap: 8px;
450
+ margin-bottom: 10px;
451
+ }
452
+
453
+ .btn {
454
+ flex: 1;
455
+ border: none;
456
+ padding: 10px;
457
+ font-size: 14px;
458
+ font-weight: 600;
459
+ border-radius: 8px;
460
+ cursor: pointer;
461
+ display: flex;
462
+ justify-content: center;
463
+ align-items: center;
464
+ gap: 6px;
465
+ transition: opacity 0.2s;
466
+ user-select: none;
467
+ }
468
+
469
+ .btn:active {
470
+ opacity: 0.8;
471
+ }
472
+
473
+ .btn:disabled {
474
+ opacity: 0.4;
475
+ cursor: not-allowed;
476
+ }
477
+
478
+ .btn-secondary {
479
+ background-color: #2b3139;
480
+ color: var(--text-main);
481
+ }
482
+
483
+ .btn-buy {
484
+ background-color: var(--up-color);
485
+ color: #fff;
486
+ font-size: 16px;
487
+ }
488
+
489
+ .btn-sell {
490
+ background-color: var(--down-color);
491
+ color: #fff;
492
+ font-size: 16px;
493
+ }
494
+
495
+ .trade-actions {
496
+ display: flex;
497
+ gap: 12px;
498
+ }
499
+
500
+ .pos-indicator {
501
+ text-align: center;
502
+ font-size: 12px;
503
+ color: var(--text-muted);
504
+ margin-bottom: 8px;
505
+ min-height: 15px;
506
+ }
507
+ </style>
508
+ </head>
509
+ <body>
510
+
511
+ <div class="phone-container">
512
+ <div class="header">
513
+ <div class="header-title-row">
514
+ <span class="header-title">Total Kekayaan (Equity)</span>
515
+ <a class="mode-link" href="https://lynk.id/readthefuture" target="_blank" rel="noopener noreferrer">MODE: PEMULA</a>
516
+ </div>
517
+ <div class="balance-row">
518
+ <span class="balance-value" id="equity-val">1.000.000</span>
519
+ <span class="pnl-badge" id="pnl-pct" style="background: rgba(255,255,255,0.1);">+0.00%</span>
520
+ </div>
521
+
522
+ <div class="stats-grid">
523
+ <div class="stat-box">
524
+ <div class="stat-label">Saldo Tunai (Cash)</div>
525
+ <div class="stat-val" id="cash-val">1.000.000</div>
526
+ </div>
527
+ <div class="stat-box">
528
+ <div class="stat-label">Nilai Aset</div>
529
+ <div class="stat-val" id="asset-val">0</div>
530
+ </div>
531
+ </div>
532
+ </div>
533
+
534
+ <div class="ticker-bar">
535
+ <div>
536
+ <strong style="color:var(--accent)">SIMULASI-UNIT</strong>
537
+ <span id="bar-progress" style="color:var(--text-muted)">0/250</span>
538
+ </div>
539
+ <div id="ticker-price" style="font-weight:700; color:var(--text-main)">0</div>
540
+ </div>
541
+
542
+ <div class="indicator-bar">
543
+ <select id="ind1" class="ind-select" title="Indikator utama 1">
544
+ <option value="">Kosong</option>
545
+ <option value="ma5">MA 5</option>
546
+ <option value="ma10">MA 10</option>
547
+ <option value="ma20">MA 20</option>
548
+ <option value="ma50">MA 50</option>
549
+ <option value="ma100">MA 100</option>
550
+ <option value="ma200">MA 200</option>
551
+ <option value="ema5">EMA 5</option>
552
+ <option value="ema10">EMA 10</option>
553
+ <option value="ema20">EMA 20</option>
554
+ <option value="ema50">EMA 50</option>
555
+ <option value="ema100">EMA 100</option>
556
+ <option value="ema200">EMA 200</option>
557
+ <option value="wma5">WMA 5</option>
558
+ <option value="wma10">WMA 10</option>
559
+ <option value="wma20">WMA 20</option>
560
+ <option value="wma50">WMA 50</option>
561
+ <option value="wma100">WMA 100</option>
562
+ <option value="wma200">WMA 200</option>
563
+ <option value="wilders5">Wilders 5</option>
564
+ <option value="wilders10">Wilders 10</option>
565
+ <option value="wilders20">Wilders 20</option>
566
+ <option value="wilders50">Wilders 50</option>
567
+ <option value="wilders100">Wilders 100</option>
568
+ <option value="wilders200">Wilders 200</option>
569
+ <option value="bollinger">Bollinger</option>
570
+ <option value="squeeze">Squeeze</option>
571
+ <option value="mahir" disabled>== MODE:MAHIR ==</option>
572
+ <option value="supnresv01" disabled>Sup & Res V01</option>
573
+ </select>
574
+ <select id="ind2" class="ind-select" title="Indikator utama 2">
575
+ <option value="">Kosong</option>
576
+ <option value="ma5">MA 5</option>
577
+ <option value="ma10">MA 10</option>
578
+ <option value="ma20">MA 20</option>
579
+ <option value="ma50">MA 50</option>
580
+ <option value="ma100">MA 100</option>
581
+ <option value="ma200">MA 200</option>
582
+ <option value="ema5">EMA 5</option>
583
+ <option value="ema10">EMA 10</option>
584
+ <option value="ema20">EMA 20</option>
585
+ <option value="ema50">EMA 50</option>
586
+ <option value="ema100">EMA 100</option>
587
+ <option value="ema200">EMA 200</option>
588
+ <option value="wma5">WMA 5</option>
589
+ <option value="wma10">WMA 10</option>
590
+ <option value="wma20">WMA 20</option>
591
+ <option value="wma50">WMA 50</option>
592
+ <option value="wma100">WMA 100</option>
593
+ <option value="wma200">WMA 200</option>
594
+ <option value="wilders5">Wilders 5</option>
595
+ <option value="wilders10">Wilders 10</option>
596
+ <option value="wilders20">Wilders 20</option>
597
+ <option value="wilders50">Wilders 50</option>
598
+ <option value="wilders100">Wilders 100</option>
599
+ <option value="wilders200">Wilders 200</option>
600
+ <option value="bollinger">Bollinger</option>
601
+ <option value="squeeze">Squeeze</option>
602
+ <option value="mahir" disabled>== MODE:MAHIR ==</option>
603
+ <option value="supnresv01" disabled>Sup & Res V01</option>
604
+ </select>
605
+ <select id="ind3" class="ind-select" title="Indikator utama 3">
606
+ <option value="">Kosong</option>
607
+ <option value="ma5">MA 5</option>
608
+ <option value="ma10">MA 10</option>
609
+ <option value="ma20">MA 20</option>
610
+ <option value="ma50">MA 50</option>
611
+ <option value="ma100">MA 100</option>
612
+ <option value="ma200">MA 200</option>
613
+ <option value="ema5">EMA 5</option>
614
+ <option value="ema10">EMA 10</option>
615
+ <option value="ema20">EMA 20</option>
616
+ <option value="ema50">EMA 50</option>
617
+ <option value="ema100">EMA 100</option>
618
+ <option value="ema200">EMA 200</option>
619
+ <option value="wma5">WMA 5</option>
620
+ <option value="wma10">WMA 10</option>
621
+ <option value="wma20">WMA 20</option>
622
+ <option value="wma50">WMA 50</option>
623
+ <option value="wma100">WMA 100</option>
624
+ <option value="wma200">WMA 200</option>
625
+ <option value="wilders5">Wilders 5</option>
626
+ <option value="wilders10">Wilders 10</option>
627
+ <option value="wilders20">Wilders 20</option>
628
+ <option value="wilders50">Wilders 50</option>
629
+ <option value="wilders100">Wilders 100</option>
630
+ <option value="wilders200">Wilders 200</option>
631
+ <option value="bollinger">Bollinger</option>
632
+ <option value="squeeze">Squeeze</option>
633
+ <option value="mahir" disabled>== MODE:MAHIR ==</option>
634
+ <option value="supnresv01" disabled>Sup & Res V01</option>
635
+ </select>
636
+ <select id="subchart" class="ind-select" title="Grafik bawah">
637
+ <option value="rsi">RSI</option>
638
+ <option value="macd">MACD+Signal</option>
639
+ </select>
640
+ </div>
641
+
642
+ <div class="fee-row">
643
+ <label>Fee Beli (%): <input type="number" id="fee-buy-input" value="0.3" step="0.01" min="0" max="10"></label>
644
+ <label>Fee Jual (%): <input type="number" id="fee-sell-input" value="0.3" step="0.01" min="0" max="10"></label>
645
+ </div>
646
+
647
+ <!-- ====== Baris brand + pilihan sumber data ====== -->
648
+ <div class="brand-bar">
649
+ <a class="brand-link" href="https://x.com/sahamharian" target="_blank" rel="noopener noreferrer">
650
+ <svg class="x-logo" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
651
+ <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/>
652
+ </svg>
653
+ <span>@sahamharian</span>
654
+ </a>
655
+ <div class="datasource-group" role="group" aria-label="Sumber data">
656
+ <button type="button" class="ds-btn active" data-source="synthetic" title="Data sintetis (dibuat acak)">Sintetis</button>
657
+ <button type="button" class="ds-btn" data-source="upload" title="Upload file CSV berisi OHLC">Upload</button>
658
+ </div>
659
+ <input type="file" id="csv-input" accept=".csv,.txt,.tsv" hidden>
660
+ </div>
661
+
662
+ <div class="chart-container" id="chart-parent">
663
+ <canvas id="tradingChart"></canvas>
664
+ </div>
665
+
666
+ <div class="subchart-container" id="subchart-parent">
667
+ <canvas id="subChart"></canvas>
668
+ </div>
669
+
670
+ <div class="control-panel">
671
+ <div class="pos-indicator" id="pos-info">Posisi saat ini: 0 Unit (Rata-rata: 0)</div>
672
+
673
+ <div class="playback-controls">
674
+ <button class="btn btn-secondary" id="btn-pause">⏸ Pause</button>
675
+ <button class="btn btn-secondary" id="btn-restart">🔄 Restart</button>
676
+ </div>
677
+
678
+ <div class="trade-actions">
679
+ <button class="btn btn-buy" id="btn-buy">BELI</button>
680
+ <button class="btn btn-sell" id="btn-sell">JUAL</button>
681
+ </div>
682
+ </div>
683
+ </div>
684
+
685
+ <script>
686
+ (function () {
687
+ 'use strict';
688
+
689
+ /* ==================== KONFIGURASI ==================== */
690
+ const INITIAL_CASH = 1000000;
691
+ const WARMUP_BARS = 30;
692
+ const VISIBLE_BARS = 30;
693
+ const INTERVAL_TIME = 1000;
694
+
695
+ // Rentang harga awal acak untuk data sintetis
696
+ const START_PRICE_MIN = 100;
697
+ const START_PRICE_MAX = 5000;
698
+
699
+ // Nilai default untuk data sintetis
700
+ const DEFAULT_TOTAL_BARS = 250;
701
+
702
+ // Akan diubah secara dinamis sesuai sumber data
703
+ let TOTAL_BARS = DEFAULT_TOTAL_BARS;
704
+ let END_INDEX = WARMUP_BARS + TOTAL_BARS;
705
+
706
+ // === FEE ===
707
+ let feeBeli = 0.003;
708
+ let feeJual = 0.003;
709
+
710
+ // Warna per slot indikator utama
711
+ const SLOT_COLORS = ['#f0b90b', '#4fc3f7', '#e91e63'];
712
+
713
+ /* ==================== STATE ==================== */
714
+ let fullData = [];
715
+ let currentIndex = WARMUP_BARS;
716
+ let isPaused = false;
717
+ let finished = false;
718
+ let timer = null;
719
+
720
+ let cash = INITIAL_CASH;
721
+ let positionVolume = 0;
722
+ let avgBuyPrice = 0;
723
+
724
+ let dpr = 1;
725
+ let viewW = 0, viewH = 0;
726
+ let subViewW = 0, subViewH = 0;
727
+
728
+ // === Sumber data ===
729
+ let dataSource = 'synthetic'; // 'synthetic' | 'upload'
730
+ let uploadedData = null; // array OHLC hasil parsing file CSV
731
+
732
+ /* ==================== DOM ==================== */
733
+ const canvas = document.getElementById('tradingChart');
734
+ const ctx = canvas.getContext('2d');
735
+ const equityValEl = document.getElementById('equity-val');
736
+ const cashValEl = document.getElementById('cash-val');
737
+ const assetValEl = document.getElementById('asset-val');
738
+ const pnlPctEl = document.getElementById('pnl-pct');
739
+ const tickerPriceEl = document.getElementById('ticker-price');
740
+ const barProgressEl = document.getElementById('bar-progress');
741
+ const posInfoEl = document.getElementById('pos-info');
742
+
743
+ const subCanvas = document.getElementById('subChart');
744
+ const sctx = subCanvas.getContext('2d');
745
+
746
+ const ind1El = document.getElementById('ind1');
747
+ const ind2El = document.getElementById('ind2');
748
+ const ind3El = document.getElementById('ind3');
749
+ const subSelectEl = document.getElementById('subchart');
750
+
751
+ const feeBuyInput = document.getElementById('fee-buy-input');
752
+ const feeSellInput = document.getElementById('fee-sell-input');
753
+
754
+ const btnPause = document.getElementById('btn-pause');
755
+ const btnRestart = document.getElementById('btn-restart');
756
+ const btnBuy = document.getElementById('btn-buy');
757
+ const btnSell = document.getElementById('btn-sell');
758
+
759
+ const dsBtns = document.querySelectorAll('.ds-btn');
760
+ const csvInput = document.getElementById('csv-input');
761
+
762
+ /* ==================== UTILITAS ==================== */
763
+ function getTickSize(price) {
764
+ if (price < 200) return 1;
765
+ if (price < 500) return 2;
766
+ if (price < 2000) return 5;
767
+ if (price < 5000) return 10;
768
+ return 25;
769
+ }
770
+
771
+ function bulatkanFraksi(price, up) {
772
+ const tick = getTickSize(price);
773
+ return up
774
+ ? Math.ceil(price / tick) * tick
775
+ : Math.floor(price / tick) * tick;
776
+ }
777
+
778
+ function formatUnit(num) {
779
+ if (!isFinite(num)) num = 0;
780
+ return Math.round(num).toLocaleString('id-ID');
781
+ }
782
+
783
+ /* ==================== PARSER CSV ==================== */
784
+ // Mengubah string angka menjadi number. Mendukung:
785
+ // "1234.56" -> 1234.56
786
+ // "1,234.56" -> 1234.56
787
+ // "1234" -> 1234
788
+ // "$1234" -> 1234
789
+ function toNum(str) {
790
+ if (str === null || str === undefined) return NaN;
791
+ let s = String(str).trim();
792
+ if (!s || s === '-' || s === 'null' || s === 'N/A' || s === 'n/a') return NaN;
793
+ // Buang semua kecuali digit, titik, minus
794
+ s = s.replace(/[^\d.\-]/g, '');
795
+ if (!s || s === '-' || s === '.') return NaN;
796
+ return parseFloat(s);
797
+ }
798
+
799
+ function parseCSV(text) {
800
+ // Buang BOM UTF-8 di awal file (jika ada)
801
+ text = text.replace(/^\uFEFF/, '');
802
+
803
+ const lines = text.split(/\r?\n/).map(l => l.trim()).filter(l => l.length > 0);
804
+ if (lines.length < 2) throw new Error('File kosong atau terlalu pendek.');
805
+
806
+ // Deteksi delimiter: koma, titik koma, atau tab
807
+ const candidates = [',', ';', '\t'];
808
+ let sep = ',';
809
+ let maxCols = 0;
810
+ for (let i = 0; i < candidates.length; i++) {
811
+ const n = lines[0].split(candidates[i]).length;
812
+ if (n > maxCols) { maxCols = n; sep = candidates[i]; }
813
+ }
814
+
815
+ // Deteksi header
816
+ const firstCells = lines[0].split(sep).map(c => c.trim().toLowerCase().replace(/["']/g, ''));
817
+ const hasHeader = firstCells.some(c =>
818
+ /open|high|low|close|date|time|volume|adj/.test(c)
819
+ );
820
+
821
+ let colMap = null; // { open, high, low, close }
822
+ if (hasHeader) {
823
+ const findCol = (patterns) => {
824
+ for (let i = 0; i < firstCells.length; i++) {
825
+ for (let p = 0; p < patterns.length; p++) {
826
+ if (firstCells[i].indexOf(patterns[p]) !== -1) return i;
827
+ }
828
+ }
829
+ return -1;
830
+ };
831
+ const o = findCol(['open']);
832
+ const h = findCol(['high']);
833
+ const l = findCol(['low']);
834
+ const c = findCol(['close', 'last', 'price']);
835
+ if (o !== -1 && h !== -1 && l !== -1 && c !== -1) {
836
+ colMap = { open: o, high: h, low: l, close: c };
837
+ }
838
+ }
839
+
840
+ const startRow = hasHeader ? 1 : 0;
841
+ const data = [];
842
+
843
+ for (let r = startRow; r < lines.length; r++) {
844
+ const cells = lines[r].split(sep).map(c => c.trim().replace(/["']/g, ''));
845
+ if (cells.length < 4) continue;
846
+
847
+ let o, h, l, c;
848
+ if (colMap) {
849
+ o = toNum(cells[colMap.open]);
850
+ h = toNum(cells[colMap.high]);
851
+ l = toNum(cells[colMap.low]);
852
+ c = toNum(cells[colMap.close]);
853
+ } else {
854
+ // Ambil 4 nilai numerik pertama di baris ini (lewati kolom tanggal)
855
+ const nums = [];
856
+ for (let k = 0; k < cells.length; k++) {
857
+ const v = toNum(cells[k]);
858
+ if (isFinite(v)) nums.push(v);
859
+ if (nums.length >= 4) break;
860
+ }
861
+ if (nums.length < 4) continue;
862
+ o = nums[0]; h = nums[1]; l = nums[2]; c = nums[3];
863
+ }
864
+
865
+ if (!isFinite(o) || !isFinite(h) || !isFinite(l) || !isFinite(c)) continue;
866
+ if (o <= 0 || h <= 0 || l <= 0 || c <= 0) continue;
867
+
868
+ const realHigh = Math.max(o, h, l, c);
869
+ const realLow = Math.min(o, h, l, c);
870
+
871
+ data.push({
872
+ open: bulatkanFraksi(o, false),
873
+ high: bulatkanFraksi(realHigh, false),
874
+ low: bulatkanFraksi(realLow, true),
875
+ close: bulatkanFraksi(c, false)
876
+ });
877
+ }
878
+
879
+ return data;
880
+ }
881
+
882
+ /* ==================== SUMBER DATA ==================== */
883
+ function setDataSource(src) {
884
+ dataSource = src;
885
+ for (let i = 0; i < dsBtns.length; i++) {
886
+ const b = dsBtns[i];
887
+ b.classList.toggle('active', b.getAttribute('data-source') === src);
888
+ }
889
+ }
890
+
891
+ dsBtns.forEach(function (btn) {
892
+ btn.addEventListener('click', function () {
893
+ const src = btn.getAttribute('data-source');
894
+ if (src === 'upload') {
895
+ // Buka dialog pilih file
896
+ csvInput.click();
897
+ } else {
898
+ // Ganti ke sintetis (hanya jika sebelumnya bukan sintetis)
899
+ if (dataSource !== 'synthetic') {
900
+ setDataSource('synthetic');
901
+ startSimulation();
902
+ }
903
+ }
904
+ });
905
+ });
906
+
907
+ csvInput.addEventListener('change', function (e) {
908
+ const file = e.target.files && e.target.files[0];
909
+ // Reset value agar file yang sama bisa dipilih ulang
910
+ csvInput.value = '';
911
+ if (!file) return;
912
+
913
+ const reader = new FileReader();
914
+ reader.onload = function (ev) {
915
+ try {
916
+ const parsed = parseCSV(ev.target.result);
917
+ const minBars = WARMUP_BARS + 20;
918
+ if (parsed.length < minBars) {
919
+ alert(
920
+ 'File harus berisi minimal ' + minBars + ' baris data OHLC yang valid.\n' +
921
+ 'Ditemukan: ' + parsed.length + ' baris.\n\n' +
922
+ 'Format yang didukung:\n' +
923
+ '• open,high,low,close\n' +
924
+ '• date,open,high,low,close\n' +
925
+ '• Date,Open,High,Low,Close,Volume (dengan header)'
926
+ );
927
+ return;
928
+ }
929
+ uploadedData = parsed;
930
+ setDataSource('upload');
931
+ startSimulation();
932
+ } catch (err) {
933
+ alert('Gagal memproses file: ' + err.message);
934
+ }
935
+ };
936
+ reader.onerror = function () {
937
+ alert('Gagal membaca file.');
938
+ };
939
+ reader.readAsText(file);
940
+ });
941
+
942
+ /* ==================== DROPDOWN BISA DICARI ==================== */
943
+ const dropdownRegistry = [];
944
+
945
+ function normalizeSearch(str) {
946
+ return String(str).toLowerCase().replace(/[^a-z0-9]/g, '');
947
+ }
948
+
949
+ function closeAllDropdowns(except) {
950
+ for (let i = 0; i < dropdownRegistry.length; i++) {
951
+ const d = dropdownRegistry[i];
952
+ if (d !== except && d.isOpen()) d.close();
953
+ }
954
+ }
955
+
956
+ function createSearchableSelect(selectEl, barEl) {
957
+ const wrap = document.createElement('div');
958
+ wrap.className = 'ind-wrap';
959
+ selectEl.parentNode.insertBefore(wrap, selectEl);
960
+ wrap.appendChild(selectEl);
961
+ selectEl.classList.add('ind-native-hidden');
962
+ selectEl.setAttribute('aria-hidden', 'true');
963
+ selectEl.setAttribute('tabindex', '-1');
964
+
965
+ const trigger = document.createElement('button');
966
+ trigger.type = 'button';
967
+ trigger.className = 'ind-trigger';
968
+ trigger.setAttribute('aria-haspopup', 'listbox');
969
+ trigger.setAttribute('aria-expanded', 'false');
970
+ wrap.appendChild(trigger);
971
+
972
+ const panel = document.createElement('div');
973
+ panel.className = 'ind-panel';
974
+ panel.hidden = true;
975
+
976
+ const searchEl = document.createElement('input');
977
+ searchEl.type = 'text';
978
+ searchEl.className = 'ind-search';
979
+ searchEl.placeholder = 'Ketik untuk mencari...';
980
+ searchEl.autocomplete = 'off';
981
+ searchEl.spellcheck = false;
982
+ searchEl.setAttribute('aria-label', 'Cari indikator');
983
+
984
+ const listEl = document.createElement('div');
985
+ listEl.className = 'ind-list';
986
+ listEl.setAttribute('role', 'listbox');
987
+
988
+ panel.appendChild(searchEl);
989
+ panel.appendChild(listEl);
990
+ barEl.appendChild(panel);
991
+
992
+ let visibleOpts = [];
993
+ let highlightIdx = -1;
994
+ let isOpen = false;
995
+
996
+ const instance = {
997
+ trigger: trigger,
998
+ panel: panel,
999
+ isOpen: function () { return isOpen; },
1000
+ close: closePanel,
1001
+ contains: function (node) {
1002
+ if (!node) return false;
1003
+ return wrap.contains(node) || panel.contains(node);
1004
+ }
1005
+ };
1006
+ dropdownRegistry.push(instance);
1007
+
1008
+ function updateTriggerLabel() {
1009
+ const opt = selectEl.options[selectEl.selectedIndex];
1010
+ const label = opt ? opt.textContent : '';
1011
+ trigger.textContent = label;
1012
+ trigger.title = label;
1013
+ }
1014
+
1015
+ function setHighlight(idx) {
1016
+ if (highlightIdx >= 0 && visibleOpts[highlightIdx]) {
1017
+ visibleOpts[highlightIdx].el.classList.remove('highlight');
1018
+ }
1019
+ highlightIdx = idx;
1020
+ if (idx >= 0 && visibleOpts[idx]) {
1021
+ const el = visibleOpts[idx].el;
1022
+ el.classList.add('highlight');
1023
+ if (el.scrollIntoView) {
1024
+ el.scrollIntoView({ block: 'nearest' });
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+ function moveHighlight(dir) {
1030
+ if (visibleOpts.length === 0) return;
1031
+ let i = highlightIdx;
1032
+ for (let step = 0; step < visibleOpts.length; step++) {
1033
+ i += dir;
1034
+ if (i < 0) i = visibleOpts.length - 1;
1035
+ if (i >= visibleOpts.length) i = 0;
1036
+ if (!visibleOpts[i].disabled) {
1037
+ setHighlight(i);
1038
+ return;
1039
+ }
1040
+ }
1041
+ }
1042
+
1043
+ function choose(value) {
1044
+ selectEl.value = value;
1045
+ updateTriggerLabel();
1046
+ closePanel();
1047
+ try { trigger.focus(); } catch (err) {}
1048
+ selectEl.dispatchEvent(new Event('change', { bubbles: true }));
1049
+ }
1050
+
1051
+ function buildList(filter) {
1052
+ const nf = normalizeSearch(filter);
1053
+ listEl.innerHTML = '';
1054
+ visibleOpts = [];
1055
+ highlightIdx = -1;
1056
+
1057
+ const opts = selectEl.options;
1058
+ for (let i = 0; i < opts.length; i++) {
1059
+ const opt = opts[i];
1060
+ const label = opt.textContent;
1061
+ if (nf && normalizeSearch(label).indexOf(nf) === -1) continue;
1062
+
1063
+ const item = document.createElement('div');
1064
+ item.className = 'ind-opt';
1065
+ item.textContent = label;
1066
+ item.setAttribute('role', 'option');
1067
+
1068
+ const entry = {
1069
+ value: opt.value,
1070
+ label: label,
1071
+ disabled: !!opt.disabled,
1072
+ el: item
1073
+ };
1074
+ visibleOpts.push(entry);
1075
+ listEl.appendChild(item);
1076
+
1077
+ if (opt.disabled) {
1078
+ item.classList.add('disabled');
1079
+ item.setAttribute('aria-disabled', 'true');
1080
+ } else {
1081
+ if (opt.value === selectEl.value) item.classList.add('selected');
1082
+ item.addEventListener('click', function () {
1083
+ choose(entry.value);
1084
+ });
1085
+ item.addEventListener('mouseenter', function () {
1086
+ setHighlight(visibleOpts.indexOf(entry));
1087
+ });
1088
+ }
1089
+ }
1090
+
1091
+ if (visibleOpts.length === 0) {
1092
+ const empty = document.createElement('div');
1093
+ empty.className = 'ind-empty';
1094
+ empty.textContent = 'Tidak ditemukan';
1095
+ listEl.appendChild(empty);
1096
+ return;
1097
+ }
1098
+
1099
+ let idx = -1;
1100
+ for (let i = 0; i < visibleOpts.length; i++) {
1101
+ if (!visibleOpts[i].disabled && visibleOpts[i].value === selectEl.value) {
1102
+ idx = i;
1103
+ break;
1104
+ }
1105
+ }
1106
+ if (idx === -1) {
1107
+ for (let i = 0; i < visibleOpts.length; i++) {
1108
+ if (!visibleOpts[i].disabled) { idx = i; break; }
1109
+ }
1110
+ }
1111
+ setHighlight(idx);
1112
+ }
1113
+
1114
+ function positionPanel() {
1115
+ const PANEL_W = 220;
1116
+ const barRect = barEl.getBoundingClientRect();
1117
+ const wrapRect = wrap.getBoundingClientRect();
1118
+ const barW = barEl.clientWidth || barRect.width;
1119
+
1120
+ let left = wrapRect.left - barRect.left;
1121
+ const maxLeft = Math.max(8, barW - PANEL_W - 8);
1122
+ if (left > maxLeft) left = maxLeft;
1123
+ if (left < 8) left = 8;
1124
+
1125
+ panel.style.left = left + 'px';
1126
+ panel.style.width = PANEL_W + 'px';
1127
+ }
1128
+
1129
+ function openPanel(initialChar) {
1130
+ closeAllDropdowns(instance);
1131
+ panel.hidden = false;
1132
+ isOpen = true;
1133
+ trigger.setAttribute('aria-expanded', 'true');
1134
+
1135
+ searchEl.value = initialChar || '';
1136
+ buildList(searchEl.value);
1137
+ positionPanel();
1138
+
1139
+ try { searchEl.focus(); } catch (err) {}
1140
+ if (searchEl.setSelectionRange) {
1141
+ const len = searchEl.value.length;
1142
+ try { searchEl.setSelectionRange(len, len); } catch (err) {}
1143
+ }
1144
+ }
1145
+
1146
+ function closePanel() {
1147
+ if (!isOpen) return;
1148
+ panel.hidden = true;
1149
+ isOpen = false;
1150
+ trigger.setAttribute('aria-expanded', 'false');
1151
+ }
1152
+
1153
+ trigger.addEventListener('click', function (e) {
1154
+ e.stopPropagation();
1155
+ if (isOpen) closePanel();
1156
+ else openPanel('');
1157
+ });
1158
+
1159
+ trigger.addEventListener('keydown', function (e) {
1160
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp' ||
1161
+ e.key === 'Enter' || e.key === ' ') {
1162
+ e.preventDefault();
1163
+ if (!isOpen) openPanel('');
1164
+ return;
1165
+ }
1166
+ if (e.key === 'Escape') {
1167
+ if (isOpen) { e.preventDefault(); closePanel(); }
1168
+ return;
1169
+ }
1170
+ if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
1171
+ e.preventDefault();
1172
+ openPanel(e.key);
1173
+ }
1174
+ });
1175
+
1176
+ searchEl.addEventListener('input', function () {
1177
+ buildList(searchEl.value);
1178
+ });
1179
+
1180
+ searchEl.addEventListener('keydown', function (e) {
1181
+ if (e.key === 'ArrowDown') {
1182
+ e.preventDefault();
1183
+ moveHighlight(1);
1184
+ } else if (e.key === 'ArrowUp') {
1185
+ e.preventDefault();
1186
+ moveHighlight(-1);
1187
+ } else if (e.key === 'Enter') {
1188
+ e.preventDefault();
1189
+ if (highlightIdx >= 0 && visibleOpts[highlightIdx] &&
1190
+ !visibleOpts[highlightIdx].disabled) {
1191
+ choose(visibleOpts[highlightIdx].value);
1192
+ }
1193
+ } else if (e.key === 'Escape') {
1194
+ e.preventDefault();
1195
+ closePanel();
1196
+ try { trigger.focus(); } catch (err) {}
1197
+ } else if (e.key === 'Tab') {
1198
+ closePanel();
1199
+ }
1200
+ });
1201
+
1202
+ updateTriggerLabel();
1203
+ return instance;
1204
+ }
1205
+
1206
+ function setupSearchableSelects() {
1207
+ const barEl = document.querySelector('.indicator-bar');
1208
+ if (!barEl) return;
1209
+ const selects = barEl.querySelectorAll('select.ind-select');
1210
+ for (let i = 0; i < selects.length; i++) {
1211
+ createSearchableSelect(selects[i], barEl);
1212
+ }
1213
+ }
1214
+
1215
+ document.addEventListener('click', function (e) {
1216
+ for (let i = 0; i < dropdownRegistry.length; i++) {
1217
+ const d = dropdownRegistry[i];
1218
+ if (d.isOpen() && !d.contains(e.target)) d.close();
1219
+ }
1220
+ });
1221
+
1222
+ window.addEventListener('resize', function () {
1223
+ closeAllDropdowns(null);
1224
+ });
1225
+ window.addEventListener('orientationchange', function () {
1226
+ closeAllDropdowns(null);
1227
+ });
1228
+
1229
+ /* ==================== GENERATOR DATA SINTETIS ==================== */
1230
+ function generateSyntheticData(totalBars) {
1231
+ const data = [];
1232
+
1233
+ // Harga awal acak di antara START_PRICE_MIN s/d START_PRICE_MAX,
1234
+ // lalu dibulatkan ke tick yang valid.
1235
+ const rawStart = START_PRICE_MIN + Math.random() * (START_PRICE_MAX - START_PRICE_MIN);
1236
+ let currentPrice = bulatkanFraksi(rawStart, false);
1237
+ if (currentPrice < START_PRICE_MIN) currentPrice = START_PRICE_MIN;
1238
+
1239
+ for (let i = 0; i < totalBars; i++) {
1240
+ const changePercent = (Math.random() - 0.48) * 0.04;
1241
+ let newPrice = currentPrice * (1 + changePercent);
1242
+ if (newPrice < 50) newPrice = 50;
1243
+
1244
+ const open = bulatkanFraksi(currentPrice, false);
1245
+ const close = bulatkanFraksi(newPrice, false);
1246
+
1247
+ let high = bulatkanFraksi(Math.max(open, close) * (1 + Math.random() * 0.015), false);
1248
+ let low = bulatkanFraksi(Math.min(open, close) * (1 - Math.random() * 0.015), true);
1249
+ high = Math.max(high, open, close);
1250
+ low = Math.min(low, open, close);
1251
+ if (low <= 0) low = Math.max(1, Math.round(open * 0.9));
1252
+
1253
+ data.push({ open, high, low, close });
1254
+ currentPrice = close;
1255
+ }
1256
+ return data;
1257
+ }
1258
+
1259
+ /* ==================== KALKULASI INDIKATOR ==================== */
1260
+ function calcSMA(values, period) {
1261
+ const out = new Array(values.length).fill(null);
1262
+ let sum = 0;
1263
+ for (let i = 0; i < values.length; i++) {
1264
+ sum += values[i];
1265
+ if (i >= period) sum -= values[i - period];
1266
+ if (i >= period - 1) out[i] = sum / period;
1267
+ }
1268
+ return out;
1269
+ }
1270
+
1271
+ function calcEMA(values, period) {
1272
+ const out = new Array(values.length).fill(null);
1273
+ if (period < 1) return out;
1274
+ const k = 2 / (period + 1);
1275
+ let prev = null;
1276
+ for (let i = 0; i < values.length; i++) {
1277
+ if (i < period - 1) continue;
1278
+ if (prev === null) {
1279
+ let s = 0;
1280
+ for (let j = i - period + 1; j <= i; j++) s += values[j];
1281
+ prev = s / period;
1282
+ } else {
1283
+ prev = values[i] * k + prev * (1 - k);
1284
+ }
1285
+ out[i] = prev;
1286
+ }
1287
+ return out;
1288
+ }
1289
+
1290
+ function calcWMA(values, period) {
1291
+ const out = new Array(values.length).fill(null);
1292
+ const denom = period * (period + 1) / 2;
1293
+ for (let i = period - 1; i < values.length; i++) {
1294
+ let s = 0;
1295
+ for (let j = 0; j < period; j++) {
1296
+ s += values[i - period + 1 + j] * (j + 1);
1297
+ }
1298
+ out[i] = s / denom;
1299
+ }
1300
+ return out;
1301
+ }
1302
+
1303
+ function calcWilders(values, period) {
1304
+ const out = new Array(values.length).fill(null);
1305
+ let prev = null;
1306
+ for (let i = 0; i < values.length; i++) {
1307
+ if (i < period - 1) continue;
1308
+ if (prev === null) {
1309
+ let s = 0;
1310
+ for (let j = i - period + 1; j <= i; j++) s += values[j];
1311
+ prev = s / period;
1312
+ } else {
1313
+ prev = (prev * (period - 1) + values[i]) / period;
1314
+ }
1315
+ out[i] = prev;
1316
+ }
1317
+ return out;
1318
+ }
1319
+
1320
+ function calcBollinger(closes, period, mult) {
1321
+ period = period || 20;
1322
+ mult = mult || 2;
1323
+ const middle = calcSMA(closes, period);
1324
+ const upper = new Array(closes.length).fill(null);
1325
+ const lower = new Array(closes.length).fill(null);
1326
+ for (let i = period - 1; i < closes.length; i++) {
1327
+ let s = 0;
1328
+ for (let j = i - period + 1; j <= i; j++) {
1329
+ const d = closes[j] - middle[i];
1330
+ s += d * d;
1331
+ }
1332
+ const sd = Math.sqrt(s / period);
1333
+ upper[i] = middle[i] + mult * sd;
1334
+ lower[i] = middle[i] - mult * sd;
1335
+ }
1336
+ return { upper, middle, lower };
1337
+ }
1338
+
1339
+ function calcATR(data, period) {
1340
+ const tr = new Array(data.length).fill(0);
1341
+ for (let i = 0; i < data.length; i++) {
1342
+ if (i === 0) {
1343
+ tr[i] = data[i].high - data[i].low;
1344
+ } else {
1345
+ tr[i] = Math.max(
1346
+ data[i].high - data[i].low,
1347
+ Math.abs(data[i].high - data[i - 1].close),
1348
+ Math.abs(data[i].low - data[i - 1].close)
1349
+ );
1350
+ }
1351
+ }
1352
+ return calcWilders(tr, period);
1353
+ }
1354
+
1355
+ function calcSqueeze(data) {
1356
+ const closes = data.map(d => d.close);
1357
+ const bb = calcBollinger(closes, 20, 2);
1358
+ const atrArr = calcATR(data, 20);
1359
+ const kcMid = calcEMA(closes, 20);
1360
+ const squeezeOn = new Array(closes.length).fill(null);
1361
+ for (let i = 0; i < closes.length; i++) {
1362
+ if (bb.upper[i] === null || atrArr[i] === null || kcMid[i] === null) continue;
1363
+ const kcUp = kcMid[i] + 1.5 * atrArr[i];
1364
+ const kcLo = kcMid[i] - 1.5 * atrArr[i];
1365
+ squeezeOn[i] = (bb.upper[i] < kcUp && bb.lower[i] > kcLo) ? 1 : 0;
1366
+ }
1367
+ return squeezeOn;
1368
+ }
1369
+
1370
+ function calcRSI(closes, period) {
1371
+ period = period || 14;
1372
+ const out = new Array(closes.length).fill(null);
1373
+ let avgGain = 0, avgLoss = 0;
1374
+ for (let i = 1; i < closes.length; i++) {
1375
+ const ch = closes[i] - closes[i - 1];
1376
+ const g = Math.max(ch, 0);
1377
+ const l = Math.max(-ch, 0);
1378
+ if (i <= period) {
1379
+ avgGain += g;
1380
+ avgLoss += l;
1381
+ if (i === period) {
1382
+ avgGain /= period;
1383
+ avgLoss /= period;
1384
+ out[i] = avgLoss === 0 ? 100 : 100 - 100 / (1 + avgGain / avgLoss);
1385
+ }
1386
+ } else {
1387
+ avgGain = (avgGain * (period - 1) + g) / period;
1388
+ avgLoss = (avgLoss * (period - 1) + l) / period;
1389
+ out[i] = avgLoss === 0 ? 100 : 100 - 100 / (1 + avgGain / avgLoss);
1390
+ }
1391
+ }
1392
+ return out;
1393
+ }
1394
+
1395
+ function calcMACD(closes, fast, slow, sigPeriod) {
1396
+ fast = fast || 12;
1397
+ slow = slow || 26;
1398
+ sigPeriod = sigPeriod || 9;
1399
+ const emaFast = calcEMA(closes, fast);
1400
+ const emaSlow = calcEMA(closes, slow);
1401
+ const macdLine = new Array(closes.length).fill(null);
1402
+ for (let i = 0; i < closes.length; i++) {
1403
+ if (emaFast[i] !== null && emaSlow[i] !== null) {
1404
+ macdLine[i] = emaFast[i] - emaSlow[i];
1405
+ }
1406
+ }
1407
+ const signalLine = new Array(closes.length).fill(null);
1408
+ let prev = null, count = 0, sum = 0;
1409
+ const k = 2 / (sigPeriod + 1);
1410
+ for (let i = 0; i < closes.length; i++) {
1411
+ if (macdLine[i] === null) continue;
1412
+ count++;
1413
+ if (count < sigPeriod) {
1414
+ sum += macdLine[i];
1415
+ } else if (count === sigPeriod) {
1416
+ sum += macdLine[i];
1417
+ prev = sum / sigPeriod;
1418
+ signalLine[i] = prev;
1419
+ } else {
1420
+ prev = macdLine[i] * k + prev * (1 - k);
1421
+ signalLine[i] = prev;
1422
+ }
1423
+ }
1424
+ const hist = new Array(closes.length).fill(null);
1425
+ for (let i = 0; i < closes.length; i++) {
1426
+ if (macdLine[i] !== null && signalLine[i] !== null) {
1427
+ hist[i] = macdLine[i] - signalLine[i];
1428
+ }
1429
+ }
1430
+ return { macd: macdLine, signal: signalLine, hist };
1431
+ }
1432
+
1433
+ function getIndicatorSeries(sel, closes, data) {
1434
+ const m = /^(ma|ema|wma|wilders)(\d+)$/.exec(sel);
1435
+ if (m) {
1436
+ const type = m[1];
1437
+ const period = parseInt(m[2], 10);
1438
+ let values;
1439
+ if (type === 'ma') values = calcSMA(closes, period);
1440
+ else if (type === 'ema') values = calcEMA(closes, period);
1441
+ else if (type === 'wma') values = calcWMA(closes, period);
1442
+ else values = calcWilders(closes, period);
1443
+ return { type: 'line', lines: [{ values: values }] };
1444
+ }
1445
+
1446
+ switch (sel) {
1447
+ case 'bollinger': {
1448
+ const bb = calcBollinger(closes, 20, 2);
1449
+ return {
1450
+ type: 'line',
1451
+ lines: [
1452
+ { values: bb.upper },
1453
+ { values: bb.middle },
1454
+ { values: bb.lower }
1455
+ ]
1456
+ };
1457
+ }
1458
+ case 'squeeze':
1459
+ return { type: 'squeeze', values: calcSqueeze(data) };
1460
+ default:
1461
+ return null;
1462
+ }
1463
+ }
1464
+
1465
+ /* ==================== UKURAN CANVAS ==================== */
1466
+ function resizeCanvas() {
1467
+ const parent = canvas.parentElement;
1468
+ if (!parent) return;
1469
+
1470
+ const rect = parent.getBoundingClientRect();
1471
+ const w = Math.round(rect.width);
1472
+ const h = Math.round(rect.height);
1473
+ if (w <= 0 || h <= 0) return;
1474
+
1475
+ dpr = window.devicePixelRatio || 1;
1476
+ const pw = Math.round(w * dpr);
1477
+ const ph = Math.round(h * dpr);
1478
+
1479
+ if (canvas.width !== pw || canvas.height !== ph) {
1480
+ canvas.width = pw;
1481
+ canvas.height = ph;
1482
+ }
1483
+ viewW = w;
1484
+ viewH = h;
1485
+
1486
+ drawChart();
1487
+ }
1488
+
1489
+ function resizeSubCanvas() {
1490
+ const parent = subCanvas.parentElement;
1491
+ if (!parent) return;
1492
+
1493
+ const rect = parent.getBoundingClientRect();
1494
+ const w = Math.round(rect.width);
1495
+ const h = Math.round(rect.height);
1496
+ if (w <= 0 || h <= 0) return;
1497
+
1498
+ const _dpr = window.devicePixelRatio || 1;
1499
+ const pw = Math.round(w * _dpr);
1500
+ const ph = Math.round(h * _dpr);
1501
+
1502
+ if (subCanvas.width !== pw || subCanvas.height !== ph) {
1503
+ subCanvas.width = pw;
1504
+ subCanvas.height = ph;
1505
+ }
1506
+ subViewW = w;
1507
+ subViewH = h;
1508
+
1509
+ drawSubChart();
1510
+ }
1511
+
1512
+ /* ==================== RENDER GRAFIK UTAMA ==================== */
1513
+ function drawChart() {
1514
+ if (!viewW || !viewH) return;
1515
+
1516
+ const w = viewW;
1517
+ const h = viewH;
1518
+
1519
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1520
+ ctx.clearRect(0, 0, w, h);
1521
+
1522
+ const start = Math.max(0, currentIndex - VISIBLE_BARS + 1);
1523
+ const displayData = fullData.slice(start, currentIndex + 1);
1524
+ if (displayData.length === 0) return;
1525
+
1526
+ const closes = fullData.map(d => d.close);
1527
+ const indicators = [];
1528
+ const selVals = [ind1El.value, ind2El.value, ind3El.value];
1529
+ for (let s = 0; s < 3; s++) {
1530
+ if (!selVals[s]) continue;
1531
+ const series = getIndicatorSeries(selVals[s], closes, fullData);
1532
+ if (series) indicators.push({ sel: selVals[s], color: SLOT_COLORS[s], series });
1533
+ }
1534
+
1535
+ let highest = -Infinity;
1536
+ let lowest = Infinity;
1537
+ for (let i = 0; i < displayData.length; i++) {
1538
+ if (displayData[i].high > highest) highest = displayData[i].high;
1539
+ if (displayData[i].low < lowest) lowest = displayData[i].low;
1540
+ }
1541
+ for (let k = 0; k < indicators.length; k++) {
1542
+ const ind = indicators[k];
1543
+ if (!ind.series || ind.series.type !== 'line') continue;
1544
+ for (let li = 0; li < ind.series.lines.length; li++) {
1545
+ const values = ind.series.lines[li].values;
1546
+ for (let i = start; i <= currentIndex; i++) {
1547
+ const v = values[i];
1548
+ if (v === null || v === undefined) continue;
1549
+ if (v > highest) highest = v;
1550
+ if (v < lowest) lowest = v;
1551
+ }
1552
+ }
1553
+ }
1554
+ if (!isFinite(highest) || !isFinite(lowest)) return;
1555
+
1556
+ const padding = (highest - lowest) * 0.15 || 10;
1557
+ highest += padding;
1558
+ lowest -= padding;
1559
+ const range = (highest - lowest) || 1;
1560
+
1561
+ const candleWidth = w / VISIBLE_BARS;
1562
+
1563
+ ctx.lineWidth = 1;
1564
+ ctx.font = '10px Arial';
1565
+ ctx.textAlign = 'right';
1566
+ ctx.textBaseline = 'middle';
1567
+
1568
+ for (let g = 1; g < 4; g++) {
1569
+ const yGrid = (h / 4) * g;
1570
+ ctx.strokeStyle = '#23282d';
1571
+ ctx.beginPath();
1572
+ ctx.moveTo(0, yGrid);
1573
+ ctx.lineTo(w, yGrid);
1574
+ ctx.stroke();
1575
+
1576
+ ctx.fillStyle = '#848e9c';
1577
+ const priceLabel = highest - (range / 4) * g;
1578
+ ctx.fillText(formatUnit(priceLabel), w - 6, yGrid - 9);
1579
+ }
1580
+
1581
+ const bodyW = Math.max(candleWidth * 0.7, 1);
1582
+ const wickW = Math.max(1, Math.min(2, candleWidth * 0.12));
1583
+
1584
+ for (let i = 0; i < displayData.length; i++) {
1585
+ const candle = displayData[i];
1586
+ const x = i * candleWidth + (candleWidth - bodyW) / 2;
1587
+ const xc = x + bodyW / 2;
1588
+
1589
+ const yOpen = h - ((candle.open - lowest) / range) * h;
1590
+ const yClose = h - ((candle.close - lowest) / range) * h;
1591
+ const yHigh = h - ((candle.high - lowest) / range) * h;
1592
+ const yLow = h - ((candle.low - lowest) / range) * h;
1593
+
1594
+ const isBullish = candle.close >= candle.open;
1595
+ const color = isBullish ? '#0ecb81' : '#f6465d';
1596
+
1597
+ ctx.strokeStyle = color;
1598
+ ctx.fillStyle = color;
1599
+
1600
+ ctx.lineWidth = wickW;
1601
+ ctx.beginPath();
1602
+ ctx.moveTo(xc, yHigh);
1603
+ ctx.lineTo(xc, yLow);
1604
+ ctx.stroke();
1605
+
1606
+ const bodyTop = Math.min(yOpen, yClose);
1607
+ const bodyH = Math.max(Math.abs(yClose - yOpen), 1.5);
1608
+ ctx.fillRect(x, bodyTop, bodyW, bodyH);
1609
+ }
1610
+
1611
+ for (let k = 0; k < indicators.length; k++) {
1612
+ const ind = indicators[k];
1613
+ if (!ind.series || ind.series.type !== 'line') continue;
1614
+ const lines = ind.series.lines;
1615
+ for (let li = 0; li < lines.length; li++) {
1616
+ const values = lines[li].values;
1617
+ const isMid = (lines.length === 3 && li === 1);
1618
+
1619
+ ctx.strokeStyle = ind.color;
1620
+ ctx.lineWidth = isMid ? 1.6 : 1.1;
1621
+ ctx.setLineDash(!isMid && lines.length === 3 ? [4, 3] : []);
1622
+ ctx.beginPath();
1623
+
1624
+ let started = false;
1625
+ for (let i = 0; i < displayData.length; i++) {
1626
+ const gi = start + i;
1627
+ const v = values[gi];
1628
+ if (v === null || v === undefined) { started = false; continue; }
1629
+ const x = i * candleWidth + candleWidth / 2;
1630
+ const y = h - ((v - lowest) / range) * h;
1631
+ if (!started) { ctx.moveTo(x, y); started = true; }
1632
+ else ctx.lineTo(x, y);
1633
+ }
1634
+ ctx.stroke();
1635
+ ctx.setLineDash([]);
1636
+ }
1637
+ }
1638
+
1639
+ for (let k = 0; k < indicators.length; k++) {
1640
+ const ind = indicators[k];
1641
+ if (!ind.series || ind.series.type !== 'squeeze') continue;
1642
+ const values = ind.series.values;
1643
+ const dotY = h - 8;
1644
+ const dotR = Math.max(2, candleWidth * 0.14);
1645
+ ctx.fillStyle = ind.color;
1646
+ for (let i = 0; i < displayData.length; i++) {
1647
+ const gi = start + i;
1648
+ if (values[gi] !== 1) continue;
1649
+ const x = i * candleWidth + candleWidth / 2;
1650
+ ctx.beginPath();
1651
+ ctx.arc(x, dotY, dotR, 0, Math.PI * 2);
1652
+ ctx.fill();
1653
+ }
1654
+ }
1655
+
1656
+ /* ====== WATERMARK TENGAH GRAFIK (@sahamharian) ====== */
1657
+ ctx.save();
1658
+ const wmText = '@sahamharian';
1659
+ const wmSize = Math.max(20, Math.min(h * 0.08, w * 0.09));
1660
+ ctx.font = '900 ' + wmSize + 'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
1661
+ ctx.textAlign = 'center';
1662
+ ctx.textBaseline = 'middle';
1663
+
1664
+ const wmX = w / 2;
1665
+ const wmY = h / 2;
1666
+
1667
+ ctx.globalAlpha = 0.10;
1668
+ ctx.fillStyle = '#000000';
1669
+ ctx.fillText(wmText, wmX + 1.5, wmY + 1.5);
1670
+
1671
+ ctx.globalAlpha = 0.16;
1672
+ ctx.fillStyle = '#eaecef';
1673
+ ctx.fillText(wmText, wmX, wmY);
1674
+
1675
+ ctx.globalAlpha = 0.06;
1676
+ ctx.fillStyle = '#f0b90b';
1677
+ ctx.fillText(wmText, wmX, wmY - 0.5);
1678
+
1679
+ ctx.restore();
1680
+ /* ====== AKHIR WATERMARK ====== */
1681
+
1682
+ const lastCandle = displayData[displayData.length - 1];
1683
+ const yLast = h - ((lastCandle.close - lowest) / range) * h;
1684
+ ctx.save();
1685
+ ctx.setLineDash([4, 4]);
1686
+ ctx.strokeStyle = 'rgba(240, 185, 11, 0.55)';
1687
+ ctx.lineWidth = 1;
1688
+ ctx.beginPath();
1689
+ ctx.moveTo(0, yLast);
1690
+ ctx.lineTo(w, yLast);
1691
+ ctx.stroke();
1692
+ ctx.restore();
1693
+ }
1694
+
1695
+ /* ==================== RENDER GRAFIK BAWAH ==================== */
1696
+ function drawSubChart() {
1697
+ if (!subViewW || !subViewH) return;
1698
+
1699
+ const w = subViewW;
1700
+ const h = subViewH;
1701
+
1702
+ sctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1703
+ sctx.clearRect(0, 0, w, h);
1704
+
1705
+ sctx.fillStyle = '#0b0e11';
1706
+ sctx.fillRect(0, 0, w, h);
1707
+
1708
+ const type = subSelectEl.value;
1709
+ const start = Math.max(0, currentIndex - VISIBLE_BARS + 1);
1710
+ const count = currentIndex - start + 1;
1711
+ if (count <= 0) return;
1712
+
1713
+ const closes = fullData.map(d => d.close);
1714
+ const candleWidth = w / VISIBLE_BARS;
1715
+
1716
+ sctx.strokeStyle = '#23282d';
1717
+ sctx.lineWidth = 1;
1718
+ for (let g = 1; g < 3; g++) {
1719
+ const yGrid = (h / 3) * g;
1720
+ sctx.beginPath();
1721
+ sctx.moveTo(0, yGrid);
1722
+ sctx.lineTo(w, yGrid);
1723
+ sctx.stroke();
1724
+ }
1725
+
1726
+ if (type === 'rsi') {
1727
+ const rsiVals = calcRSI(closes, 14);
1728
+ const toY = (v) => h - (v / 100) * h;
1729
+
1730
+ sctx.strokeStyle = 'rgba(132,142,156,0.35)';
1731
+ sctx.setLineDash([4, 4]);
1732
+ [30, 70].forEach(lvl => {
1733
+ const y = toY(lvl);
1734
+ sctx.beginPath();
1735
+ sctx.moveTo(0, y);
1736
+ sctx.lineTo(w, y);
1737
+ sctx.stroke();
1738
+ });
1739
+ sctx.setLineDash([]);
1740
+
1741
+ sctx.fillStyle = '#848e9c';
1742
+ sctx.font = '9px Arial';
1743
+ sctx.textAlign = 'left';
1744
+ sctx.textBaseline = 'middle';
1745
+ sctx.fillText('70', 4, toY(70));
1746
+ sctx.fillText('30', 4, toY(30));
1747
+ sctx.textBaseline = 'top';
1748
+ sctx.fillText('RSI(14)', 4, 4);
1749
+
1750
+ sctx.strokeStyle = '#f0b90b';
1751
+ sctx.lineWidth = 1.5;
1752
+ sctx.beginPath();
1753
+ let started = false;
1754
+ for (let i = 0; i < count; i++) {
1755
+ const gi = start + i;
1756
+ const v = rsiVals[gi];
1757
+ if (v === null || v === undefined) { started = false; continue; }
1758
+ const x = i * candleWidth + candleWidth / 2;
1759
+ const y = toY(v);
1760
+ if (!started) { sctx.moveTo(x, y); started = true; }
1761
+ else sctx.lineTo(x, y);
1762
+ }
1763
+ sctx.stroke();
1764
+
1765
+ } else if (type === 'macd') {
1766
+ const m = calcMACD(closes, 12, 26, 9);
1767
+
1768
+ let hi = 0, lo = 0;
1769
+ for (let i = 0; i < count; i++) {
1770
+ const gi = start + i;
1771
+ const vals = [m.macd[gi], m.signal[gi], m.hist[gi]];
1772
+ for (let k = 0; k < vals.length; k++) {
1773
+ const v = vals[k];
1774
+ if (v === null || v === undefined) continue;
1775
+ if (v > hi) hi = v;
1776
+ if (v < lo) lo = v;
1777
+ }
1778
+ }
1779
+ if (hi === lo) { hi = 1; lo = -1; }
1780
+ const pad = (hi - lo) * 0.1;
1781
+ hi += pad; lo -= pad;
1782
+ const rng = (hi - lo) || 1;
1783
+ const toY = (v) => h - ((v - lo) / rng) * h;
1784
+
1785
+ sctx.strokeStyle = 'rgba(132,142,156,0.4)';
1786
+ sctx.setLineDash([4, 4]);
1787
+ sctx.beginPath();
1788
+ sctx.moveTo(0, toY(0));
1789
+ sctx.lineTo(w, toY(0));
1790
+ sctx.stroke();
1791
+ sctx.setLineDash([]);
1792
+
1793
+ sctx.fillStyle = '#848e9c';
1794
+ sctx.font = '9px Arial';
1795
+ sctx.textAlign = 'left';
1796
+ sctx.textBaseline = 'top';
1797
+ sctx.fillText('MACD(12,26,9)', 4, 4);
1798
+
1799
+ for (let i = 0; i < count; i++) {
1800
+ const gi = start + i;
1801
+ const v = m.hist[gi];
1802
+ if (v === null || v === undefined) continue;
1803
+ const x = i * candleWidth + candleWidth * 0.15;
1804
+ const bw = Math.max(candleWidth * 0.7, 1);
1805
+ const y0 = toY(0);
1806
+ const yv = toY(v);
1807
+ sctx.fillStyle = v >= 0 ? 'rgba(14,203,129,0.55)' : 'rgba(246,70,93,0.55)';
1808
+ sctx.fillRect(x, Math.min(y0, yv), bw, Math.max(Math.abs(yv - y0), 1));
1809
+ }
1810
+
1811
+ sctx.strokeStyle = '#4fc3f7';
1812
+ sctx.lineWidth = 1.5;
1813
+ sctx.beginPath();
1814
+ let started = false;
1815
+ for (let i = 0; i < count; i++) {
1816
+ const gi = start + i;
1817
+ const v = m.macd[gi];
1818
+ if (v === null || v === undefined) { started = false; continue; }
1819
+ const x = i * candleWidth + candleWidth / 2;
1820
+ const y = toY(v);
1821
+ if (!started) { sctx.moveTo(x, y); started = true; }
1822
+ else sctx.lineTo(x, y);
1823
+ }
1824
+ sctx.stroke();
1825
+
1826
+ sctx.strokeStyle = '#e91e63';
1827
+ sctx.lineWidth = 1.5;
1828
+ sctx.beginPath();
1829
+ started = false;
1830
+ for (let i = 0; i < count; i++) {
1831
+ const gi = start + i;
1832
+ const v = m.signal[gi];
1833
+ if (v === null || v === undefined) { started = false; continue; }
1834
+ const x = i * candleWidth + candleWidth / 2;
1835
+ const y = toY(v);
1836
+ if (!started) { sctx.moveTo(x, y); started = true; }
1837
+ else sctx.lineTo(x, y);
1838
+ }
1839
+ sctx.stroke();
1840
+ }
1841
+ }
1842
+
1843
+ /* ==================== UPDATE UI ==================== */
1844
+ function updateUI() {
1845
+ const bar = fullData[currentIndex];
1846
+ const currentPrice = bar ? bar.close : 0;
1847
+
1848
+ const assetValue = positionVolume * currentPrice;
1849
+ const totalEquity = cash + assetValue;
1850
+ const totalPnL = ((totalEquity - INITIAL_CASH) / INITIAL_CASH) * 100;
1851
+
1852
+ equityValEl.textContent = formatUnit(totalEquity);
1853
+ cashValEl.textContent = formatUnit(cash);
1854
+ assetValEl.textContent = formatUnit(assetValue);
1855
+ tickerPriceEl.textContent = formatUnit(currentPrice);
1856
+
1857
+ const progress = Math.min(Math.max(currentIndex - WARMUP_BARS, 0), TOTAL_BARS);
1858
+ barProgressEl.textContent = progress + '/' + TOTAL_BARS;
1859
+
1860
+ pnlPctEl.textContent = (totalPnL >= 0 ? '+' : '') + totalPnL.toFixed(2) + '%';
1861
+
1862
+ if (totalPnL > 0) {
1863
+ pnlPctEl.style.backgroundColor = 'rgba(14, 203, 129, 0.2)';
1864
+ pnlPctEl.style.color = '#0ecb81';
1865
+ } else if (totalPnL < 0) {
1866
+ pnlPctEl.style.backgroundColor = 'rgba(246, 70, 93, 0.2)';
1867
+ pnlPctEl.style.color = '#f6465d';
1868
+ } else {
1869
+ pnlPctEl.style.backgroundColor = 'rgba(255,255,255,0.1)';
1870
+ pnlPctEl.style.color = '#eaecef';
1871
+ }
1872
+
1873
+ posInfoEl.textContent =
1874
+ 'Posisi saat ini: ' + formatUnit(positionVolume) +
1875
+ ' Unit (Rata-rata: ' + formatUnit(avgBuyPrice) + ')';
1876
+ }
1877
+
1878
+ /* ==================== AKSI TRADING ==================== */
1879
+ function doBuy() {
1880
+ const bar = fullData[currentIndex];
1881
+ if (!bar || finished || isPaused) return;
1882
+
1883
+ const currentPrice = bar.close;
1884
+ const maxBuyable = cash / (currentPrice * (1 + feeBeli));
1885
+ const buyVolume = Math.floor(maxBuyable);
1886
+ if (buyVolume <= 0) return;
1887
+
1888
+ const cost = buyVolume * currentPrice;
1889
+ const fee = cost * feeBeli;
1890
+
1891
+ cash -= (cost + fee);
1892
+
1893
+ const totalCostOld = positionVolume * avgBuyPrice;
1894
+ const totalCostNew = buyVolume * currentPrice;
1895
+ positionVolume += buyVolume;
1896
+ avgBuyPrice = (totalCostOld + totalCostNew) / positionVolume;
1897
+
1898
+ updateUI();
1899
+ }
1900
+
1901
+ function doSell() {
1902
+ const bar = fullData[currentIndex];
1903
+ if (!bar || finished || isPaused) return;
1904
+ if (positionVolume <= 0) return;
1905
+
1906
+ const currentPrice = bar.close;
1907
+ const revenue = positionVolume * currentPrice;
1908
+ const fee = revenue * feeJual;
1909
+
1910
+ cash += (revenue - fee);
1911
+ positionVolume = 0;
1912
+ avgBuyPrice = 0;
1913
+
1914
+ updateUI();
1915
+ }
1916
+
1917
+ /* ==================== LOOP SIMULASI ==================== */
1918
+ function step() {
1919
+ if (isPaused || finished) return;
1920
+
1921
+ currentIndex++;
1922
+
1923
+ if (currentIndex >= END_INDEX) {
1924
+ currentIndex = END_INDEX;
1925
+ finished = true;
1926
+ clearInterval(timer);
1927
+ timer = null;
1928
+
1929
+ updateUI();
1930
+ drawChart();
1931
+ drawSubChart();
1932
+
1933
+ btnBuy.disabled = true;
1934
+ btnSell.disabled = true;
1935
+ posInfoEl.textContent = '✅ Simulasi selesai! Tekan Restart untuk mencoba lagi.';
1936
+ return;
1937
+ }
1938
+
1939
+ updateUI();
1940
+ drawChart();
1941
+ drawSubChart();
1942
+ }
1943
+
1944
+ function startSimulation() {
1945
+ clearInterval(timer);
1946
+ timer = null;
1947
+
1948
+ // Tentukan sumber data & sesuaikan END_INDEX / TOTAL_BARS
1949
+ if (dataSource === 'upload' && uploadedData && uploadedData.length > 0) {
1950
+ fullData = uploadedData.slice();
1951
+ END_INDEX = fullData.length - 1;
1952
+ TOTAL_BARS = Math.max(1, END_INDEX - WARMUP_BARS);
1953
+ } else {
1954
+ dataSource = 'synthetic';
1955
+ setDataSource('synthetic');
1956
+ TOTAL_BARS = DEFAULT_TOTAL_BARS;
1957
+ END_INDEX = WARMUP_BARS + TOTAL_BARS;
1958
+ fullData = generateSyntheticData(END_INDEX + 10);
1959
+ }
1960
+
1961
+ // Reset state trading
1962
+ cash = INITIAL_CASH;
1963
+ positionVolume = 0;
1964
+ avgBuyPrice = 0;
1965
+ currentIndex = WARMUP_BARS;
1966
+ isPaused = false;
1967
+ finished = false;
1968
+
1969
+ btnPause.textContent = '⏸ Pause';
1970
+ btnBuy.disabled = false;
1971
+ btnSell.disabled = false;
1972
+
1973
+ resizeCanvas();
1974
+ resizeSubCanvas();
1975
+ updateUI();
1976
+ drawChart();
1977
+ drawSubChart();
1978
+
1979
+ timer = setInterval(step, INTERVAL_TIME);
1980
+ }
1981
+
1982
+ /* ==================== EVENT LISTENER ==================== */
1983
+ btnPause.addEventListener('click', function () {
1984
+ if (finished) return;
1985
+ isPaused = !isPaused;
1986
+ btnPause.textContent = isPaused ? '▶️ Resume' : '⏸ Pause';
1987
+ });
1988
+
1989
+ btnRestart.addEventListener('click', startSimulation);
1990
+ btnBuy.addEventListener('click', doBuy);
1991
+ btnSell.addEventListener('click', doSell);
1992
+
1993
+ ind1El.addEventListener('change', drawChart);
1994
+ ind2El.addEventListener('change', drawChart);
1995
+ ind3El.addEventListener('change', drawChart);
1996
+
1997
+ subSelectEl.addEventListener('change', drawSubChart);
1998
+
1999
+ function updateFees() {
2000
+ let buyVal = parseFloat(feeBuyInput.value);
2001
+ let sellVal = parseFloat(feeSellInput.value);
2002
+ if (isNaN(buyVal) || buyVal < 0) buyVal = 0;
2003
+ if (isNaN(sellVal) || sellVal < 0) sellVal = 0;
2004
+ if (buyVal > 10) buyVal = 10;
2005
+ if (sellVal > 10) sellVal = 10;
2006
+ feeBeli = buyVal / 100;
2007
+ feeJual = sellVal / 100;
2008
+ }
2009
+ feeBuyInput.addEventListener('input', updateFees);
2010
+ feeSellInput.addEventListener('input', updateFees);
2011
+
2012
+ window.addEventListener('resize', function () {
2013
+ resizeCanvas();
2014
+ resizeSubCanvas();
2015
+ });
2016
+ window.addEventListener('orientationchange', function () {
2017
+ setTimeout(function () {
2018
+ resizeCanvas();
2019
+ resizeSubCanvas();
2020
+ }, 150);
2021
+ });
2022
+
2023
+ if (typeof ResizeObserver !== 'undefined') {
2024
+ new ResizeObserver(resizeCanvas).observe(canvas.parentElement);
2025
+ new ResizeObserver(resizeSubCanvas).observe(subCanvas.parentElement);
2026
+ }
2027
+
2028
+ /* ==================== INISIALISASI ==================== */
2029
+ function init() {
2030
+ setupSearchableSelects();
2031
+ updateFees();
2032
+ setDataSource('synthetic');
2033
+ startSimulation();
2034
+ requestAnimationFrame(function () {
2035
+ resizeCanvas();
2036
+ resizeSubCanvas();
2037
+ });
2038
+ setTimeout(function () {
2039
+ resizeCanvas();
2040
+ resizeSubCanvas();
2041
+ }, 150);
2042
+ }
2043
+
2044
+ if (document.readyState === 'loading') {
2045
+ document.addEventListener('DOMContentLoaded', init);
2046
+ } else {
2047
+ init();
2048
+ }
2049
+ })();
2050
+ </script>
2051
+ </body>
2052
+ </html>