-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathTraderOracle.cpp
More file actions
2774 lines (2230 loc) · 89.6 KB
/
TraderOracle.cpp
File metadata and controls
2774 lines (2230 loc) · 89.6 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"
SCDLLName("Trader Oracle DLL")
#pragma region COMMON FUNCTIONS
double CandleLength(SCBaseDataRef InData, int index)
{
return InData[SC_HIGH][index] - InData[SC_LOW][index];
}
double BodyLength(SCBaseDataRef InData, int index)
{
return fabs(InData[SC_OPEN][index] - InData[SC_LAST][index]);
}
double PercentOfCandleLength(SCBaseDataRef InData, int index, double percent)
{
return CandleLength(InData, index) * (percent / 100.0);
}
double PercentOfBodyLength(SCBaseDataRef InData, int index, double percent)
{
return BodyLength(InData, index) * percent / 100.0;
}
double UpperWickLength(SCBaseDataRef InData, int index)
{
double upperBoundary = max(InData[SC_LAST][index], InData[SC_OPEN][index]);
double upperWickLength = InData[SC_HIGH][index] - upperBoundary;
return upperWickLength;
}
double LowerWickLength(SCBaseDataRef InData, int index)
{
double lowerBoundary = min(InData[SC_LAST][index], InData[SC_OPEN][index]);
double lowerWickLength = lowerBoundary - InData[SC_LOW][index];
return lowerWickLength;
}
bool IsGreen(SCBaseDataRef InData, int index)
{
return InData[SC_LAST][index] > InData[SC_OPEN][index];
}
bool IsRed(SCBaseDataRef InData, int index)
{
return InData[SC_LAST][index] < InData[SC_OPEN][index];
}
bool IsNearEqual(double value1, double value2, SCBaseDataRef InData, int index, double percent)
{
return abs(value1 - value2) < (3 * percent); //PercentOfCandleLength(InData, index, percent);
}
bool IsUpperWickSmall(SCBaseDataRef InData, int index, double percent)
{
return UpperWickLength(InData, index) < PercentOfCandleLength(InData, index, percent);
}
bool IsLowerWickSmall(SCBaseDataRef InData, int index, double percent)
{
return LowerWickLength(InData, index) < PercentOfCandleLength(InData, index, percent);
}
bool IsBullishEngulfing(SCStudyInterfaceRef sc, int index)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (InData[SC_LAST][index - 1] < InData[SC_OPEN][index - 1] && InData[SC_LAST][index] > InData[SC_OPEN][index])
{
if ((InData[SC_HIGH][index] > InData[SC_HIGH][index - 1]) &&
(InData[SC_LOW][index] < InData[SC_LOW][index - 1]) &&
(InData[SC_LAST][index] > InData[SC_OPEN][index - 1]) &&
(InData[SC_OPEN][index] < InData[SC_LAST][index - 1]))
ret_flag = true;
}
return ret_flag;
}
bool IsBearishEngulfing(SCStudyInterfaceRef sc, int index)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (InData[SC_LAST][index - 1] > InData[SC_OPEN][index - 1] && InData[SC_LAST][index] < InData[SC_OPEN][index])
{
if ((InData[SC_HIGH][index] > InData[SC_HIGH][index - 1]) &&
(InData[SC_LOW][index] < InData[SC_LOW][index - 1]) &&
(InData[SC_OPEN][index] > InData[SC_LAST][index - 1]) &&
(InData[SC_LAST][index] < InData[SC_OPEN][index - 1]))
ret_flag = true;
}
return ret_flag;
}
bool IsThreeOutsideUp(SCStudyInterfaceRef sc, int index)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (IsGreen(InData, index) && (InData[SC_LAST][index] > InData[SC_LAST][index - 1]))
{
if (IsBullishEngulfing(sc, index - 1))
ret_flag = true;
}
return ret_flag;
}
bool IsThreeOutsideDown(SCStudyInterfaceRef sc, int index)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (IsRed(InData, index) && (InData[SC_LAST][index] < InData[SC_LAST][index - 1]))
{
if (IsBearishEngulfing(sc, index - 1))
ret_flag = true;
}
return ret_flag;
}
const int k_Body_NUM_OF_CANDLES = 5; // number of previous candles to calculate body strength
inline bool IsBodyStrong(SCBaseDataRef InData, int index)
{
bool ret_flag = false;
float mov_aver = 0;
for (int i = 1; i < k_Body_NUM_OF_CANDLES + 1; i++)
mov_aver += static_cast<float>(BodyLength(InData, index - i));
mov_aver /= k_Body_NUM_OF_CANDLES;
if (BodyLength(InData, index) > mov_aver)
ret_flag = true;
return ret_flag;
}
bool IsTweezerTop(SCStudyInterfaceRef sc, int index, float UpperBand)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (IsNearEqual(InData[SC_OPEN][index - 1], InData[SC_LAST][index - 2], InData, index, sc.TickSize)
&& InData[SC_LOW][index] < InData[SC_LOW][index - 1] // current bar lower than previous
&& IsRed(InData, index)
&& IsRed(InData, index - 1)
&& IsGreen(InData, index - 2)
&& IsGreen(InData, index - 3)
&& (InData[SC_HIGH][index - 1] > UpperBand || InData[SC_HIGH][index - 2] > UpperBand)
)
ret_flag = true;
return ret_flag;
}
bool IsTweezerBottom(SCStudyInterfaceRef sc, int index, float LowerBand)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (IsNearEqual(InData[SC_OPEN][index - 1], InData[SC_LAST][index - 2], InData, index, sc.TickSize)
&& InData[SC_HIGH][index] > InData[SC_HIGH][index - 1]
&& IsGreen(InData, index)
&& IsGreen(InData, index - 1)
&& IsRed(InData, index - 2)
&& IsRed(InData, index - 3)
&& (InData[SC_LOW][index - 1] < LowerBand || InData[SC_LOW][index - 2] < LowerBand)
)
ret_flag = true;
return ret_flag;
}
bool IsTrampoline(SCStudyInterfaceRef sc, int index, float rsi, float prsi, float pprsi, float BBBand, int iTickSize)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (IsRed(InData, index)
&& IsRed(InData, index - 1)
&& IsGreen(InData, index - 2)
&& InData[SC_LAST][index] < InData[SC_LAST][index - 1]
&& (rsi > 80 || prsi > 80 || pprsi > 80)
&& InData[SC_HIGH][index - 2] >= (BBBand - (1 * iTickSize))
)
ret_flag = true;
if (IsGreen(InData, index)
&& IsGreen(InData, index - 1)
&& IsRed(InData, index - 2)
&& InData[SC_LAST][index] > InData[SC_LAST][index - 1]
&& (rsi < 20 || prsi < 20 || pprsi < 20)
&& InData[SC_LOW][index - 2] <= (BBBand + (1 * iTickSize))
)
ret_flag = true;
return ret_flag;
}
bool IsStairs(SCStudyInterfaceRef sc, int index)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
return ret_flag;
}
bool IsVolImbGreen(SCStudyInterfaceRef sc, int index)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (IsGreen(InData, index)
&& IsGreen(InData, index - 1)
&& InData[SC_OPEN][index] > InData[SC_LAST][index - 1]
)
ret_flag = true;
return ret_flag;
}
bool IsVolImbRed(SCStudyInterfaceRef sc, int index)
{
SCBaseDataRef InData = sc.BaseData;
bool ret_flag = false;
if (IsRed(InData, index)
&& IsRed(InData, index - 1)
&& InData[SC_OPEN][index] < InData[SC_LAST][index - 1]
)
ret_flag = true;
return ret_flag;
}
bool IsDoji(SCBaseDataRef InData, int index)
{
bool ret_flag = false;
if (IsRed(InData, index))
{
if (abs(InData[SC_HIGH][index] - InData[SC_OPEN][index]) > abs(InData[SC_OPEN][index] - InData[SC_LAST][index]) &&
abs(InData[SC_LAST][index] - InData[SC_LOW][index]) > abs(InData[SC_OPEN][index] - InData[SC_LAST][index]))
ret_flag = true;
}
else if (IsGreen(InData, index))
{
if (abs(InData[SC_HIGH][index] - InData[SC_LAST][index]) > abs(InData[SC_OPEN][index] - InData[SC_LAST][index]) &&
abs(InData[SC_OPEN][index] - InData[SC_LOW][index]) > abs(InData[SC_OPEN][index] - InData[SC_LAST][index]))
ret_flag = true;
}
return ret_flag;
}
void DrawText(SCStudyInterfaceRef sc, SCSubgraphRef screffy, SCString txt, int iAboveCandle, int iBuffer)
{
s_UseTool Tool;
int i = sc.Index;
if (txt == "Eq Lo" || txt == "Eq Hi" || txt == "TR")
i = sc.Index - 1;
Tool.ChartNumber = sc.ChartNumber;
Tool.DrawingType = DRAWING_TEXT;
Tool.BeginIndex = sc.CurrentIndex;
Tool.Region = sc.GraphRegion;
if (iAboveCandle == 0) // automatic detection
{
if (sc.Close[i] > sc.Open[i]) // green candle
iAboveCandle = 1;
else
iAboveCandle = -1;
}
if (iAboveCandle == 1)
{
Tool.BeginValue = sc.High[i] + ((sc.High[i] - sc.Low[i]) * iBuffer * 0.01f);
Tool.TextAlignment = DT_CENTER | DT_BOTTOM;
}
else if(iAboveCandle == -1)
{
Tool.BeginValue = sc.Low[i] - ((sc.High[i] - sc.Low[i]) * iBuffer * 0.01f);
Tool.TextAlignment = DT_CENTER | DT_TOP;
}
Tool.Color = screffy.PrimaryColor;
Tool.FontBackColor = screffy.SecondaryColor;
Tool.FontSize = screffy.LineWidth;
Tool.FontBold = TRUE;
Tool.Text.Format("%s", txt.GetChars());
Tool.AddMethod = UTAM_ADD_ALWAYS;
sc.UseTool(Tool);
}
#pragma endregion
#pragma region DELTA INTENSITY
SCSFExport scsf_Delta_Intensity(SCStudyInterfaceRef sc)
{
int i = sc.Index;
SCInputRef Input_Threshold = sc.Input[0];
SCInputRef Input_InputDataLow = sc.Input[1];
SCSubgraphRef Subgraph_GreenBar = sc.Subgraph[0];
SCSubgraphRef Subgraph_IntenseGreenBar = sc.Subgraph[1];
SCSubgraphRef Subgraph_RedBar = sc.Subgraph[2];
SCSubgraphRef Subgraph_IntenseRedBar = sc.Subgraph[3];
SCSubgraphRef Subgraph_Winner = sc.Subgraph[4];
if (sc.SetDefaults)
{
sc.GraphName = "Delta Intensity";
sc.GraphRegion = 1;
sc.AutoLoop = 1;
Input_Threshold.Name = "Bright Color Threshold";
Input_Threshold.SetInt(450);
Subgraph_GreenBar.Name = "Green Bar";
Subgraph_GreenBar.PrimaryColor = RGB(0, 140, 0);
Subgraph_GreenBar.DrawStyle = DRAWSTYLE_BAR_BOTTOM;
Subgraph_GreenBar.LineWidth = 17;
Subgraph_RedBar.Name = "Red Bar";
Subgraph_RedBar.PrimaryColor = RGB(140, 0, 0);
Subgraph_RedBar.DrawStyle = DRAWSTYLE_BAR_BOTTOM;
Subgraph_RedBar.LineWidth = 17;
Subgraph_IntenseGreenBar.Name = "Intense Green Bar";
Subgraph_IntenseGreenBar.PrimaryColor = RGB(0, 255, 0);
Subgraph_IntenseGreenBar.DrawStyle = DRAWSTYLE_BAR_BOTTOM;
Subgraph_IntenseGreenBar.LineWidth = 17;
Subgraph_IntenseRedBar.Name = "Intense Red Bar";
Subgraph_IntenseRedBar.PrimaryColor = RGB(255, 0, 0);
Subgraph_IntenseRedBar.DrawStyle = DRAWSTYLE_BAR_BOTTOM;
Subgraph_IntenseRedBar.LineWidth = 17;
Subgraph_Winner.Name = "Green or Red Dominant";
Subgraph_Winner.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
Subgraph_Winner.PrimaryColor = RGB(255, 255, 255);
Subgraph_Winner.SecondaryColorUsed = true;
Subgraph_Winner.SecondaryColor = RGB(0, 167, 0);
Subgraph_Winner.LineWidth = 10;
Subgraph_Winner.DrawZeros = false;
return;
}
double green = sc.BidVolume[i];
double red = sc.AskVolume[i];
float volsec = 1;
float minDelta = sc.BaseData[SC_ASKBID_DIFF_LOW][sc.Index];
float maxDelta = sc.BaseData[SC_ASKBID_DIFF_HIGH][sc.Index];
//SCDateTime BarEndDateTime = sc.GetEndingDateTimeForBarIndex(sc.Index);
//float bartime = static_cast<float>((BarEndDateTime - sc.BaseDateTimeIn[sc.Index] + SCDateTime::MICROSECONDS(1)).GetAsDouble());
//if (bartime > 0)
// volsec = (sc.Volume[i] / bartime);
float delta = sc.AskVolume[i] - sc.BidVolume[i];
float deltaPer = delta > 0 ? (delta / maxDelta) : (delta / minDelta);
float deltaIntense = abs((delta * deltaPer) * volsec);
if (deltaIntense > Input_Threshold.GetInt())
{
if (delta > 0)
{
Subgraph_IntenseGreenBar[i] = deltaIntense;
Subgraph_GreenBar[i] = 0;
}
else
{
Subgraph_IntenseRedBar[i] = deltaIntense;
Subgraph_RedBar[i] = 0;
}
}
else
{
if (delta > 0)
{
Subgraph_IntenseGreenBar[i] = 0;
Subgraph_GreenBar[i] = deltaIntense;
}
else
{
Subgraph_IntenseRedBar[i] = 0;
Subgraph_RedBar[i] = deltaIntense;
}
}
SCString t = "";
if (IsRed(sc.BaseData, i) && delta < 0)
{
Subgraph_Winner.SecondaryColor = RGB(0, 0, 0);
Subgraph_Winner.PrimaryColor = RGB(0, 0, 0);
sc.AddAndManageSingleTextUserDrawnDrawingForStudy(sc, true, 90, 90, Subgraph_Winner, false, t, true, 1);
}
if (IsGreen(sc.BaseData, i) && delta > 0)
{
Subgraph_Winner.SecondaryColor = RGB(0, 0, 0);
Subgraph_Winner.PrimaryColor = RGB(0, 0, 0);
sc.AddAndManageSingleTextUserDrawnDrawingForStudy(sc, true, 90, 90, Subgraph_Winner, false, t, true, 1);
}
if (IsRed(sc.BaseData, i) && delta > 0)
{
t = "Delta Divergence";
Subgraph_Winner.SecondaryColor = RGB(167, 0, 0);
Subgraph_Winner.PrimaryColor = RGB(255, 255, 255);
sc.AddAndManageSingleTextUserDrawnDrawingForStudy(sc, true, 90, 90, Subgraph_Winner, false, t, true, 1);
}
if (IsGreen(sc.BaseData, i) && delta < 0)
{
t = "Delta Divergence";
Subgraph_Winner.SecondaryColor = RGB(0, 167, 0);
Subgraph_Winner.PrimaryColor = RGB(255, 255, 255);
sc.AddAndManageSingleTextUserDrawnDrawingForStudy(sc, true, 90, 90, Subgraph_Winner, false, t, true, 1);
}
}
#pragma endregion
#pragma region OLYMPUS
SCSFExport scsf_Olympus(SCStudyInterfaceRef sc)
{
#pragma region INPUTS
SCString txt;
SCInputRef Input_WaddahIntensity = sc.Input[0];
SCInputRef Input_UseWaddah = sc.Input[1];
SCInputRef Input_UseMacd = sc.Input[2];
SCInputRef Input_UseSar = sc.Input[3];
SCInputRef Input_UseSuperTrend = sc.Input[4];
SCInputRef Input_UseAO = sc.Input[5];
SCInputRef Input_UseHMA = sc.Input[6];
SCInputRef Input_UseT3 = sc.Input[7];
SCInputRef Input_UseFisher = sc.Input[8];
SCInputRef Input_ADX = sc.Input[9];
SCInputRef Input_IgnoreDoji = sc.Input[10];
SCInputRef Input_BarColor = sc.Input[11];
SCInputRef Input_BarColorWaddah = sc.Input[12];
SCInputRef Input_BarColorLinda = sc.Input[13];
SCInputRef Input_UpOffset = sc.Input[14];
SCInputRef Input_DownOffset = sc.Input[15];
SCInputRef Input_ShavedBuffer = sc.Input[16];
SCInputRef Input_DojiCity = sc.Input[17];
SCSubgraphRef Subgraph_DotUp = sc.Subgraph[0];
SCSubgraphRef Subgraph_DotDown = sc.Subgraph[1];
SCSubgraphRef Subgraph_VolImbUp = sc.Subgraph[2];
SCSubgraphRef Subgraph_VolImbDown = sc.Subgraph[3];
SCSubgraphRef Subgraph_SqueezeUp = sc.Subgraph[4];
SCSubgraphRef Subgraph_SqueezeDown = sc.Subgraph[5];
SCSubgraphRef Subgraph_3oU = sc.Subgraph[6];
SCSubgraphRef Subgraph_3oD = sc.Subgraph[7];
SCSubgraphRef Subgraph_EqualH = sc.Subgraph[8];
SCSubgraphRef Subgraph_EqualL = sc.Subgraph[9];
SCSubgraphRef Subgraph_Tramp = sc.Subgraph[10];
SCSubgraphRef Subgraph_KAMA = sc.Subgraph[11];
SCSubgraphRef Subgraph_WaddahPos = sc.Subgraph[12];
SCSubgraphRef Subgraph_WaddahNeg = sc.Subgraph[13];
SCSubgraphRef Subgraph_Slow = sc.Subgraph[14];
SCSubgraphRef Subgraph_Fast = sc.Subgraph[15];
SCSubgraphRef Subgraph_BB = sc.Subgraph[16];
SCSubgraphRef Subgraph_ColorBar = sc.Subgraph[17];
SCSubgraphRef Subgraph_ColorUp = sc.Subgraph[18];
SCSubgraphRef Subgraph_ColorDown = sc.Subgraph[19];
SCSubgraphRef Subgraph_LindaMACD = sc.Subgraph[20];
SCSubgraphRef Subgraph_Parabolic = sc.Subgraph[21];
SCSubgraphRef Subgraph_AO = sc.Subgraph[22];
SCSubgraphRef Subgraph_Fisher = sc.Subgraph[23];
SCSubgraphRef Subgraph_ADX = sc.Subgraph[24];
SCSubgraphRef Subgraph_T3 = sc.Subgraph[25];
SCSubgraphRef Subgraph_HMA = sc.Subgraph[26];
SCSubgraphRef Subgraph_Calc = sc.Subgraph[27];
SCSubgraphRef Subgraph_MomentumHist = sc.Subgraph[28];
SCSubgraphRef Subgraph_MomentumHistUpColors = sc.Subgraph[29];
SCSubgraphRef Subgraph_MomentumHistDownColors = sc.Subgraph[30];
SCSubgraphRef Subgraph_SuperTrend = sc.Subgraph[31];
SCSubgraphRef Subgraph_Intersection = sc.Subgraph[32];
SCSubgraphRef Subgraph_BBGreen = sc.Subgraph[33];
SCSubgraphRef Subgraph_BBRed = sc.Subgraph[34];
SCSubgraphRef Subgraph_ShavedGreen = sc.Subgraph[35];
SCSubgraphRef Subgraph_ShavedRed = sc.Subgraph[36];
SCSubgraphRef Subgraph_DojiCity = sc.Subgraph[37];
SCSubgraphRef Subgraph_HullATR = sc.Subgraph[38];
SCFloatArrayRef Array_TrueRange = Subgraph_SuperTrend.Arrays[0];
SCFloatArrayRef Array_AvgTrueRange = Subgraph_SuperTrend.Arrays[1];
SCFloatArrayRef Array_UpperBandBasic = Subgraph_SuperTrend.Arrays[2];
SCFloatArrayRef Array_LowerBandBasic = Subgraph_SuperTrend.Arrays[3];
SCFloatArrayRef Array_UpperBand = Subgraph_SuperTrend.Arrays[4];
SCFloatArrayRef Array_LowerBand = Subgraph_SuperTrend.Arrays[5];
COLORREF UpColor = Subgraph_ColorUp.PrimaryColor;
COLORREF DownColor = Subgraph_ColorDown.PrimaryColor;
#pragma endregion
#pragma region DEFAULTS
if (sc.SetDefaults)
{
sc.GraphName = "Olympus";
sc.GraphRegion = 0;
sc.AutoLoop = 1;
Input_WaddahIntensity.Name = "Waddah Intensity";
Input_WaddahIntensity.SetInt(150);
Input_UseWaddah.Name = "Use Waddah";
Input_UseWaddah.SetYesNo(1);
Input_UseMacd.Name = "Use MACD";
Input_UseMacd.SetYesNo(1);
Input_UseSar.Name = "Use Parabolic Sar";
Input_UseSar.SetYesNo(1);
Input_UseSuperTrend.Name = "Use Supertrend";
Input_UseSuperTrend.SetYesNo(0);
Input_UseAO.Name = "Use Awesome Oscillator";
Input_UseAO.SetYesNo(0);
Input_UseFisher.Name = "Use Fisher Transform";
Input_UseFisher.SetYesNo(1);
Input_UseHMA.Name = "Use Hull Moving Average";
Input_UseHMA.SetYesNo(1);
Input_UseT3.Name = "Use T3";
Input_UseT3.SetYesNo(0);
Input_ADX.Name = "Minimum ADX";
Input_ADX.SetInt(11);
Input_UpOffset.Name = "Up Offset In Ticks";
Input_UpOffset.SetInt(2);
Input_DownOffset.Name = "Down Offset In Ticks";
Input_DownOffset.SetInt(2);
Input_ShavedBuffer.Name = "Shaved candle buffer";
Input_ShavedBuffer.SetInt(1);
Input_BarColor.Name = "Bar coloring";
Input_BarColor.SetCustomInputStrings("None;Waddah;Linda MACD;Supertrend");
Input_BarColor.SetCustomInputIndex(0);
Input_BarColorWaddah.Name = "Bar color Waddah offset";
Input_BarColorWaddah.SetInt(80);
Input_BarColorLinda.Name = "Bar color LindaMACD offset";
Input_BarColorLinda.SetInt(40);
Input_IgnoreDoji.Name = "Ignore Dojis";
Input_IgnoreDoji.SetYesNo(1);
Input_IgnoreDoji.SetDescription("Ignore when wicks are larger than candle body");
Input_DojiCity.Name = "Show Doji Cities";
Input_DojiCity.SetYesNo(1);
// =======================================================================
Subgraph_ColorBar.Name = "Bar Color";
Subgraph_ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR;
Subgraph_ColorBar.LineWidth = 1;
Subgraph_ColorUp.Name = "Bar Color Up";
Subgraph_ColorUp.PrimaryColor = RGB(0, 255, 0);
Subgraph_ColorUp.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_ColorUp.LineWidth = 1;
Subgraph_ColorUp.DrawZeros = false;
Subgraph_ColorDown.Name = "Bar Color Down";
Subgraph_ColorDown.PrimaryColor = RGB(255, 0, 0);
Subgraph_ColorDown.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_ColorDown.LineWidth = 1;
Subgraph_ColorDown.DrawZeros = false;
Subgraph_DotUp.Name = "Standard Buy Dot";
Subgraph_DotUp.PrimaryColor = RGB(0, 255, 0);
Subgraph_DotUp.DrawStyle = DRAWSTYLE_TRIANGLE_UP;
Subgraph_DotUp.LineWidth = 2;
Subgraph_DotUp.DrawZeros = false;
Subgraph_DotDown.Name = "Standard Sell Dot";
Subgraph_DotDown.PrimaryColor = RGB(255, 0, 0);
Subgraph_DotDown.DrawStyle = DRAWSTYLE_TRIANGLE_DOWN;
Subgraph_DotDown.LineWidth = 2;
Subgraph_DotDown.DrawZeros = false;
Subgraph_SqueezeUp.Name = "Squeeze Buy Dot";
Subgraph_SqueezeUp.PrimaryColor = RGB(255, 255, 0);
Subgraph_SqueezeUp.DrawStyle = DRAWSTYLE_STAR;
Subgraph_SqueezeUp.LineWidth = 1;
Subgraph_SqueezeUp.DrawZeros = false;
Subgraph_SqueezeDown.Name = "Squeeze Sell Dot";
Subgraph_SqueezeDown.PrimaryColor = RGB(255, 255, 0);
Subgraph_SqueezeDown.DrawStyle = DRAWSTYLE_STAR;
Subgraph_SqueezeDown.LineWidth = 1;
Subgraph_SqueezeDown.DrawZeros = false;
Subgraph_VolImbUp.Name = "Volume Imbalance Up";
Subgraph_VolImbUp.PrimaryColor = RGB(255, 255, 255);
Subgraph_VolImbUp.DrawStyle = DRAWSTYLE_ARROW_UP;
Subgraph_VolImbUp.LineWidth = 1;
Subgraph_VolImbUp.DrawZeros = false;
Subgraph_VolImbDown.Name = "Volume Imbalance Down";
Subgraph_VolImbDown.PrimaryColor = RGB(255, 255, 255);
Subgraph_VolImbDown.DrawStyle = DRAWSTYLE_ARROW_DOWN;
Subgraph_VolImbDown.LineWidth = 1;
Subgraph_VolImbDown.DrawZeros = false;
Subgraph_KAMA.Name = "KAMA";
Subgraph_KAMA.DrawStyle = DRAWSTYLE_LINE;
Subgraph_KAMA.LineWidth = 2;
Subgraph_KAMA.PrimaryColor = RGB(191, 140, 29);
Subgraph_DojiCity.Name = "Doji City";
Subgraph_DojiCity.DrawStyle = DRAWSTYLE_BACKGROUND;
Subgraph_DojiCity.PrimaryColor = RGB(27, 25, 94);
Subgraph_DojiCity.LineWidth = 1;
Subgraph_3oU.Name = "Three Outside Up";
Subgraph_3oU.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
Subgraph_3oU.PrimaryColor = RGB(255, 255, 29);
Subgraph_3oU.SecondaryColor = RGB(1, 97, 3);
Subgraph_3oU.LineWidth = 8;
Subgraph_3oD.Name = "Three Outside Down";
Subgraph_3oD.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
Subgraph_3oD.PrimaryColor = RGB(255, 255, 29);
Subgraph_3oD.SecondaryColor = RGB(97, 1, 1);
Subgraph_3oD.LineWidth = 8;
Subgraph_EqualH.Name = "Equal High";
Subgraph_EqualH.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
Subgraph_EqualH.PrimaryColor = RGB(255, 255, 29);
Subgraph_EqualH.SecondaryColor = RGB(97, 1, 1);
Subgraph_EqualH.LineWidth = 8;
Subgraph_EqualL.Name = "Equal Low";
Subgraph_EqualL.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
Subgraph_EqualL.PrimaryColor = RGB(255, 255, 29);
Subgraph_EqualL.SecondaryColor = RGB(1, 97, 3);
Subgraph_EqualL.LineWidth = 8;
Subgraph_Tramp.Name = "Trampoline";
Subgraph_Tramp.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
Subgraph_Tramp.PrimaryColor = RGB(0, 0, 0);
Subgraph_Tramp.SecondaryColor = RGB(169, 205, 252);
Subgraph_Tramp.LineWidth = 8;
Subgraph_BBGreen.Name = "Engulfing Green BB";
Subgraph_BBGreen.PrimaryColor = RGB(0, 64, 0);
Subgraph_BBGreen.DrawStyle = DRAWSTYLE_BACKGROUND;
Subgraph_BBGreen.LineWidth = 1;
Subgraph_BBGreen.DrawZeros = false;
Subgraph_BBRed.Name = "Engulfing Red BB";
Subgraph_BBRed.PrimaryColor = RGB(70, 0, 35);
Subgraph_BBRed.DrawStyle = DRAWSTYLE_BACKGROUND;
Subgraph_BBRed.LineWidth = 1;
Subgraph_BBRed.DrawZeros = false;
Subgraph_ShavedGreen.Name = "Shaved Green Candle";
Subgraph_ShavedGreen.PrimaryColor = RGB(170, 221, 255);
Subgraph_ShavedGreen.DrawStyle = DRAWSTYLE_COLOR_BAR;
Subgraph_ShavedGreen.LineWidth = 1;
Subgraph_ShavedGreen.DrawZeros = false;
Subgraph_ShavedRed.Name = "Shaved Red Candle";
Subgraph_ShavedRed.PrimaryColor = RGB(255, 128, 192);
Subgraph_ShavedRed.DrawStyle = DRAWSTYLE_COLOR_BAR;
Subgraph_ShavedRed.LineWidth = 1;
Subgraph_ShavedRed.DrawZeros = false;
Subgraph_LindaMACD.Name = "Linda MACD";
Subgraph_LindaMACD.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_Parabolic.Name = "Parabolic";
Subgraph_Parabolic.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_HMA.Name = "Hull Moving Average";
Subgraph_HMA.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_Calc.Name = "RSI";
Subgraph_Calc.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_MomentumHist.Name = "Squeeze Relaxer 1";
Subgraph_MomentumHist.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_MomentumHistUpColors.Name = "Squeeze Relaxer 2";
Subgraph_MomentumHistUpColors.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_MomentumHistDownColors.Name = "Squeeze Relaxer 3";
Subgraph_MomentumHistDownColors.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_BB.Name = "Bollinger Bands";
Subgraph_BB.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_AO.Name = "Awesome Oscillator";
Subgraph_AO.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_Fisher.Name = "Awesome Oscillator";
Subgraph_Fisher.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_ADX.Name = "ADX";
Subgraph_ADX.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_T3.Name = "T3";
Subgraph_T3.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_Slow.Name = "SMA Slow";
Subgraph_Slow.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_Fast.Name = "SMA Fast";
Subgraph_Fast.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_WaddahPos.Name = "Waddah Positive";
Subgraph_WaddahPos.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_WaddahNeg.Name = "Waddah Negative";
Subgraph_WaddahNeg.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_SuperTrend.Name = "SuperTrend";
Subgraph_SuperTrend.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_Intersection.Name = "Vol Imb Intersections";
Subgraph_Intersection.DrawStyle = DRAWSTYLE_IGNORE;
return;
}
#pragma endregion
int i = sc.Index;
int& r_SqueezeUp = sc.GetPersistentInt(0);
int cl = sc.GetBarHasClosedStatus(i); // BHCS_BAR_HAS_NOT_CLOSED
SCBaseDataRef in = sc.BaseData;
double close = sc.Close[i];
double open = sc.Open[i];
double high = sc.High[i];
double low = sc.Low[i];
double pclose = sc.Close[i - 1];
double popen = sc.Open[i - 1];
double phigh = sc.High[i - 1];
double plow = sc.Low[i - 1];
double body = abs(open - close);
double pbody = abs(popen - pclose);
bool red = open > close;
bool green = open < close;
bool pdoji = false;
double upperwick = 0;
double lowerwick = 0;
if (green)
{
upperwick = abs(high - close);
lowerwick = abs(open - low);
pdoji = abs(phigh - pclose) > pbody && abs(popen - plow) > body;
}
else // red
{
upperwick = abs(high - open);
lowerwick = abs(close - low);
pdoji = abs(phigh - popen) > pbody && abs(pclose - plow) > body;
}
bool doji = upperwick > body && lowerwick > body;
SCFloatArrayRef Price = sc.BaseData[SC_HL_AVG];
SCFloatArrayRef Array_Value = Subgraph_Calc.Arrays[0];
//int X = sc.BarIndexToXPixelCoordinate(i);
//int Y = sc.BarIndexToRelativeHorizontalCoordinate(i, false);
#pragma region INDICATORS
// for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++)
{
bool BarCloseStatus = false;
bool sqRelaxUp;
bool bSuperUp;
if (i < sc.ArraySize - 1)
BarCloseStatus = true;
// SUPER TREND
int ATRMultiplier = 2;
int ATRPeriod = 11;
sc.TrueRange(sc.BaseDataIn, Array_TrueRange);
sc.HullMovingAverage(Array_TrueRange, Subgraph_HullATR, ATRPeriod);
Array_AvgTrueRange[sc.Index] = Subgraph_HullATR[sc.Index];
Array_UpperBandBasic[sc.Index] = sc.BaseDataIn[SC_HL][sc.Index] + ATRMultiplier * Array_AvgTrueRange[sc.Index];
Array_LowerBandBasic[sc.Index] = sc.BaseDataIn[SC_HL][sc.Index] - ATRMultiplier * Array_AvgTrueRange[sc.Index];
// Calculate Upper and Lower Bands
if (Array_UpperBandBasic[sc.Index] < Array_UpperBand[sc.Index - 1] || sc.Close[sc.Index - 1] > Array_UpperBand[sc.Index - 1])
Array_UpperBand[sc.Index] = Array_UpperBandBasic[sc.Index];
else
Array_UpperBand[sc.Index] = Array_UpperBand[sc.Index - 1];
if (Array_LowerBandBasic[sc.Index] > Array_LowerBand[sc.Index - 1] || sc.Close[sc.Index - 1] < Array_LowerBand[sc.Index - 1])
Array_LowerBand[sc.Index] = Array_LowerBandBasic[sc.Index - 1];
else
Array_LowerBand[sc.Index] = Array_LowerBand[sc.Index - 1];
if (sc.Index == 0)
Subgraph_SuperTrend[sc.Index] = Array_UpperBand[sc.Index];
if (Subgraph_SuperTrend[sc.Index - 1] == Array_UpperBand[sc.Index - 1] && sc.Close[sc.Index] < Array_UpperBand[sc.Index])
Subgraph_SuperTrend[sc.Index] = Array_UpperBand[sc.Index];
else if (Subgraph_SuperTrend[sc.Index - 1] == Array_UpperBand[sc.Index - 1] && sc.Close[sc.Index] > Array_UpperBand[sc.Index])
Subgraph_SuperTrend[sc.Index] = Array_LowerBand[sc.Index];
else if (Subgraph_SuperTrend[sc.Index - 1] == Array_LowerBand[sc.Index - 1] && sc.Close[sc.Index] > Array_LowerBand[sc.Index])
Subgraph_SuperTrend[sc.Index] = Array_LowerBand[sc.Index];
else if (Subgraph_SuperTrend[sc.Index - 1] == Array_LowerBand[sc.Index - 1] && sc.Close[sc.Index] < Array_LowerBand[sc.Index])
Subgraph_SuperTrend[sc.Index] = Array_UpperBand[sc.Index];
else
Subgraph_SuperTrend[sc.Index] = Subgraph_SuperTrend[sc.Index - 1];
if (Subgraph_SuperTrend[sc.Index] == Array_UpperBand[sc.Index])
bSuperUp = false;
else
bSuperUp = true;
// SQUEEZE RELAXER
sc.DataStartIndex = 20;
sc.ExponentialMovAvg(sc.Close, Subgraph_MomentumHistUpColors, 20); // Note: EMA returns close when index is < HistogramLenSecondData.GetInt()
sc.MovingAverage(sc.Close, Subgraph_MomentumHistUpColors, MOVAVGTYPE_EXPONENTIAL, 20);
float hlh = sc.GetHighest(sc.High, 20);
float lll = sc.GetLowest(sc.Low, 20);
Subgraph_MomentumHistDownColors[sc.Index] = sc.Open[sc.Index] - ((hlh + lll) / 2.0f + Subgraph_MomentumHistUpColors[sc.Index]) / 2.0f;
sc.LinearRegressionIndicator(Subgraph_MomentumHistDownColors, Subgraph_MomentumHist, 20);
sc.MovingAverage(sc.Close, Subgraph_MomentumHistUpColors, MOVAVGTYPE_LINEARREGRESSION, 20);
if ((Subgraph_MomentumHist[i] <= 0) && (Subgraph_MomentumHist[i] > Subgraph_MomentumHist[i - 1]))
{
if (r_SqueezeUp == 0) {
Subgraph_SqueezeUp[i] = sc.Low[i] - ((Input_UpOffset.GetInt()) * sc.TickSize);
Subgraph_SqueezeDown[i] = 0;
r_SqueezeUp = 1;
}
}
else if ((Subgraph_MomentumHist[i] >= 0) && (Subgraph_MomentumHist[i] < Subgraph_MomentumHist[i - 1]))
{
if (r_SqueezeUp == 1) {
Subgraph_SqueezeDown[i] = sc.High[i] + ((Input_DownOffset.GetInt()) * sc.TickSize);
Subgraph_SqueezeUp[i] = 0;
r_SqueezeUp = 0;
}
}
// FISHER TRANSFORM
float Highest = sc.GetHighest(Price, 10);
float Lowest = sc.GetLowest(Price, 10);
float Range = Highest - Lowest;
if (Range == 0)
Array_Value[i] = 0;
else
Array_Value[i] = .66f * ((Price[i] - Lowest) / Range - 0.5f) + 0.67f * Array_Value[i - 1];
float TruncValue = Array_Value[i];
if (TruncValue > .99f)
TruncValue = .999f;
else if (TruncValue < -.99f)
TruncValue = -.999f;
float fish = .5f * (log((1 + TruncValue) / (1 - TruncValue)) + Subgraph_Fisher[i - 1]);
//int data_type_indx = (int)Input_InputData.GetInputDataIndex();
//SCFloatArrayRef in = sc.BaseDataIn[data_type_indx];
//SCDateTimeArrayRef ti = sc.BaseDateTimeIn[data_type_indx];
sc.AdaptiveMovAvg(sc.BaseDataIn[SC_LAST], Subgraph_KAMA, 9, 2, 109);
float kama = Subgraph_KAMA[i];
sc.T3MovingAverage(sc.BaseDataIn[SC_LAST], Subgraph_T3, 0.84, 10);
float t3 = Subgraph_T3[i];
sc.ADX(sc.BaseDataIn, Subgraph_ADX, i, 14, 14);
float adx = Subgraph_ADX[i];
sc.AwesomeOscillator(sc.BaseDataIn[SC_LAST], Subgraph_AO, 0, 0);
float ao = Subgraph_AO[i];
sc.HullMovingAverage(sc.BaseDataIn[SC_LAST], Subgraph_HMA, 10);
float hma = Subgraph_HMA[i];
float phma = Subgraph_HMA[i - 1];
sc.MovingAverage(sc.BaseDataIn[SC_LAST], Subgraph_Fast, MOVAVGTYPE_EXPONENTIAL, 20);
float a1 = Subgraph_Fast[i];
float b1 = Subgraph_Fast[i - 1];
sc.MovingAverage(sc.BaseDataIn[SC_LAST], Subgraph_Slow, MOVAVGTYPE_EXPONENTIAL, 40);
float a2 = Subgraph_Slow[i];
float b2 = Subgraph_Slow[i - 1];
sc.BollingerBands(sc.BaseDataIn[SC_LAST], Subgraph_BB, 20, 2, MOVAVGTYPE_SIMPLE);
float UpperBand = Subgraph_BB.Arrays[0][i];
float LowerBand = Subgraph_BB.Arrays[1][i];
float e1 = UpperBand - LowerBand;
float t1 = ((a1 - a2) - (b1 - b2)) * Input_WaddahIntensity.GetInt();
sc.MACD(sc.BaseDataIn[SC_LAST], Subgraph_LindaMACD, 3, 9, 16, MOVAVGTYPE_SIMPLE);
float linda = Subgraph_LindaMACD.Arrays[3][i];
sc.Parabolic(sc.BaseDataIn, sc.BaseDateTimeIn, Subgraph_Parabolic, i, 0.02f, 0.02f, 0.2f, 0, SC_HIGH, SC_LOW);
float SAR = Subgraph_Parabolic[i];
sc.RSI(sc.BaseDataIn[SC_LAST], Subgraph_Calc, MOVAVGTYPE_SIMPLE, 14);
float rsi = Subgraph_Calc[i];
float prsi = Subgraph_Calc[i - 1];
float pprsi = Subgraph_Calc[i - 2];
#pragma endregion
SCFloatArray SubgraphArray;
sc.GetStudyArray(11, 3, SubgraphArray);
if (SubgraphArray.GetArraySize() == 0)
{
// The SubgraphArray may not exist or is empty. Either way we can not do anything with it.
}
double dTickie = Input_ShavedBuffer.GetInt() * sc.TickSize;
if (Input_IgnoreDoji.GetYesNo() == SC_YES && doji)
return;
if (green && high == close)
{
Subgraph_ShavedGreen[i] = 1;
Subgraph_ColorBar.DataColor[i] = RGB(170, 221, 255);
}
if (red && close == low)
Subgraph_ShavedRed[i] = 1;
if (low < LowerBand && green && high > phigh && close > pclose && pclose < popen)
Subgraph_BBGreen[i] = 1;
if (high > UpperBand && red && low < plow && close < pclose && pclose < popen)
Subgraph_BBRed[i] = 1;
#pragma region BUY SELL PLOTS
if (BarCloseStatus)
{
int iEndings = 0;
const int32_t numLines = sc.GetNumLinesUntilFutureIntersection(sc.ChartNumber, sc.StudyGraphInstanceID) - 1;
if (numLines != 0)
{
for (int32_t lineIndex = numLines; lineIndex >= 0; --lineIndex)
{
int32_t lineID{ 0 };
int32_t startIndex{ 0 };
int32_t endIndex{ 0 };
float lineValue{ 0.0f };
if (sc.GetStudyLineUntilFutureIntersectionByIndex(sc.ChartNumber, sc.StudyGraphInstanceID, lineIndex, lineID, startIndex, lineValue, endIndex))
{
if (endIndex > 0)
{
iEndings++;
//DrawText(sc, Subgraph_3oU, "shit", 0, 5);
//sc.DeleteLineUntilFutureIntersection(startIndex, lineID);
//Subgraph_Intersection[i] = endIndex;
}
}
}
}
Subgraph_Intersection[i] = iEndings;