Repository navigation
Expand file tree
/
Copy pathNebula_v3.cpp
More file actions
2258 lines (2137 loc) · 79.3 KB
/
Copy pathNebula_v3.cpp
File metadata and controls
2258 lines (2137 loc) · 79.3 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
#include "sierrachart.h"
#include <vector>
#include <algorithm>
#include <cmath>
#include <type_traits>
SCDLLName("Nebula v3")
namespace nebula
{
struct Col
{
float r, g, b, t;
};
constexpr COLORREF Hex(uint32_t h)
{
return RGB((h >> 16) & 0xFF, (h >> 8) & 0xFF, h & 0xFF);
}
inline Col C(COLORREF c, float t = 0.0f)
{
return Col{ (float)GetRValue(c), (float)GetGValue(c), (float)GetBValue(c), t };
}
inline Col T(Col c, float t)
{
c.t = t;
return c;
}
inline float Clamp(float v, float lo, float hi)
{
return v < lo ? lo : (v > hi ? hi : v);
}
inline Col Grad(float v, float lo, float hi, Col a, Col b)
{
if (!std::isfinite(v))
return a;
float f = hi == lo ? 1.0f : Clamp((v - lo) / (hi - lo), 0.0f, 1.0f);
return Col{ a.r + (b.r - a.r) * f, a.g + (b.g - a.g) * f, a.b + (b.b - a.b) * f, a.t + (b.t - a.t) * f };
}
inline COLORREF Ref(Col c, COLORREF bg)
{
float a = 1.0f - Clamp(c.t, 0.0f, 100.0f) / 100.0f;
int r = (int)std::lround(c.r * a + GetRValue(bg) * (1.0f - a));
int g = (int)std::lround(c.g * a + GetGValue(bg) * (1.0f - a));
int b = (int)std::lround(c.b * a + GetBValue(bg) * (1.0f - a));
return RGB(r, g, b);
}
inline Col Darken(Col c, float k)
{
return Col{ c.r * k, c.g * k, c.b * k, c.t };
}
inline bool Ok(float v)
{
return std::isfinite(v) != 0;
}
inline float Nz(float v, float d = 0.0f)
{
return std::isfinite(v) ? v : d;
}
float Sma(SCFloatArrayRef a, int i, int n)
{
if (n > i + 1)
n = i + 1;
double s = 0;
for (int k = 0; k < n; k++)
s += a[i - k];
return (float)(s / n);
}
float Stdev(SCFloatArrayRef a, int i, int n)
{
if (n > i + 1)
n = i + 1;
double m = 0;
for (int k = 0; k < n; k++)
m += a[i - k];
m /= n;
double v = 0;
for (int k = 0; k < n; k++)
v += (a[i - k] - m) * (a[i - k] - m);
return (float)std::sqrt(v / n);
}
float Wma(SCFloatArrayRef a, int i, int n)
{
if (n > i + 1)
n = i + 1;
double s = 0, w = 0;
for (int k = 0; k < n; k++)
{
double wk = n - k;
s += a[i - k] * wk;
w += wk;
}
return (float)(s / w);
}
float Highest(SCFloatArrayRef a, int i, int n)
{
float h = -FLT_MAX;
for (int k = 0; k < n && i - k >= 0; k++)
h = (std::max)(h, a[i - k]);
return h;
}
float Lowest(SCFloatArrayRef a, int i, int n)
{
float l = FLT_MAX;
for (int k = 0; k < n && i - k >= 0; k++)
l = (std::min)(l, a[i - k]);
return l;
}
float Linreg(SCFloatArrayRef a, int i, int n)
{
if (n > i + 1)
n = i + 1;
if (n < 2)
return a[i];
double sx = 0, sy = 0, sxy = 0, sxx = 0;
for (int k = 0; k < n; k++)
{
double x = k;
double y = a[i - n + 1 + k];
sx += x;
sy += y;
sxy += x * y;
sxx += x * x;
}
double slope = (n * sxy - sx * sy) / (n * sxx - sx * sx);
double icpt = (sy - slope * sx) / n;
return (float)(icpt + slope * (n - 1));
}
void EmaStep(SCFloatArrayRef out, float v, int i, int n)
{
float al = 2.0f / (n + 1);
if (i == 0 || !Ok(out[i - 1]))
out[i] = v;
else
out[i] = al * v + (1.0f - al) * out[i - 1];
}
void RmaStep(SCFloatArrayRef out, float v, int i, int n)
{
float al = 1.0f / n;
if (i == 0 || !Ok(out[i - 1]))
out[i] = v;
else
out[i] = al * v + (1.0f - al) * out[i - 1];
}
inline bool CrossOver(float a0, float a1, float b0, float b1)
{
return a0 > b0 && a1 <= b1;
}
inline bool CrossUnder(float a0, float a1, float b0, float b1)
{
return a0 < b0 && a1 >= b1;
}
inline bool InSession(int t, int start, int end)
{
if (start < end)
return t >= start && t < end;
return t >= start || t < end;
}
SCString Bar(float pct, int blocks)
{
int full = (int)std::lround(Clamp(pct, 0.0f, 100.0f) / 100.0f * blocks);
SCString s;
for (int b = 1; b <= blocks; b++)
s += b <= full ? "|" : ".";
return s;
}
struct Imbalance
{
int Bar;
float Level;
float Fill;
int Dir;
};
struct Tag
{
float Price;
SCString Name;
COLORREF Color;
};
const COLORREF THEME_BULL[] = {
Hex(0x00ff00), Hex(0x00f5f1), Hex(0x03fcf4), Hex(0x35defc), Hex(0x39ff14), Hex(0x00f0ff), Hex(0x64ffda),
Hex(0x4dd0e1), Hex(0xffc857), Hex(0xa3be8c), Hex(0x50fa7b), Hex(0x7aa2f7), Hex(0xffd700), Hex(0x00bfff),
Hex(0x00e04b), Hex(0x1e88e5), Hex(0xffc400), Hex(0x76ff03), Hex(0x1de9b6) };
const COLORREF THEME_BEAR[] = {
Hex(0xff0000), Hex(0xfc03f8), Hex(0xfca903), Hex(0xfcf11c), Hex(0xff073a), Hex(0xff2a6d), Hex(0xb388ff),
Hex(0xff8a65), Hex(0xe84855), Hex(0xbf616a), Hex(0xff79c6), Hex(0xf7768e), Hex(0x9d4edd), Hex(0xff4500),
Hex(0xffd600), Hex(0xe53935), Hex(0xd50000), Hex(0xaa00ff), Hex(0xff9100) };
const COLORREF CLOUD_UP[] = {
0, Hex(0x00d4c8), Hex(0x2ecc71), Hex(0x4fc3f7), Hex(0xc6ff00), Hex(0xffd54f), Hex(0x1de9b6),
Hex(0x69f0ae), Hex(0x2979ff), Hex(0x00a86b), Hex(0x40e0d0), Hex(0x8c9eff), Hex(0x80deea) };
const COLORREF CLOUD_DN[] = {
0, Hex(0xff6f61), Hex(0xe74c3c), Hex(0xba68c8), Hex(0xff9100), Hex(0x7c4dff), Hex(0xf50057),
Hex(0xff80ab), Hex(0xffab00), Hex(0xe0115f), Hex(0xff6347), Hex(0xffab91), Hex(0xff3d00) };
const COLORREF GRAY = Hex(0x787b86);
const COLORREF PINE_RED = Hex(0xf23645);
const COLORREF PINE_PURPLE = Hex(0x9c27b0);
const COLORREF PINE_ORANGE = Hex(0xff9800);
const COLORREF YELLOW = Hex(0xffeb3b);
const COLORREF BLUE_VECTOR = RGB(83, 144, 249);
const COLORREF VIOLET_VECTOR = Hex(0xe040fb);
const COLORREF REG_UP = Hex(0x02a433);
const COLORREF REG_DN = Hex(0xa10101);
enum CandleMode
{
NCM_NONE, NCM_VECTOR, NCM_WADDAH, NCM_SQUEEZE, NCM_VOLUME_DELTA, NCM_TREND_AGREEMENT, NCM_TIDAL_WAVE,
NCM_CONFLUENCE, NCM_RSI_HEAT, NCM_KERNEL_SLOPE, NCM_RELATIVE_VOLUME, NCM_ADX_STRENGTH, NCM_HEIKIN_ASHI,
NCM_STRETCH, NCM_SUPERTREND
};
enum CloudType
{
NCT_NONE, NCT_SIMPLE, NCT_RSI, NCT_MFI, NCT_CCI
};
enum SubgraphIndex
{
SG_CANDLE_OUTLINE, SG_CANDLE_BODY, SG_CLOUD_TOP, SG_CLOUD_BOTTOM, SG_SQZ_TOP, SG_SQZ_BOTTOM,
SG_SQZ_EDGE_TOP, SG_SQZ_EDGE_BOTTOM, SG_HEMA, SG_BUY, SG_SELL, SG_STRONG_BUY, SG_STRONG_SELL,
SG_ADD_LONG, SG_ADD_SHORT, SG_VODKA_LONG, SG_VODKA_SHORT, SG_TP_ALL, SG_TP_PARTIAL, SG_DIV_BULL,
SG_DIV_BEAR, SG_CROSS_UP, SG_CROSS_DOWN, SG_SQZ_REL_UP, SG_SQZ_REL_DOWN, SG_ORB_UP, SG_ORB_DOWN,
SG_FANVMA, SG_MCGINLEY, SG_CALC0
};
enum InputIndex
{
IN_CANDLE_MODE, IN_THEME, IN_CLOUD_TYPE, IN_CLOUD_PALETTE, IN_SHOW_DASH, IN_SHOW_SQZ, IN_SHOW_DIV,
IN_SHOW_LEVELS, IN_SHOW_HEMA, IN_SHOW_PLUS, IN_SHOW_VODKA, IN_SHOW_921, IN_SHOW_VI, IN_BG_COLOR,
IN_TEXT_COLOR, IN_DASH_POS, IN_DASH_FONT, IN_DASH_LEVELS, IN_DASH_SPACING, IN_BAR_BLOCKS,
IN_SQZ_COLOR, IN_SQZ_MIN, IN_SQZ_RELEASE, IN_DIV_LINES, IN_DIV_TRANSP, IN_DIV_RSI, IN_DIV_LBL, IN_DIV_LBR,
IN_DIV_MIN, IN_DIV_MAX, IN_OR_ON, IN_OR_START, IN_OR_END, IN_LON_ON, IN_LON_START, IN_LON_END,
IN_ASIA_ON, IN_ASIA_START, IN_ASIA_END, IN_YC_ON, IN_RTH_START, IN_RTH_END, IN_LVL_EXT, IN_LVL_FORMING,
IN_LVL_BREAK, IN_LVL_MERGE, IN_LVL_OFFSET, IN_LVL_TRANSP, IN_VI_EXTEND, IN_VI_WIDTH, IN_VI_STYLE,
IN_TP_PARTIAL, IN_TP_ALL, IN_QUAD_921, IN_CLOUD_SIMPLE_T, IN_CLOUD_WEAK_T, IN_CLOUD_STRONG_T,
IN_WAE_SENS, IN_WAE_FAST, IN_WAE_SLOW, IN_WAE_CHANNEL, IN_WAE_MULT, IN_SQ_TOL, IN_SHARK_2575,
IN_MARKER_SPACING, IN_ALERTS_ON, IN_ALERT_NUMBER
};
enum ArrayIndex
{
A_TR, A_ATR14, A_ATR30, A_ATR10, A_EMA9, A_EMA21, A_EMA14, A_PDM, A_MDM, A_DI_PLUS, A_DI_MINUS, A_ADX_IN, A_ADX,
A_CVD_BUY, A_CVD_SELL, A_TD_B, A_TD_S, A_LUX, A_FR_UP, A_FR_DN, A_UP_CLOSE, A_DN_CLOSE, A_EARLY,
A_RSI_UP, A_RSI_DN, A_RSI14, A_FV_SPDI, A_FV_SMDI, A_FV_STR, A_FV_ADX, A_FV_VAR, A_EMA_FAST, A_EMA_SLOW,
A_MACD, A_T1, A_E1, A_T1S, A_E1S, A_TRAMP_DN, A_TRAMP_UP, A_GO_UP, A_GO_DN, A_TRAMP, A_SQ_ON, A_SQ_SRC,
A_SQ_VAL, A_SQ_CR, A_SQ_CG, A_SQ_POS, A_SQ_NEG, A_SQZ, A_SQ_LEN, A_PV_CODE, A_SHARK, A_DEADREV, A_BANDS,
A_RSIU_UP, A_RSIU_DN, A_RSIU, A_RSIU_BASIS, A_RSIU_UPPER, A_RSIU_LOWER, A_RSIU_MA, A_PI_UPPER, A_PI_LOWER,
A_ATRB_UPPER, A_ATRB_LOWER, A_LAST_BUY_WATCH, A_LAST_SELL_WATCH, A_PLOT_BUY, A_PLOT_SELL, A_NZVOL,
A_VOL_AVGL, A_VOLA, A_DER_C, A_DER_CP, A_DER_CM, A_DER_BO, A_DER_BC, A_WMA1, A_WMA2, A_LLW, A_UPW, A_DNW,
A_KERNEL, A_RSID_UP, A_RSID_DN, A_RSID, A_PL_FOUND, A_PL_RSI, A_PL_LOW, A_PL_BAR, A_PH_FOUND, A_PH_RSI,
A_PH_HIGH, A_PH_BAR, A_DIVB_X1, A_DIVB_Y1, A_DIVS_X1, A_DIVS_Y1, A_TP_COUNT, A_WAVE, A_BRIGHT_G, A_BRIGHT_R,
A_SIG_WAVE, A_HEMA_B, A_RSI_HEAT, A_KSLOPE, A_RELVOL_S, A_ADX_S, A_HA_OPEN, A_ZSCORE, A_ST_UPPER,
A_ST_LOWER, A_ST_DIR, A_ST_VAL, A_CVD, A_DER_SUPN, A_DER_DEMN, A_VOLA_RAW, A_CCI_TP,
A_S0_HI, A_S0_LO, A_S0_START, A_S0_END, A_S0_STATE, A_S0_HIBRK, A_S0_LOBRK,
A_S1_HI, A_S1_LO, A_S1_START, A_S1_END, A_S1_STATE, A_S1_HIBRK, A_S1_LOBRK,
A_S2_HI, A_S2_LO, A_S2_START, A_S2_END, A_S2_STATE, A_S2_HIBRK, A_S2_LOBRK,
A_YC_VAL, A_YC_X, A_ORB_DIR, A_ORB_BAR, A_ORB_POSTHI, A_ORB_POSTLO, A_OR_DONE_SIZE,
A_COUNT
};
const int ARRAYS_PER_SUBGRAPH = 1 + MAX_SUBGRAPH_EXTRA_ARRAYS;
const int CALC_SUBGRAPHS = (A_COUNT + ARRAYS_PER_SUBGRAPH - 1) / ARRAYS_PER_SUBGRAPH;
enum SessionSlot
{
NSESS_OR = 0, NSESS_LON = 1, NSESS_ASIA = 2
};
enum SessionState
{
NSS_IDLE = 0, NSS_FORMING = 1, NSS_DONE = 2
};
const int LN_DASH = 781000;
const int LN_LEVEL_LINE = 782000;
const int LN_LEVEL_TAG = 783000;
const int LN_FORMING = 784000;
const int LN_IMBALANCE = 785000;
const int LN_DIV_LINE = 786000;
const int MAX_DASH_ROWS = 20;
const int MAX_LEVEL_LINES = 20;
const int MAX_FORMING = 3;
const int MAX_IMBALANCES = 150;
const int MAX_DIV_LINES = 40;
}
using namespace nebula;
template <typename TObj>
static auto TrySetTransparency(TObj& obj, int value, int) -> decltype(obj.TransparencyLevel = 0, void())
{
obj.TransparencyLevel = static_cast<typename std::remove_reference<decltype(obj.TransparencyLevel)>::type>(value);
}
template <typename TObj>
static void TrySetTransparency(TObj&, int, long)
{
}
static SCFloatArrayRef Arr(SCStudyInterfaceRef sc, int n)
{
int sg = SG_CALC0 + n / ARRAYS_PER_SUBGRAPH;
int k = n % ARRAYS_PER_SUBGRAPH;
if (k == 0)
return sc.Subgraph[sg].Data;
return sc.Subgraph[sg].Arrays[k - 1];
}
static void DeleteSlots(SCStudyInterfaceRef sc, int base, int from, int to)
{
for (int k = from; k < to; k++)
sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_CHARTDRAWING, base + k + sc.StudyGraphInstanceID * 10000);
}
static void UseSlot(SCStudyInterfaceRef sc, s_UseTool& tool, int lineNumber)
{
tool.ChartNumber = sc.ChartNumber;
tool.Region = sc.GraphRegion;
tool.LineNumber = lineNumber + sc.StudyGraphInstanceID * 10000;
tool.AddMethod = UTAM_ADD_OR_ADJUST;
sc.UseTool(tool);
}
static SCString TimeframeLabel(int seconds)
{
SCString s;
if (seconds <= 0)
s = "";
else if (seconds < 60)
s.Format("%ds", seconds);
else if (seconds < 3600)
s.Format("%dm", seconds / 60);
else if (seconds < 86400)
s.Format("%dh", seconds / 3600);
else
s.Format("%dD", seconds / 86400);
return s;
}
static SCString Pad(const char* text, int width)
{
SCString s = text;
while ((int)s.GetLength() < width)
s += " ";
return s;
}
SCSFExport scsf_NebulaV3(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Nebula v3";
sc.StudyDescription = "Nebula v3 by TraderOracle: trend cloud, Tidal Wave signals, take-profit confluence, RSI divergences, squeeze zones, session levels and dashboard. Designed for 1-minute NQ.";
sc.GraphRegion = 0;
sc.AutoLoop = 0;
sc.ValueFormat = VALUEFORMAT_INHERITED;
sc.ScaleRangeType = SCALE_SAMEASREGION;
sc.DrawStudyUnderneathMainPriceGraph = 0;
TrySetTransparency(sc, 80, 0);
sc.GlobalDisplayStudySubgraphsNameAndValue = 0;
sc.DisplayStudyInputValues = 0;
struct SgDef { int Index; const char* Name; int Style; COLORREF Color; int Width; };
const SgDef defs[] = {
{ SG_CANDLE_OUTLINE, "Candle Outline", DRAWSTYLE_COLOR_BAR, RGB(128, 128, 128), 1 },
{ SG_CANDLE_BODY, "Candle Body", DRAWSTYLE_COLOR_BAR_CANDLE_FILL, RGB(128, 128, 128), 1 },
{ SG_CLOUD_TOP, "Cloud Top", DRAWSTYLE_TRANSPARENT_FILL_TOP, RGB(0, 255, 0), 1 },
{ SG_CLOUD_BOTTOM, "Cloud Bottom", DRAWSTYLE_TRANSPARENT_FILL_BOTTOM, RGB(0, 255, 0), 1 },
{ SG_SQZ_TOP, "Squeeze Zone Top", DRAWSTYLE_TRANSPARENT_FILL_TOP, RGB(33, 150, 243), 1 },
{ SG_SQZ_BOTTOM, "Squeeze Zone Bottom", DRAWSTYLE_TRANSPARENT_FILL_BOTTOM, RGB(33, 150, 243), 1 },
{ SG_SQZ_EDGE_TOP, "Squeeze Edge Top", DRAWSTYLE_LINE_SKIP_ZEROS, RGB(33, 150, 243), 1 },
{ SG_SQZ_EDGE_BOTTOM, "Squeeze Edge Bottom", DRAWSTYLE_LINE_SKIP_ZEROS, RGB(33, 150, 243), 1 },
{ SG_HEMA, "HEMA", DRAWSTYLE_LINE_SKIP_ZEROS, Hex(0xe040fb), 1 },
{ SG_BUY, "Buy", DRAWSTYLE_POINT, RGB(0, 255, 0), 5 },
{ SG_SELL, "Sell", DRAWSTYLE_POINT, RGB(255, 0, 0), 5 },
{ SG_STRONG_BUY, "Strong Buy", DRAWSTYLE_ARROW_UP, RGB(0, 255, 0), 3 },
{ SG_STRONG_SELL, "Strong Sell", DRAWSTYLE_ARROW_DOWN, RGB(153, 0, 0), 3 },
{ SG_ADD_LONG, "Add Long (light)", DRAWSTYLE_PLUS, RGB(0, 255, 0), 2 },
{ SG_ADD_SHORT, "Add Short (light)", DRAWSTYLE_PLUS, RGB(255, 0, 0), 2 },
{ SG_VODKA_LONG, "Add Long (Vodka Shot)", DRAWSTYLE_PLUS, RGB(0, 255, 0), 5 },
{ SG_VODKA_SHORT, "Add Short (Vodka Shot)", DRAWSTYLE_PLUS, RGB(255, 0, 0), 5 },
{ SG_TP_ALL, "Take All Profit", DRAWSTYLE_STAR, PINE_RED, 5 },
{ SG_TP_PARTIAL, "Take Partial Profit", DRAWSTYLE_DIAMOND, PINE_PURPLE, 4 },
{ SG_DIV_BULL, "Bullish Divergence", DRAWSTYLE_CUSTOM_TEXT, RGB(0, 255, 0), 8 },
{ SG_DIV_BEAR, "Bearish Divergence", DRAWSTYLE_CUSTOM_TEXT, RGB(255, 0, 0), 8 },
{ SG_CROSS_UP, "9/21 Cross Up", DRAWSTYLE_TRIANGLE_UP, YELLOW, 2 },
{ SG_CROSS_DOWN, "9/21 Cross Down", DRAWSTYLE_TRIANGLE_DOWN, YELLOW, 2 },
{ SG_SQZ_REL_UP, "Squeeze Release Up", DRAWSTYLE_ARROW_UP, RGB(0, 255, 0), 2 },
{ SG_SQZ_REL_DOWN, "Squeeze Release Down", DRAWSTYLE_ARROW_DOWN, RGB(255, 0, 0), 2 },
{ SG_ORB_UP, "OR Breakout Up", DRAWSTYLE_TRIANGLE_UP, RGB(0, 255, 0), 3 },
{ SG_ORB_DOWN, "OR Breakout Down", DRAWSTYLE_TRIANGLE_DOWN, RGB(255, 0, 0), 3 },
{ SG_FANVMA, "Fantail VMA", DRAWSTYLE_IGNORE, RGB(255, 255, 255), 1 },
{ SG_MCGINLEY, "McGinley Dynamic", DRAWSTYLE_IGNORE, RGB(0, 0, 255), 1 },
};
for (const SgDef& d : defs)
{
SCSubgraphRef s = sc.Subgraph[d.Index];
s.Name = d.Name;
s.DrawStyle = d.Style;
s.PrimaryColor = d.Color;
s.LineWidth = d.Width;
s.DrawZeros = 0;
s.DisplayNameValueInWindowsFlags = 0;
}
sc.Subgraph[SG_DIV_BULL].TextDrawStyleText = "Div";
sc.Subgraph[SG_DIV_BEAR].TextDrawStyleText = "Div";
sc.Subgraph[SG_SQZ_EDGE_TOP].LineStyle = LINESTYLE_SOLID;
for (int k = 0; k < CALC_SUBGRAPHS; k++)
{
SCString name;
name.Format("Calc %d", k + 1);
sc.Subgraph[SG_CALC0 + k].Name = name;
sc.Subgraph[SG_CALC0 + k].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[SG_CALC0 + k].DrawZeros = 0;
sc.Subgraph[SG_CALC0 + k].DisplayNameValueInWindowsFlags = 0;
}
sc.Input[IN_CANDLE_MODE].Name = "Candle Coloring";
sc.Input[IN_CANDLE_MODE].SetCustomInputStrings("None;Vector;Waddah;Squeeze;Volume Delta;Trend Agreement;Tidal Wave;Signal Confluence;RSI Heat;Kernel Slope;Relative Volume;ADX Strength;Heikin Ashi Trend;Stretch from Mean;Supertrend");
sc.Input[IN_CANDLE_MODE].SetCustomInputIndex(NCM_WADDAH);
sc.Input[IN_THEME].Name = "Color Theme";
sc.Input[IN_THEME].SetCustomInputStrings("Standard;Pinky and the Brain;Color Blind;Mellow Yellow;Neon;Cyberpunk;Aurora;Ocean;Sunset;Nord;Dracula;Tokyo Night;Royal;Ice and Fire;Green Lantern;Superman;Wonder Woman;Hulk;Aquaman");
sc.Input[IN_THEME].SetCustomInputIndex(0);
sc.Input[IN_CLOUD_TYPE].Name = "Cloud Type";
sc.Input[IN_CLOUD_TYPE].SetCustomInputStrings("None;Simple;Relative Strength;Money Flow;Commodity Channel");
sc.Input[IN_CLOUD_TYPE].SetCustomInputIndex(NCT_SIMPLE);
sc.Input[IN_CLOUD_PALETTE].Name = "Cloud Colors";
sc.Input[IN_CLOUD_PALETTE].SetCustomInputStrings("Theme;Aqua / Coral;Emerald / Crimson;Sky / Orchid;Lime / Tangerine;Gold / Violet;Teal / Magenta;Mint / Rose;Cobalt / Amber;Jade / Ruby;Turquoise / Tomato;Periwinkle / Peach;Ice / Lava");
sc.Input[IN_CLOUD_PALETTE].SetCustomInputIndex(0);
sc.Input[IN_SHOW_DASH].Name = "Show dashboard";
sc.Input[IN_SHOW_DASH].SetYesNo(0);
sc.Input[IN_SHOW_SQZ].Name = "Show squeeze zones";
sc.Input[IN_SHOW_SQZ].SetYesNo(1);
sc.Input[IN_SHOW_DIV].Name = "Show RSI divergences";
sc.Input[IN_SHOW_DIV].SetYesNo(1);
sc.Input[IN_SHOW_LEVELS].Name = "Show session levels";
sc.Input[IN_SHOW_LEVELS].SetYesNo(1);
sc.Input[IN_SHOW_HEMA].Name = "Show HEMA line";
sc.Input[IN_SHOW_HEMA].SetYesNo(0);
sc.Input[IN_SHOW_PLUS].Name = "Show plus sign to add";
sc.Input[IN_SHOW_PLUS].SetYesNo(0);
sc.Input[IN_SHOW_VODKA].Name = "Show bigger plus sign (Vodka Shot)";
sc.Input[IN_SHOW_VODKA].SetYesNo(1);
sc.Input[IN_SHOW_921].Name = "Show 9/21 EMA cross";
sc.Input[IN_SHOW_921].SetYesNo(0);
sc.Input[IN_SHOW_VI].Name = "Show volume imbalances";
sc.Input[IN_SHOW_VI].SetYesNo(0);
sc.Input[IN_BG_COLOR].Name = "Chart background color (for blending)";
sc.Input[IN_BG_COLOR].SetColor(RGB(0, 0, 0));
sc.Input[IN_TEXT_COLOR].Name = "Chart text color (neutral elements)";
sc.Input[IN_TEXT_COLOR].SetColor(RGB(209, 212, 220));
sc.Input[IN_DASH_POS].Name = "Dashboard: Position";
sc.Input[IN_DASH_POS].SetCustomInputStrings("Top Right;Top Center;Top Left;Middle Right;Middle Left;Bottom Right;Bottom Center;Bottom Left");
sc.Input[IN_DASH_POS].SetCustomInputIndex(0);
sc.Input[IN_DASH_FONT].Name = "Dashboard: Font size";
sc.Input[IN_DASH_FONT].SetInt(9);
sc.Input[IN_DASH_FONT].SetIntLimits(6, 30);
sc.Input[IN_DASH_LEVELS].Name = "Dashboard: Show session levels";
sc.Input[IN_DASH_LEVELS].SetYesNo(1);
sc.Input[IN_DASH_SPACING].Name = "Dashboard: Row spacing (% of chart height)";
sc.Input[IN_DASH_SPACING].SetFloat(2.8f);
sc.Input[IN_DASH_SPACING].SetFloatLimits(1.0f, 10.0f);
sc.Input[IN_BAR_BLOCKS].Name = "Dashboard: Bar length (blocks)";
sc.Input[IN_BAR_BLOCKS].SetInt(10);
sc.Input[IN_BAR_BLOCKS].SetIntLimits(5, 20);
sc.Input[IN_SQZ_COLOR].Name = "Squeeze zones: Color";
sc.Input[IN_SQZ_COLOR].SetColor(RGB(33, 150, 243));
sc.Input[IN_SQZ_MIN].Name = "Squeeze zones: Minimum length (bars)";
sc.Input[IN_SQZ_MIN].SetInt(3);
sc.Input[IN_SQZ_MIN].SetIntLimits(1, 500);
sc.Input[IN_SQZ_RELEASE].Name = "Squeeze zones: Show release arrows";
sc.Input[IN_SQZ_RELEASE].SetYesNo(0);
sc.Input[IN_DIV_LINES].Name = "RSI divergence: Draw lines on price";
sc.Input[IN_DIV_LINES].SetYesNo(0);
sc.Input[IN_DIV_TRANSP].Name = "RSI divergence: Transparency";
sc.Input[IN_DIV_TRANSP].SetInt(50);
sc.Input[IN_DIV_TRANSP].SetIntLimits(0, 100);
sc.Input[IN_DIV_RSI].Name = "RSI divergence: RSI length";
sc.Input[IN_DIV_RSI].SetInt(14);
sc.Input[IN_DIV_RSI].SetIntLimits(1, 500);
sc.Input[IN_DIV_LBL].Name = "RSI divergence: Pivot lookback left";
sc.Input[IN_DIV_LBL].SetInt(5);
sc.Input[IN_DIV_LBL].SetIntLimits(1, 100);
sc.Input[IN_DIV_LBR].Name = "RSI divergence: Pivot lookback right";
sc.Input[IN_DIV_LBR].SetInt(5);
sc.Input[IN_DIV_LBR].SetIntLimits(1, 100);
sc.Input[IN_DIV_MIN].Name = "RSI divergence: Min bars between pivots";
sc.Input[IN_DIV_MIN].SetInt(5);
sc.Input[IN_DIV_MIN].SetIntLimits(1, 1000);
sc.Input[IN_DIV_MAX].Name = "RSI divergence: Max bars between pivots";
sc.Input[IN_DIV_MAX].SetInt(60);
sc.Input[IN_DIV_MAX].SetIntLimits(2, 1000);
sc.Input[IN_OR_ON].Name = "Session levels: Opening range";
sc.Input[IN_OR_ON].SetYesNo(1);
sc.Input[IN_OR_START].Name = "Session levels: Opening range start (New York)";
sc.Input[IN_OR_START].SetTime(9 * 3600 + 30 * 60);
sc.Input[IN_OR_END].Name = "Session levels: Opening range end (New York)";
sc.Input[IN_OR_END].SetTime(10 * 3600 + 30 * 60);
sc.Input[IN_LON_ON].Name = "Session levels: London";
sc.Input[IN_LON_ON].SetYesNo(1);
sc.Input[IN_LON_START].Name = "Session levels: London start (New York)";
sc.Input[IN_LON_START].SetTime(3 * 3600);
sc.Input[IN_LON_END].Name = "Session levels: London end (New York)";
sc.Input[IN_LON_END].SetTime(8 * 3600);
sc.Input[IN_ASIA_ON].Name = "Session levels: Asia";
sc.Input[IN_ASIA_ON].SetYesNo(1);
sc.Input[IN_ASIA_START].Name = "Session levels: Asia start (New York)";
sc.Input[IN_ASIA_START].SetTime(18 * 3600);
sc.Input[IN_ASIA_END].Name = "Session levels: Asia end (New York)";
sc.Input[IN_ASIA_END].SetTime(3 * 3600);
sc.Input[IN_YC_ON].Name = "Session levels: Yesterday's close";
sc.Input[IN_YC_ON].SetYesNo(1);
sc.Input[IN_RTH_START].Name = "Session levels: Regular session start (New York)";
sc.Input[IN_RTH_START].SetTime(9 * 3600 + 30 * 60);
sc.Input[IN_RTH_END].Name = "Session levels: Regular session end (New York)";
sc.Input[IN_RTH_END].SetTime(16 * 3600);
sc.Input[IN_LVL_EXT].Name = "Session levels: Opening range extensions (1.5x / 2x)";
sc.Input[IN_LVL_EXT].SetYesNo(1);
sc.Input[IN_LVL_FORMING].Name = "Session levels: Shade ranges while they form";
sc.Input[IN_LVL_FORMING].SetYesNo(1);
sc.Input[IN_LVL_BREAK].Name = "Session levels: Mark opening range breakout";
sc.Input[IN_LVL_BREAK].SetYesNo(1);
sc.Input[IN_LVL_MERGE].Name = "Session levels: Merge tags within (ticks)";
sc.Input[IN_LVL_MERGE].SetInt(8);
sc.Input[IN_LVL_MERGE].SetIntLimits(0, 1000);
sc.Input[IN_LVL_OFFSET].Name = "Session levels: Tag distance from last bar";
sc.Input[IN_LVL_OFFSET].SetInt(4);
sc.Input[IN_LVL_OFFSET].SetIntLimits(1, 50);
sc.Input[IN_LVL_TRANSP].Name = "Session levels: Level transparency";
sc.Input[IN_LVL_TRANSP].SetInt(45);
sc.Input[IN_LVL_TRANSP].SetIntLimits(0, 100);
sc.Input[IN_VI_EXTEND].Name = "Volume imbalances: Bars to extend line";
sc.Input[IN_VI_EXTEND].SetInt(50);
sc.Input[IN_VI_EXTEND].SetIntLimits(10, 500);
sc.Input[IN_VI_WIDTH].Name = "Volume imbalances: Line width";
sc.Input[IN_VI_WIDTH].SetInt(3);
sc.Input[IN_VI_WIDTH].SetIntLimits(1, 10);
sc.Input[IN_VI_STYLE].Name = "Volume imbalances: Line style";
sc.Input[IN_VI_STYLE].SetCustomInputStrings("Solid;Dotted;Dashed");
sc.Input[IN_VI_STYLE].SetCustomInputIndex(1);
sc.Input[IN_TP_PARTIAL].Name = "Advanced: Minimum signals for take partial profit";
sc.Input[IN_TP_PARTIAL].SetInt(5);
sc.Input[IN_TP_PARTIAL].SetIntLimits(2, 50);
sc.Input[IN_TP_ALL].Name = "Advanced: Minimum signals for take ALL profit";
sc.Input[IN_TP_ALL].SetInt(7);
sc.Input[IN_TP_ALL].SetIntLimits(3, 50);
sc.Input[IN_QUAD_921].Name = "Advanced: Use quadratic equation for 9/21 cross";
sc.Input[IN_QUAD_921].SetYesNo(0);
sc.Input[IN_CLOUD_SIMPLE_T].Name = "Advanced: Simple cloud transparency";
sc.Input[IN_CLOUD_SIMPLE_T].SetInt(80);
sc.Input[IN_CLOUD_SIMPLE_T].SetIntLimits(0, 100);
sc.Input[IN_CLOUD_WEAK_T].Name = "Advanced: Weak trend transparency";
sc.Input[IN_CLOUD_WEAK_T].SetInt(80);
sc.Input[IN_CLOUD_WEAK_T].SetIntLimits(0, 100);
sc.Input[IN_CLOUD_STRONG_T].Name = "Advanced: Strong trend transparency";
sc.Input[IN_CLOUD_STRONG_T].SetInt(50);
sc.Input[IN_CLOUD_STRONG_T].SetIntLimits(0, 100);
sc.Input[IN_WAE_SENS].Name = "WAE: Sensitivity";
sc.Input[IN_WAE_SENS].SetInt(150);
sc.Input[IN_WAE_FAST].Name = "WAE: FastEMA length";
sc.Input[IN_WAE_FAST].SetInt(20);
sc.Input[IN_WAE_FAST].SetIntLimits(1, 500);
sc.Input[IN_WAE_SLOW].Name = "WAE: SlowEMA length";
sc.Input[IN_WAE_SLOW].SetInt(40);
sc.Input[IN_WAE_SLOW].SetIntLimits(1, 500);
sc.Input[IN_WAE_CHANNEL].Name = "WAE: BB channel length";
sc.Input[IN_WAE_CHANNEL].SetInt(20);
sc.Input[IN_WAE_CHANNEL].SetIntLimits(1, 500);
sc.Input[IN_WAE_MULT].Name = "WAE: BB stdev multiplier";
sc.Input[IN_WAE_MULT].SetFloat(2.0f);
sc.Input[IN_SQ_TOL].Name = "Squeeze tolerance (lower = more sensitive)";
sc.Input[IN_SQ_TOL].SetInt(2);
sc.Input[IN_SQ_TOL].SetIntLimits(0, 100);
sc.Input[IN_SHARK_2575].Name = "Shark: Apply 25/75 RSI rule";
sc.Input[IN_SHARK_2575].SetYesNo(0);
sc.Input[IN_MARKER_SPACING].Name = "Marker spacing from bar (x ATR 14)";
sc.Input[IN_MARKER_SPACING].SetFloat(0.3f);
sc.Input[IN_MARKER_SPACING].SetFloatLimits(0.0f, 5.0f);
sc.Input[IN_ALERTS_ON].Name = "Alerts: Any Nebula signal";
sc.Input[IN_ALERTS_ON].SetYesNo(1);
sc.Input[IN_ALERT_NUMBER].Name = "Alerts: Alert sound number";
sc.Input[IN_ALERT_NUMBER].SetInt(1);
sc.Input[IN_ALERT_NUMBER].SetIntLimits(1, 150);
return;
}
std::vector<Imbalance>* imbalances = (std::vector<Imbalance>*)sc.GetPersistentPointer(1);
if (sc.LastCallToFunction)
{
if (imbalances != nullptr)
{
delete imbalances;
sc.SetPersistentPointer(1, nullptr);
}
return;
}
if (imbalances == nullptr)
{
imbalances = new std::vector<Imbalance>();
sc.SetPersistentPointer(1, imbalances);
}
int& lastImbalanceBar = sc.GetPersistentInt(1);
int& prevLevelLines = sc.GetPersistentInt(2);
int& prevLevelTags = sc.GetPersistentInt(3);
int& prevForming = sc.GetPersistentInt(4);
int& prevImbalanceLines = sc.GetPersistentInt(5);
int& prevDivLines = sc.GetPersistentInt(6);
int& prevDashRows = sc.GetPersistentInt(7);
int& lastAlertBar = sc.GetPersistentInt(8);
const int candleMode = sc.Input[IN_CANDLE_MODE].GetIndex();
const int theme = (std::min)((int)sc.Input[IN_THEME].GetIndex(), 18);
const int cloudType = sc.Input[IN_CLOUD_TYPE].GetIndex();
const int palette = (std::min)((int)sc.Input[IN_CLOUD_PALETTE].GetIndex(), 12);
const bool showDash = sc.Input[IN_SHOW_DASH].GetYesNo() != 0;
const bool showSqz = sc.Input[IN_SHOW_SQZ].GetYesNo() != 0;
const bool showDiv = sc.Input[IN_SHOW_DIV].GetYesNo() != 0;
const bool showLevels = sc.Input[IN_SHOW_LEVELS].GetYesNo() != 0;
const bool showHema = sc.Input[IN_SHOW_HEMA].GetYesNo() != 0;
const bool showPlus = sc.Input[IN_SHOW_PLUS].GetYesNo() != 0;
const bool showVodka = sc.Input[IN_SHOW_VODKA].GetYesNo() != 0;
const bool show921 = sc.Input[IN_SHOW_921].GetYesNo() != 0;
const bool showVI = sc.Input[IN_SHOW_VI].GetYesNo() != 0;
const COLORREF bg = sc.Input[IN_BG_COLOR].GetColor();
const COLORREF fg = sc.Input[IN_TEXT_COLOR].GetColor();
const int sqzMin = sc.Input[IN_SQZ_MIN].GetInt();
const bool sqzRelease = sc.Input[IN_SQZ_RELEASE].GetYesNo() != 0;
const bool divLines = sc.Input[IN_DIV_LINES].GetYesNo() != 0;
const int divTransp = sc.Input[IN_DIV_TRANSP].GetInt();
const int divRsiLen = sc.Input[IN_DIV_RSI].GetInt();
const int lbL = sc.Input[IN_DIV_LBL].GetInt();
const int lbR = sc.Input[IN_DIV_LBR].GetInt();
const int divMin = sc.Input[IN_DIV_MIN].GetInt();
const int divMax = sc.Input[IN_DIV_MAX].GetInt();
const int viExtend = sc.Input[IN_VI_EXTEND].GetInt();
const int tpPartial = sc.Input[IN_TP_PARTIAL].GetInt();
const int tpAll = sc.Input[IN_TP_ALL].GetInt();
const bool quad921 = sc.Input[IN_QUAD_921].GetYesNo() != 0;
const float waeSens = (float)sc.Input[IN_WAE_SENS].GetInt();
const int waeFast = sc.Input[IN_WAE_FAST].GetInt();
const int waeSlow = sc.Input[IN_WAE_SLOW].GetInt();
const int waeChannel = sc.Input[IN_WAE_CHANNEL].GetInt();
const float waeMult = sc.Input[IN_WAE_MULT].GetFloat();
const int sqTol = sc.Input[IN_SQ_TOL].GetInt();
const bool shark2575 = sc.Input[IN_SHARK_2575].GetYesNo() != 0;
const float markerSpacing = sc.Input[IN_MARKER_SPACING].GetFloat();
const bool alertsOn = sc.Input[IN_ALERTS_ON].GetYesNo() != 0;
const int alertNumber = sc.Input[IN_ALERT_NUMBER].GetInt();
const int sessStart[3] = { sc.Input[IN_OR_START].GetTime(), sc.Input[IN_LON_START].GetTime(), sc.Input[IN_ASIA_START].GetTime() };
const int sessEnd[3] = { sc.Input[IN_OR_END].GetTime(), sc.Input[IN_LON_END].GetTime(), sc.Input[IN_ASIA_END].GetTime() };
const int rthStart = sc.Input[IN_RTH_START].GetTime();
const int rthEnd = sc.Input[IN_RTH_END].GetTime();
const Col G = C(THEME_BULL[theme]);
const Col R = C(THEME_BEAR[theme]);
const Col cloudUp = palette == 0 ? G : C(CLOUD_UP[palette]);
const Col cloudDn = palette == 0 ? R : C(CLOUD_DN[palette]);
const Col grayC = C(GRAY);
const Col strongSellRed = Darken(R, 0.6f);
const int simpleT = sc.Input[IN_CLOUD_SIMPLE_T].GetInt();
const int weakT = sc.Input[IN_CLOUD_WEAK_T].GetInt();
const int strongT = sc.Input[IN_CLOUD_STRONG_T].GetInt();
{
const int fillT = cloudType == NCT_SIMPLE ? simpleT : strongT;
TrySetTransparency(sc, fillT, 0);
TrySetTransparency(sc.Subgraph[SG_CLOUD_TOP], fillT, 0);
TrySetTransparency(sc.Subgraph[SG_CLOUD_BOTTOM], fillT, 0);
TrySetTransparency(sc.Subgraph[SG_SQZ_TOP], fillT, 0);
TrySetTransparency(sc.Subgraph[SG_SQZ_BOTTOM], fillT, 0);
}
const int ATR30 = 30;
const float kernelH = 21.0f, kernelR = 8.0f;
const int kernelX0 = 15;
float kernelW[64];
float kernelWSum = 0;
for (int k = 0; k <= 1 + kernelX0; k++)
{
kernelW[k] = (float)std::pow(1.0 + (k * k) / (kernelH * kernelH * 2.0 * kernelR), -kernelR);
kernelWSum += kernelW[k];
}
if (sc.UpdateStartIndex == 0)
{
imbalances->clear();
lastImbalanceBar = -1;
lastAlertBar = -1;
}
SCFloatArrayRef O = sc.Open;
SCFloatArrayRef H = sc.High;
SCFloatArrayRef L = sc.Low;
SCFloatArrayRef Cl = sc.Close;
SCFloatArrayRef V = sc.Volume;
SCFloatArrayRef tr = Arr(sc, A_TR);
SCFloatArrayRef atr14 = Arr(sc, A_ATR14);
SCFloatArrayRef atr30 = Arr(sc, A_ATR30);
SCFloatArrayRef atr10 = Arr(sc, A_ATR10);
SCFloatArrayRef ema9 = Arr(sc, A_EMA9);
SCFloatArrayRef ema21 = Arr(sc, A_EMA21);
SCFloatArrayRef ema14 = Arr(sc, A_EMA14);
SCFloatArrayRef pdm = Arr(sc, A_PDM);
SCFloatArrayRef mdm = Arr(sc, A_MDM);
SCFloatArrayRef diPlus = Arr(sc, A_DI_PLUS);
SCFloatArrayRef diMinus = Arr(sc, A_DI_MINUS);
SCFloatArrayRef adxIn = Arr(sc, A_ADX_IN);
SCFloatArrayRef adx = Arr(sc, A_ADX);
SCFloatArrayRef cvdBuy = Arr(sc, A_CVD_BUY);
SCFloatArrayRef cvdSell = Arr(sc, A_CVD_SELL);
SCFloatArrayRef cvd = Arr(sc, A_CVD);
SCFloatArrayRef tdB = Arr(sc, A_TD_B);
SCFloatArrayRef tdS = Arr(sc, A_TD_S);
SCFloatArrayRef lux = Arr(sc, A_LUX);
SCFloatArrayRef frUp = Arr(sc, A_FR_UP);
SCFloatArrayRef frDn = Arr(sc, A_FR_DN);
SCFloatArrayRef upClose = Arr(sc, A_UP_CLOSE);
SCFloatArrayRef dnClose = Arr(sc, A_DN_CLOSE);
SCFloatArrayRef early = Arr(sc, A_EARLY);
SCFloatArrayRef rsiUp = Arr(sc, A_RSI_UP);
SCFloatArrayRef rsiDn = Arr(sc, A_RSI_DN);
SCFloatArrayRef rsi14 = Arr(sc, A_RSI14);
SCFloatArrayRef fvSPDI = Arr(sc, A_FV_SPDI);
SCFloatArrayRef fvSMDI = Arr(sc, A_FV_SMDI);
SCFloatArrayRef fvSTR = Arr(sc, A_FV_STR);
SCFloatArrayRef fvADX = Arr(sc, A_FV_ADX);
SCFloatArrayRef fvVar = Arr(sc, A_FV_VAR);
SCFloatArrayRef fanVMA = sc.Subgraph[SG_FANVMA].Data;
SCFloatArrayRef mg = sc.Subgraph[SG_MCGINLEY].Data;
SCFloatArrayRef emaFast = Arr(sc, A_EMA_FAST);
SCFloatArrayRef emaSlow = Arr(sc, A_EMA_SLOW);
SCFloatArrayRef macd = Arr(sc, A_MACD);
SCFloatArrayRef t1 = Arr(sc, A_T1);
SCFloatArrayRef e1 = Arr(sc, A_E1);
SCFloatArrayRef t1s = Arr(sc, A_T1S);
SCFloatArrayRef e1s = Arr(sc, A_E1S);
SCFloatArrayRef trampDn = Arr(sc, A_TRAMP_DN);
SCFloatArrayRef trampUp = Arr(sc, A_TRAMP_UP);
SCFloatArrayRef goUp = Arr(sc, A_GO_UP);
SCFloatArrayRef goDn = Arr(sc, A_GO_DN);
SCFloatArrayRef tramp = Arr(sc, A_TRAMP);
SCFloatArrayRef sqOn = Arr(sc, A_SQ_ON);
SCFloatArrayRef sqSrc = Arr(sc, A_SQ_SRC);
SCFloatArrayRef sqVal = Arr(sc, A_SQ_VAL);
SCFloatArrayRef sqCR = Arr(sc, A_SQ_CR);
SCFloatArrayRef sqCG = Arr(sc, A_SQ_CG);
SCFloatArrayRef sqPos = Arr(sc, A_SQ_POS);
SCFloatArrayRef sqNeg = Arr(sc, A_SQ_NEG);
SCFloatArrayRef sqz = Arr(sc, A_SQZ);
SCFloatArrayRef sqLen = Arr(sc, A_SQ_LEN);
SCFloatArrayRef pvCode = Arr(sc, A_PV_CODE);
SCFloatArrayRef shark = Arr(sc, A_SHARK);
SCFloatArrayRef deadRev = Arr(sc, A_DEADREV);
SCFloatArrayRef bands = Arr(sc, A_BANDS);
SCFloatArrayRef rsiuUp = Arr(sc, A_RSIU_UP);
SCFloatArrayRef rsiuDn = Arr(sc, A_RSIU_DN);
SCFloatArrayRef rsiU = Arr(sc, A_RSIU);
SCFloatArrayRef rsiuBasis = Arr(sc, A_RSIU_BASIS);
SCFloatArrayRef rsiuUpper = Arr(sc, A_RSIU_UPPER);
SCFloatArrayRef rsiuLower = Arr(sc, A_RSIU_LOWER);
SCFloatArrayRef rsiuMa = Arr(sc, A_RSIU_MA);
SCFloatArrayRef piUpper = Arr(sc, A_PI_UPPER);
SCFloatArrayRef piLower = Arr(sc, A_PI_LOWER);
SCFloatArrayRef atrbUpper = Arr(sc, A_ATRB_UPPER);
SCFloatArrayRef atrbLower = Arr(sc, A_ATRB_LOWER);
SCFloatArrayRef lastBuyWatch = Arr(sc, A_LAST_BUY_WATCH);
SCFloatArrayRef lastSellWatch = Arr(sc, A_LAST_SELL_WATCH);
SCFloatArrayRef plotBuy = Arr(sc, A_PLOT_BUY);
SCFloatArrayRef plotSell = Arr(sc, A_PLOT_SELL);
SCFloatArrayRef nzVol = Arr(sc, A_NZVOL);
SCFloatArrayRef volAvgL = Arr(sc, A_VOL_AVGL);
SCFloatArrayRef vola = Arr(sc, A_VOLA);
SCFloatArrayRef derC = Arr(sc, A_DER_C);
SCFloatArrayRef derCP = Arr(sc, A_DER_CP);
SCFloatArrayRef derCM = Arr(sc, A_DER_CM);
SCFloatArrayRef derSupN = Arr(sc, A_DER_SUPN);
SCFloatArrayRef derDemN = Arr(sc, A_DER_DEMN);
SCFloatArrayRef derBO = Arr(sc, A_DER_BO);
SCFloatArrayRef derBC = Arr(sc, A_DER_BC);
SCFloatArrayRef wma1 = Arr(sc, A_WMA1);
SCFloatArrayRef wma2 = Arr(sc, A_WMA2);
SCFloatArrayRef llw = Arr(sc, A_LLW);
SCFloatArrayRef upw = Arr(sc, A_UPW);
SCFloatArrayRef dnw = Arr(sc, A_DNW);
SCFloatArrayRef kernel = Arr(sc, A_KERNEL);
SCFloatArrayRef rsidUp = Arr(sc, A_RSID_UP);
SCFloatArrayRef rsidDn = Arr(sc, A_RSID_DN);
SCFloatArrayRef rsiD = Arr(sc, A_RSID);
SCFloatArrayRef plFound = Arr(sc, A_PL_FOUND);
SCFloatArrayRef plRsi = Arr(sc, A_PL_RSI);
SCFloatArrayRef plLow = Arr(sc, A_PL_LOW);
SCFloatArrayRef plBar = Arr(sc, A_PL_BAR);
SCFloatArrayRef phFound = Arr(sc, A_PH_FOUND);
SCFloatArrayRef phRsi = Arr(sc, A_PH_RSI);
SCFloatArrayRef phHigh = Arr(sc, A_PH_HIGH);
SCFloatArrayRef phBar = Arr(sc, A_PH_BAR);
SCFloatArrayRef divbX1 = Arr(sc, A_DIVB_X1);
SCFloatArrayRef divbY1 = Arr(sc, A_DIVB_Y1);
SCFloatArrayRef divsX1 = Arr(sc, A_DIVS_X1);
SCFloatArrayRef divsY1 = Arr(sc, A_DIVS_Y1);
SCFloatArrayRef tpCount = Arr(sc, A_TP_COUNT);
SCFloatArrayRef wave = Arr(sc, A_WAVE);
SCFloatArrayRef brightG = Arr(sc, A_BRIGHT_G);
SCFloatArrayRef brightR = Arr(sc, A_BRIGHT_R);
SCFloatArrayRef sigWave = Arr(sc, A_SIG_WAVE);
SCFloatArrayRef hemaB = Arr(sc, A_HEMA_B);
SCFloatArrayRef hema = sc.Subgraph[SG_HEMA].Arrays[0];
SCFloatArrayRef rsiHeat = Arr(sc, A_RSI_HEAT);
SCFloatArrayRef kSlope = Arr(sc, A_KSLOPE);
SCFloatArrayRef relVolS = Arr(sc, A_RELVOL_S);
SCFloatArrayRef adxS = Arr(sc, A_ADX_S);
SCFloatArrayRef haOpen = Arr(sc, A_HA_OPEN);
SCFloatArrayRef zScore = Arr(sc, A_ZSCORE);
SCFloatArrayRef stUpper = Arr(sc, A_ST_UPPER);
SCFloatArrayRef stLower = Arr(sc, A_ST_LOWER);
SCFloatArrayRef stDir = Arr(sc, A_ST_DIR);
SCFloatArrayRef stVal = Arr(sc, A_ST_VAL);
SCFloatArrayRef ccitp = Arr(sc, A_CCI_TP);
SCFloatArrayRef ycVal = Arr(sc, A_YC_VAL);
SCFloatArrayRef ycX = Arr(sc, A_YC_X);
SCFloatArrayRef orbDir = Arr(sc, A_ORB_DIR);
SCFloatArrayRef orbBar = Arr(sc, A_ORB_BAR);
SCFloatArrayRef orbPostHi = Arr(sc, A_ORB_POSTHI);
SCFloatArrayRef orbPostLo = Arr(sc, A_ORB_POSTLO);
SCFloatArrayRef orDoneSize = Arr(sc, A_OR_DONE_SIZE);
const int sBase[3] = { A_S0_HI, A_S1_HI, A_S2_HI };
for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++)
{
const bool conf = sc.GetBarHasClosedStatus(i) == BHCS_BAR_HAS_CLOSED;
const bool first = i == 0;
const int p = first ? 0 : i - 1;
const bool isGreen = Cl[i] > O[i];
const bool isRed = Cl[i] < O[i];
const bool bullBar = Cl[i] >= O[i];
const float chg = first ? 0.0f : Cl[i] - Cl[p];
tr[i] = first ? H[i] - L[i] : (std::max)(H[i] - L[i], (std::max)(std::fabs(H[i] - Cl[p]), std::fabs(L[i] - Cl[p])));
RmaStep(atr14, tr[i], i, 14);
RmaStep(atr30, tr[i], i, ATR30);
RmaStep(atr10, tr[i], i, 10);
EmaStep(ema9, Cl[i], i, 9);
EmaStep(ema21, Cl[i], i, 21);
EmaStep(ema14, Cl[i], i, 14);
{
float up = first ? 0.0f : H[i] - H[p];
float dn = first ? 0.0f : L[p] - L[i];
float plusDM = (up > dn && up > 0) ? up : 0.0f;
float minusDM = (dn > up && dn > 0) ? dn : 0.0f;
RmaStep(pdm, plusDM, i, 14);
RmaStep(mdm, minusDM, i, 14);
float trr = atr14[i];
float pl = trr > 0 ? 100.0f * pdm[i] / trr : (first ? 0.0f : diPlus[p]);
float mi = trr > 0 ? 100.0f * mdm[i] / trr : (first ? 0.0f : diMinus[p]);
diPlus[i] = pl;
diMinus[i] = mi;
float sum = pl + mi;
adxIn[i] = std::fabs(pl - mi) / (sum == 0 ? 1.0f : sum);
RmaStep(adx, adxIn[i], i, 14);
}
const float adxVal = 100.0f * adx[i];
const bool sigAbove = adxVal > 0.0f;
{
float upperWick = isGreen ? H[i] - Cl[i] : H[i] - O[i];
float lowerWick = isGreen ? O[i] - L[i] : Cl[i] - L[i];
float spread = H[i] - L[i];
float pu = spread > 0 ? upperWick / spread : 0.0f;
float pl = spread > 0 ? lowerWick / spread : 0.0f;
float pb = spread > 0 ? (spread - (upperWick + lowerWick)) / spread : 0.0f;
float ws = (pu + pl) / 2.0f;
float buyV = isGreen ? (pb + ws) * V[i] : ws * V[i];
float sellV = isRed ? (pb + ws) * V[i] : ws * V[i];
EmaStep(cvdBuy, buyV, i, 14);
EmaStep(cvdSell, sellV, i, 14);
cvd[i] = cvdBuy[i] - cvdSell[i];
}
{
float ll3 = Lowest(L, i, 3);
float hh3 = Highest(H, i, 3);
bool lowBreak = false, highBreak = false;
for (int k = 1; k <= 3 && i - k >= 0; k++)
{
if (ll3 < Lowest(L, i - k, 50))
lowBreak = true;
if (hh3 > Highest(H, i - k, 50))
highBreak = true;
}
bool buyDSR = !first && Cl[p] < O[p] && isGreen && Cl[i] > O[p] && lowBreak;
bool sellDSR = !first && Cl[p] > O[p] && isRed && Cl[i] < O[p] && highBreak;
deadRev[i] = (buyDSR || sellDSR) ? 1.0f : 0.0f;
}
{
float b1 = first ? 0.0f : tdB[p];
float s1 = first ? 0.0f : tdS[p];
float b, s;
if (i >= 4 && Cl[i] < Cl[i - 4])
{
b = b1 == 9 ? 1.0f : b1 + 1.0f;
s = 0.0f;
}
else
{
s = s1 == 9 ? 1.0f : s1 + 1.0f;
b = 0.0f;
}
tdB[i] = b;
tdS[i] = s;
lux[i] = ((b == 9 || (b1 == 8 && s == 1) || s == 9 || (s1 == 8 && b == 1)) && conf) ? 1.0f : 0.0f;
}
{
frUp[i] = first ? 0.0f : frUp[p];
frDn[i] = first ? 0.0f : frDn[p];
upClose[i] = first ? 0.0f : upClose[p];
dnClose[i] = first ? 0.0f : dnClose[p];
if (i >= 5)
{
auto sgn = [](float x) { return x > 0 ? 1 : (x < 0 ? -1 : 0); };
int dh = sgn(H[i] - H[i - 1]) + sgn(H[i - 1] - H[i - 2]);
int dh2 = sgn(H[i - 2] - H[i - 3]) + sgn(H[i - 3] - H[i - 4]);
int dl = sgn(L[i] - L[i - 1]) + sgn(L[i - 1] - L[i - 2]);
int dl2 = sgn(L[i - 2] - L[i - 3]) + sgn(L[i - 3] - L[i - 4]);
if (dh == -2 && dh2 == 2 && H[i - 2] == Highest(H, i, 5))
frUp[i] = H[i - 2];
if (dl == 2 && dl2 == -2 && L[i - 2] == Lowest(L, i, 5))
frDn[i] = L[i - 2];
}
if (!first && frUp[i] != 0 && CrossOver(Cl[i], Cl[p], frUp[i], frUp[p]))
upClose[i] = Cl[i];
if (!first && frDn[i] != 0 && CrossUnder(Cl[i], Cl[p], frDn[i], frDn[p]))
dnClose[i] = Cl[i];
}
RmaStep(rsiUp, (std::max)(chg, 0.0f), i, 14);
RmaStep(rsiDn, -(std::min)(chg, 0.0f), i, 14);
rsi14[i] = rsiDn[i] == 0 ? 100.0f : (rsiUp[i] == 0 ? 0.0f : 100.0f - 100.0f / (1.0f + rsiUp[i] / rsiDn[i]));
const float rsiM = rsi14[i];
{
const float W = 10.0f;
float bulls1 = first ? 0.0f : 0.5f * (std::fabs(H[i] - H[p]) + (H[i] - H[p]));
float bears1 = first ? 0.0f : 0.5f * (std::fabs(L[p] - L[i]) + (L[p] - L[i]));
float bears = bulls1 >= bears1 ? 0.0f : bears1;
float bulls = bulls1 <= bears1 ? 0.0f : bulls1;
float trf = first ? H[i] - L[i] : (std::max)(H[i] - L[i], H[i] - Cl[p]);
if (first)
{
fvSPDI[i] = 0;
fvSMDI[i] = 0;
fvSTR[i] = H[i] - L[i];
fvADX[i] = 0;
fvVar[i] = Cl[i];
}
else
{
fvSPDI[i] = (W * fvSPDI[p] + bulls) / (W + 1);
fvSMDI[i] = (W * fvSMDI[p] + bears) / (W + 1);
fvSTR[i] = (W * fvSTR[p] + trf) / (W + 1);
}
float pdi = fvSTR[i] > 0 ? fvSPDI[i] / fvSTR[i] : 0.0f;
float mdi = fvSTR[i] > 0 ? fvSMDI[i] / fvSTR[i] : 0.0f;