-
Notifications
You must be signed in to change notification settings - Fork 10
/
anaPivotsDailyV43.cs
2589 lines (2424 loc) · 87.8 KB
/
anaPivotsDailyV43.cs
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
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Collections;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
#region Global Enums
public enum anaPivotStylesPD43 {Floor, Wide, Fibonacci, Jackson, Camarilla, Woodie}
public enum anaSessionTypePD43 {DailyBars, ETH, RTH, Auto, UserDefined}
public enum anaSessionCountPD43 {First, Second, Third}
public enum anaCalcModePD43 {DailyClose, IntradayClose}
public enum anaPlotAlignPD43 {Left, Right, LeftAll, RightAll, DoNotPlot}
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Pivot Points.
/// </summary>
[Description("Daily Session Pivots.")]
public class anaPivotsDailyV43: Indicator
{
#region Variables
private SolidBrush[] brushes = { new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black),
new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black)};
private DateTime sessionBegin = Cbi.Globals.MinDate;
private DateTime sessionEnd = Cbi.Globals.MinDate;
private DateTime plotStart = Cbi.Globals.MaxDate;
private DateTime cacheSessionBeginTmp = Cbi.Globals.MinDate;
private DateTime cacheSessionEndTmp = Cbi.Globals.MinDate;
private DateTime cacheSessionDate = Cbi.Globals.MinDate;
private DateTime sessionDateTmp = Cbi.Globals.MinDate;
private DateTime currentDate = Cbi.Globals.MinDate;
private DateTime priorDate = Cbi.Globals.MinDate;
private DateTime lastBarTimeStamp1 = Cbi.Globals.MinDate;
private double currentHigh = double.MinValue;
private double currentLow = double.MaxValue;
private double currentClose = 0.0;
private double high = 0.0;
private double low = 0.0;
private double close = 0.0;
private double volSum = 0.0;
private double volPriceSum = 0.0;
private double currentVolSum = 0.0;
private double currentVolPriceSum = 0.0;
private double displaySize = 0.0;
private Bars dailyBars = null;
private bool tickBuilt = false;
private bool showMidpivots = false;
private bool showPriorPeriods = true;
private bool existsHistDailyData = false;
private bool isDailyDataLoaded = false;
private bool plotPivots = false;
private bool calcOpen = false;
private bool bridgePublicHoliday = false;
private bool extendPublicHoliday = false;
private bool noDailyData = false;
private bool noCurrentDailyBar = false;
private bool isCurrency = false;
private bool isGlobex = false;
private ArrayList newSessionBarIdxArr1 = new ArrayList();
private anaPlotAlignPD43 plotLabels = anaPlotAlignPD43.RightAll;
private anaPivotStylesPD43 pivotFormula = anaPivotStylesPD43.Floor;
private anaSessionTypePD43 pivotSession = anaSessionTypePD43.Auto;
private anaSessionTypePD43 selectedSession = anaSessionTypePD43.ETH;
private anaSessionCountPD43 activeSession = anaSessionCountPD43.Second;
private anaCalcModePD43 calcMode = anaCalcModePD43.DailyClose;
private Data.PivotRange pivotRangeType1 = PivotRange.Daily;
private double range = 0.0;
private double pp = 0.0;
private double r1 = 0.0;
private double r2 = 0.0;
private double r3 = 0.0;
private double r4 = 0.0;
private double r5 = 0.0;
private double s1 = 0.0;
private double s2 = 0.0;
private double s3 = 0.0;
private double s4 = 0.0;
private double s5 = 0.0;
private double rmid = 0.0;
private double r12mid = 0.0;
private double r23mid = 0.0;
private double r34mid = 0.0;
private double r45mid = 0.0;
private double smid = 0.0;
private double s12mid = 0.0;
private double s23mid = 0.0;
private double s34mid = 0.0;
private double s45mid = 0.0;
private double centralPivot = 0.0;
private double directionalPivot = 0.0;
private double previousVWAP = 0.0;
private double previousHigh = 0.0;
private double previousLow = 0.0;
private double previousClose = 0.0;
private SolidBrush pivotBrush = new SolidBrush(Color.DodgerBlue);
private SolidBrush centralBrush = new SolidBrush(Color.Navy);
private SolidBrush jacksonBrush = new SolidBrush(Color.SlateGray);
private SolidBrush errorBrush = new SolidBrush(Color.White);
private Pen pivotLinePen = null;
private Font labelFont = new Font("Arial", 8);
private Font errorFont = new Font("Arial", 10);
private string errorData1 = "Daily Pivots can only be displayed on intraday charts.";
private string errorData2 = "No daily data found. Please reload daily data or use CalcFromIntradayData.";
private string errorData3 = "The prior close detected by the Daily Pivots indicator is not within the range of the selected session.";
private string errorData4 = "Insufficient historical data for the Daily Pivots indicator. Please increase the chart look back period.";
private float errorTextHeight = 0;
private StringFormat stringFormatCenter = new StringFormat();
private StringFormat stringFormatFar = new StringFormat();
private StringFormat stringFormatNear = new StringFormat();
private double userDefinedClose = 0.0;
private double userDefinedHigh = 0.0;
private double userDefinedLow = 0.0;
private int countDown = 1;
private int numberOfSessions = 1;
private int sessionCount = 0;
private int width = 20;
private int labelFontSize = 8;
private int labelOffset = 20;
private int opacityPR = 5;
private int opacityJZ = 5;
private int plot0Width = 1;
private DashStyle dash0Style = DashStyle.Solid;
private int plot1Width = 1;
private DashStyle dash1Style = DashStyle.DashDot;
private int plot2Width = 2;
private DashStyle dash2Style = DashStyle.Dot;
private Color pivotColor = Color.CornflowerBlue;
private Color resistanceColor = Color.LightSkyBlue;
private Color supportColor = Color.LightSkyBlue;
private Color midpivotColor = Color.LightSkyBlue;
private Color highColor = Color.Lime;
private Color lowColor = Color.OrangeRed;
private Color closeColor = Color.Yellow;
private Color centralPivotColor = Color.CornflowerBlue;
private Color directionalPivotColor = Color.CornflowerBlue;
private Color pivotRangeColor = Color.DodgerBlue;
private Color centralRangeColor = Color.Navy;
private Color jacksonZonesColor = Color.SlateGray;
private Color vwapColor = Color.HotPink;
private DateTime publicHoliday0 = new DateTime (2009,01,19);
private DateTime publicHoliday1 = new DateTime (2009,02,16);
private DateTime publicHoliday2 = new DateTime (2009,05,25);
private DateTime publicHoliday3 = new DateTime (2009,07,03);
private DateTime publicHoliday4 = new DateTime (2009,09,07);
private DateTime publicHoliday5 = new DateTime (2009,11,26);
private DateTime publicHoliday6 = new DateTime (2010,01,18);
private DateTime publicHoliday7 = new DateTime (2010,02,15);
private DateTime publicHoliday8 = new DateTime (2010,05,31);
private DateTime publicHoliday9 = new DateTime (2010,07,05);
private DateTime publicHoliday10 = new DateTime (2010,09,06);
private DateTime publicHoliday11 = new DateTime (2010,11,25);
private DateTime publicHoliday12 = new DateTime (2011,01,17);
private DateTime publicHoliday13 = new DateTime (2011,02,21);
private DateTime publicHoliday14 = new DateTime (2011,05,30);
private DateTime publicHoliday15 = new DateTime (2011,07,04);
private DateTime publicHoliday16 = new DateTime (2011,09,05);
private DateTime publicHoliday17 = new DateTime (2011,11,24);
private DateTime publicHoliday18 = new DateTime (2012,01,16);
private DateTime publicHoliday19 = new DateTime (2012,02,20);
private DateTime publicHoliday20 = new DateTime (2012,05,28);
private DateTime publicHoliday21 = new DateTime (2012,07,04);
private DateTime publicHoliday22 = new DateTime (2012,09,03);
private DateTime publicHoliday23 = new DateTime (2012,11,22);
private DateTime publicHoliday24 = new DateTime (2013,01,21);
private DateTime publicHoliday25 = new DateTime (2013,02,18);
private DateTime publicHoliday26 = new DateTime (2013,05,27);
private DateTime publicHoliday27 = new DateTime (2013,07,04);
private DateTime publicHoliday28 = new DateTime (2013,09,02);
private DateTime publicHoliday29 = new DateTime (2013,11,28);
private DateTime publicHoliday30 = new DateTime (2014,01,20);
private DateTime publicHoliday31 = new DateTime (2014,02,17);
private DateTime publicHoliday32 = new DateTime (2014,05,26);
private DateTime publicHoliday33 = new DateTime (2014,07,04);
private DateTime publicHoliday34 = new DateTime (2014,09,01);
private DateTime publicHoliday35 = new DateTime (2014,11,27);
private DateTime publicHoliday36 = new DateTime (2015,01,19);
private DateTime publicHoliday37 = new DateTime (2015,02,16);
private DateTime publicHoliday38 = new DateTime (2015,05,25);
private DateTime publicHoliday39 = new DateTime (2015,07,03);
private DateTime publicHoliday40 = new DateTime (2015,09,07);
private DateTime publicHoliday41 = new DateTime (2015,11,26);
private DateTime[] publicHoliday = new DateTime [42];
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"PP "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R1 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S1 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R2 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S2 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R3 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S3 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R4 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S4 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R5 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S5 "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"RMid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"SMid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R12Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S12Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R23Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S23Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R34Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S34Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"R45Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"S45Mid "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"Y-High "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"Y-Low "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"Y-Close "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"CP "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"DP "));
Add(new Plot(new Pen(Color.Gray,1), PlotStyle.Line,"Y-VWAP"));
AutoScale = false;
Overlay = true;
PriceTypeSupported = false;
PlotsConfigurable = false;
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
BarsRequired = 0;
ZOrder = 1;
stringFormatNear.Alignment = StringAlignment.Near;
stringFormatCenter.Alignment = StringAlignment.Center;
stringFormatFar.Alignment = StringAlignment.Far;
}
/// <summary>
/// </summary>
protected override void OnStartUp()
{
if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Future &&
(Instrument.MasterInstrument.Name == "EMD" ||Instrument.MasterInstrument.Name == "ES" || Instrument.MasterInstrument.Name == "NQ"
||Instrument.MasterInstrument.Name == "YM"||Instrument.MasterInstrument.Name == "GE" ||Instrument.MasterInstrument.Name == "SR"
||Instrument.MasterInstrument.Name == "UB"||Instrument.MasterInstrument.Name == "ZB" ||Instrument.MasterInstrument.Name == "ZF"
||Instrument.MasterInstrument.Name == "ZN"||Instrument.MasterInstrument.Name == "ZQ" ||Instrument.MasterInstrument.Name == "ZT"
||Instrument.MasterInstrument.Name == "6A"||Instrument.MasterInstrument.Name == "6B" ||Instrument.MasterInstrument.Name == "6C"
||Instrument.MasterInstrument.Name == "6E"||Instrument.MasterInstrument.Name == "6J" ||Instrument.MasterInstrument.Name == "6M"
||Instrument.MasterInstrument.Name == "6N"||Instrument.MasterInstrument.Name == "6S" ||Instrument.MasterInstrument.Name == "E7"
||Instrument.MasterInstrument.Name == "J7"||Instrument.MasterInstrument.Name == "M6A" ||Instrument.MasterInstrument.Name == "M6B"
||Instrument.MasterInstrument.Name == "M6C"||Instrument.MasterInstrument.Name == "M6E" ||Instrument.MasterInstrument.Name == "M6J"
||Instrument.MasterInstrument.Name == "M6S"||Instrument.MasterInstrument.Name == "CL" ||Instrument.MasterInstrument.Name == "EH"
||Instrument.MasterInstrument.Name == "GC"||Instrument.MasterInstrument.Name == "HG" ||Instrument.MasterInstrument.Name == "HO"
||Instrument.MasterInstrument.Name == "NG"||Instrument.MasterInstrument.Name == "QG" ||Instrument.MasterInstrument.Name == "QM"
||Instrument.MasterInstrument.Name == "RB"||Instrument.MasterInstrument.Name == "SI" ||Instrument.MasterInstrument.Name == "YG"
||Instrument.MasterInstrument.Name == "YI"||Instrument.MasterInstrument.Name == "GF" ||Instrument.MasterInstrument.Name == "GPB"
||Instrument.MasterInstrument.Name == "HE"||Instrument.MasterInstrument.Name == "LE" ||Instrument.MasterInstrument.Name == "YC"
||Instrument.MasterInstrument.Name == "YK"||Instrument.MasterInstrument.Name == "YW" ||Instrument.MasterInstrument.Name == "ZC"
||Instrument.MasterInstrument.Name == "ZE"||Instrument.MasterInstrument.Name == "ZL" ||Instrument.MasterInstrument.Name == "ZM"
||Instrument.MasterInstrument.Name == "ZO"||Instrument.MasterInstrument.Name == "ZR" ||Instrument.MasterInstrument.Name == "ZS"
||Instrument.MasterInstrument.Name == "ZW"))
isGlobex = true;
if (isGlobex)
{
publicHoliday[0] = publicHoliday0;
publicHoliday[1] = publicHoliday1;
publicHoliday[2] = publicHoliday2;
publicHoliday[3] = publicHoliday3;
publicHoliday[4] = publicHoliday4;
publicHoliday[5] = publicHoliday5;
publicHoliday[6] = publicHoliday6;
publicHoliday[7] = publicHoliday7;
publicHoliday[8] = publicHoliday8;
publicHoliday[9] = publicHoliday9;
publicHoliday[10] = publicHoliday10;
publicHoliday[11] = publicHoliday11;
publicHoliday[12] = publicHoliday12;
publicHoliday[13] = publicHoliday13;
publicHoliday[14] = publicHoliday14;
publicHoliday[15] = publicHoliday15;
publicHoliday[16] = publicHoliday16;
publicHoliday[17] = publicHoliday17;
publicHoliday[18] = publicHoliday18;
publicHoliday[19] = publicHoliday19;
publicHoliday[20] = publicHoliday20;
publicHoliday[21] = publicHoliday21;
publicHoliday[22] = publicHoliday22;
publicHoliday[23] = publicHoliday23;
publicHoliday[24] = publicHoliday24;
publicHoliday[25] = publicHoliday25;
publicHoliday[26] = publicHoliday26;
publicHoliday[27] = publicHoliday27;
publicHoliday[28] = publicHoliday28;
publicHoliday[29] = publicHoliday29;
publicHoliday[30] = publicHoliday30;
publicHoliday[31] = publicHoliday31;
publicHoliday[32] = publicHoliday32;
publicHoliday[33] = publicHoliday33;
publicHoliday[34] = publicHoliday34;
publicHoliday[35] = publicHoliday35;
publicHoliday[36] = publicHoliday36;
publicHoliday[37] = publicHoliday37;
publicHoliday[38] = publicHoliday38;
publicHoliday[39] = publicHoliday39;
publicHoliday[40] = publicHoliday40;
publicHoliday[41] = publicHoliday41;
}
else for(int i=0; i<42; i++)
publicHoliday[i] = Cbi.Globals.MinDate;
if (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.Currency || Instrument.MasterInstrument.Name == "DX"|| Instrument.MasterInstrument.Name == "6A"
|| Instrument.MasterInstrument.Name == "6B" || Instrument.MasterInstrument.Name == "6C" ||Instrument.MasterInstrument.Name == "6E"
|| Instrument.MasterInstrument.Name == "6J" || Instrument.MasterInstrument.Name == "6M" || Instrument.MasterInstrument.Name == "6S"
|| Instrument.MasterInstrument.Name == "6N" || Instrument.MasterInstrument.Name == "E7" || Instrument.MasterInstrument.Name == "J7"
|| Instrument.MasterInstrument.Name == "M6A" || Instrument.MasterInstrument.Name == "M6B" || Instrument.MasterInstrument.Name == "M6C"
|| Instrument.MasterInstrument.Name == "M6E" || Instrument.MasterInstrument.Name == "M6J" || Instrument.MasterInstrument.Name == "M6S")
isCurrency = true;
if (pivotSession == anaSessionTypePD43.Auto && isCurrency)
selectedSession = anaSessionTypePD43.ETH;
else if(pivotSession == anaSessionTypePD43.Auto)
selectedSession = anaSessionTypePD43.RTH;
else
selectedSession = pivotSession;
labelFont = new Font ("Arial", labelFontSize);
if (PivotFormula == anaPivotStylesPD43.Jackson)
{
Plots[0].Name = "PP";
Plots[1].Name = "R1";
Plots[2].Name = "S1";
Plots[3].Name = "RB1";
Plots[4].Name = "SB1";
Plots[5].Name = "R2";
Plots[6].Name = "S2";
Plots[7].Name = "RB2";
Plots[8].Name = "SB2";
Plots[9].Name = "R3";
Plots[10].Name = "S3";
jacksonBrush = new SolidBrush(Color.FromArgb(25*opacityJZ, jacksonZonesColor));
}
else
{
Plots[0].Name = "PP";
Plots[1].Name = "R1";
Plots[2].Name = "S1";
Plots[3].Name = "R2";
Plots[4].Name = "S2";
Plots[5].Name = "R3";
Plots[6].Name = "S3";
Plots[7].Name = "R4";
Plots[8].Name = "S4";
Plots[9].Name = "R5";
Plots[10].Name = "S5";
}
labelFont = new Font ("Arial", labelFontSize);
pivotBrush = new SolidBrush(Color.FromArgb(25*opacityPR, pivotRangeColor));
centralBrush = new SolidBrush(Color.FromArgb(25*opacityPR, centralRangeColor));
pivotLinePen = new Pen(Color.FromArgb(Math.Min(40*opacityPR,255), pivotRangeColor),1);
pivotLinePen.DashStyle = DashStyle.Dot;
Plots[0].Pen.Color = pivotColor;
Plots[1].Pen.Color = resistanceColor;
Plots[2].Pen.Color = supportColor;
Plots[3].Pen.Color = resistanceColor;
Plots[4].Pen.Color = supportColor;
Plots[5].Pen.Color = resistanceColor;
Plots[6].Pen.Color = supportColor;
Plots[7].Pen.Color = resistanceColor;
Plots[8].Pen.Color = supportColor;
Plots[9].Pen.Color = resistanceColor;
Plots[10].Pen.Color = supportColor;
Plots[11].Pen.Color = midpivotColor;
Plots[12].Pen.Color = midpivotColor;
Plots[13].Pen.Color = midpivotColor;
Plots[14].Pen.Color = midpivotColor;
Plots[15].Pen.Color = midpivotColor;
Plots[16].Pen.Color = midpivotColor;
Plots[17].Pen.Color = midpivotColor;
Plots[18].Pen.Color = midpivotColor;
Plots[19].Pen.Color = midpivotColor;
Plots[20].Pen.Color = midpivotColor;
Plots[21].Pen.Color = highColor;
Plots[22].Pen.Color = lowColor;
Plots[23].Pen.Color = closeColor;
Plots[24].Pen.Color = centralPivotColor;
Plots[25].Pen.Color = directionalPivotColor;
Plots[26].Pen.Color = vwapColor;
for (int i = 0; i < 11; i++)
{
Plots[i].Pen.Width = plot0Width;
Plots[i].Pen.DashStyle = dash0Style;
}
for (int i = 11; i < 21; i++)
{
Plots[i].Pen.Width = plot1Width;
Plots[i].Pen.DashStyle = dash1Style;
}
for (int i = 21; i < 24; i++)
{
Plots[i].Pen.Width = plot2Width;
Plots[i].Pen.DashStyle = dash2Style;
}
for (int i = 24; i < 27; i++)
{
Plots[i].Pen.Width = plot0Width;
Plots[i].Pen.DashStyle = dash0Style;
}
if(ChartControl != null)
errorBrush.Color = ChartControl.AxisColor;
if (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.Currency && (TickSize == 0.00001 || TickSize == 0.001))
displaySize = 5* TickSize;
else
displaySize = TickSize;
if (AutoScale)
AutoScale = false;
if (!Bars.BarsType.IsIntraday || BarsPeriod.Id == PeriodType.Minute || BarsPeriod.Id == PeriodType.Second)
tickBuilt = false;
else
tickBuilt = true;
existsHistDailyData = false;
if(selectedSession == anaSessionTypePD43.DailyBars || selectedSession == anaSessionTypePD43.UserDefined)
countDown = 0;
else
countDown = 1;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Bars == null)
return;
if (!Bars.BarsType.IsIntraday && Bars.Period.Id != PeriodType.Day)
return;
if (Bars.Period.Id == PeriodType.Day && Bars.Period.Value > 1)
return;
if (Bars.Period.Id == PeriodType.Day && pivotRangeType1 == PivotRange.Daily)
{
DrawTextFixed("errortag1", errorData1, TextPosition.Center, errorBrush.Color, errorFont, Color.Transparent,Color.Transparent,0);
return;
}
if (CurrentBar == 0)
{
if (selectedSession == anaSessionTypePD43.UserDefined)
{
currentHigh = userDefinedHigh;
currentLow = userDefinedLow;
currentClose = userDefinedClose;
}
else
{
currentDate = GetLastBarSessionDate(Time[0], Bars, 0, pivotRangeType1);
sessionCount = 1;
}
existsHistDailyData = false;
return;
}
if(FirstTickOfBar && Bars.BarsType.IsIntraday && (selectedSession == anaSessionTypePD43.DailyBars || (selectedSession != anaSessionTypePD43.UserDefined && calcMode == anaCalcModePD43.DailyClose)))
{
if(!isDailyDataLoaded)
{
Enabled = false;
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetBarsNow));
return;
}
if (!existsHistDailyData)
{
DrawTextFixed("errortag2", errorData2, TextPosition.Center, errorBrush.Color, errorFont, Color.Transparent,Color.Transparent,0);
return;
}
IBar dailyBar;
if (existsHistDailyData)
{
noCurrentDailyBar = false;
noDailyData = false;
dailyBar = dailyBars.Get(dailyBars.GetBar(currentDate));
if (dailyBar.Time.Date != currentDate)
{
noCurrentDailyBar = true;
dailyBar = dailyBars.Get(dailyBars.GetBar(priorDate));
if (dailyBar.Time.Date != priorDate)
{
noDailyData = true;
}
}
if(selectedSession == anaSessionTypePD43.DailyBars)
{
high = dailyBar.High;
low = dailyBar.Low;
}
close = dailyBar.Close;
}
else
dailyBar = null;
}
if(!existsHistDailyData)
{
high = High[0];
low = Low[0];
close = Close[0];
}
else if (selectedSession != anaSessionTypePD43.DailyBars)
{
high = High[0];
low = Low[0];
}
lastBarTimeStamp1 = GetLastBarSessionDate(Time[0], Bars, 0, pivotRangeType1);
if (lastBarTimeStamp1 != currentDate)
{
countDown = countDown -1;
sessionCount = 1;
calcOpen = false;
if (countDown < 0 && existsHistDailyData)
{
currentClose = close;
if (selectedSession == anaSessionTypePD43.DailyBars)
{
currentHigh = Math.Max(currentHigh, high);
currentLow = Math.Min(currentLow, low);
}
}
priorDate = currentDate;
currentDate = lastBarTimeStamp1;
bridgePublicHoliday = false;
for (int i =0; i<42; i++)
{
if (publicHoliday[i].Date == priorDate)
bridgePublicHoliday = true;
}
if ((countDown < 0 && !bridgePublicHoliday) || selectedSession == anaSessionTypePD43.UserDefined)
{
if(!plotPivots)
{
Bars.Session.GetNextBeginEnd(Bars, 0, out sessionBegin, out sessionEnd);
plotStart = sessionBegin;
}
range = (currentHigh - currentLow);
if (PivotFormula == anaPivotStylesPD43.Fibonacci)
{
pp = (currentHigh + currentLow + currentClose)/ 3;
r1 = pp + 0.382*range;
s1 = pp - 0.382*range;
r2 = pp + 0.618*range;
s2 = pp - 0.618*range;
r3 = pp + range;
s3 = pp - range;
r4 = pp + 1.382*range;
s4 = pp - 1.382*range;
r5 = pp + 1.618*range;
s5 = pp - 1.618*range;
}
else if (PivotFormula == anaPivotStylesPD43.Jackson)
{
pp = (currentHigh + currentLow + currentClose)/ 3;
r1 = pp + 0.500*range;
s1 = pp - 0.500*range;
r2 = pp + 0.618*range;
s2 = pp - 0.618*range;
r3 = pp + range;
s3 = pp - range;
r4 = pp + 1.382*range;
s4 = pp - 1.382*range;
r5 = pp + 1.618*range;
s5 = pp - 1.618*range;
}
else if (PivotFormula == anaPivotStylesPD43.Camarilla)
{
pp = (currentHigh + currentLow + currentClose)/ 3;
r1 = currentClose + 1.1/12*range;
s1 = currentClose - 1.1/12*range;
r2 = currentClose + 1.1/6*range;
s2 = currentClose - 1.1/6*range;
r3 = currentClose + 1.1/4*range;
s3 = currentClose - 1.1/4*range;
r4 = currentClose + 1.1/2*range;
s4 = currentClose - 1.1/2*range;
if(currentLow != 0)
{
r5 = currentClose * currentHigh / currentLow;
s5 = 2 * currentClose - r5;
}
}
else
{
if (PivotFormula == anaPivotStylesPD43.Floor || PivotFormula == anaPivotStylesPD43.Wide)
pp = (currentHigh + currentLow + currentClose)/ 3;
else if (PivotFormula == anaPivotStylesPD43.Woodie)
pp = (currentHigh + currentLow + 2*currentClose)/ 4;
r1 = 2 * pp - currentLow;
s1 = 2 * pp - currentHigh;
r2 = pp + range;
s2 = pp - range;
if (PivotFormula == anaPivotStylesPD43.Floor || PivotFormula == anaPivotStylesPD43.Woodie)
{
r3 = r1 + range;
s3 = s1 - range;
r4 = r3 + (pp - currentLow);
s4 = s3 - (currentHigh - pp);
r5 = r4 + (pp - currentLow);
s5 = s4 - (currentHigh - pp);
}
else if (PivotFormula == anaPivotStylesPD43.Wide)
{
r3 = r2 + range;
s3 = s2 - range;
r4 = r3 + range;
s4 = s3 - range;
r5 = r4 + range;
s5 = s4 - range;
}
rmid = 0.5*(pp+r1);
smid = 0.5*(pp+s1);
r12mid = 0.5*(r1+r2);
s12mid = 0.5*(s1+s2);
r23mid = 0.5*(r2+r3);
s23mid = 0.5*(s2+s3);
r34mid = 0.5*(r3+r4);
s34mid = 0.5*(s3+s4);
r45mid = 0.5*(r4+r5);
s45mid = 0.5*(s4+s5);
}
pp = Math.Round(pp/displaySize)* displaySize;
r1 = Math.Round(r1/displaySize)* displaySize;
s1 = Math.Round(s1/displaySize)* displaySize;
r2 = Math.Round(r2/displaySize)* displaySize;
s2 = Math.Round(s2/displaySize)* displaySize;
r3 = Math.Round(r3/displaySize)* displaySize;
s3 = Math.Round(s3/displaySize)* displaySize;
r4 = Math.Round(r4/displaySize)* displaySize;
s4 = Math.Round(s4/displaySize)* displaySize;
r5 = Math.Round(r5/displaySize)* displaySize;
s5 = Math.Round(s5/displaySize)* displaySize;
if (showMidpivots && PivotFormula != anaPivotStylesPD43.Camarilla &&
PivotFormula != anaPivotStylesPD43.Fibonacci && PivotFormula != anaPivotStylesPD43.Jackson)
{
rmid = Math.Round(rmid/displaySize)* displaySize;
smid = Math.Round(smid/displaySize)* displaySize;
r12mid = Math.Round(r12mid/displaySize)* displaySize;
s12mid = Math.Round(s12mid/displaySize)* displaySize;
r23mid = Math.Round(r23mid/displaySize)* displaySize;
s23mid = Math.Round(s23mid/displaySize)* displaySize;
r34mid = Math.Round(r34mid/displaySize)* displaySize;
s34mid = Math.Round(s34mid/displaySize)* displaySize;
r45mid = Math.Round(r45mid/displaySize)* displaySize;
s45mid = Math.Round(s45mid/displaySize)* displaySize;
}
previousHigh = currentHigh;
previousLow = currentLow;
previousClose = currentClose;
centralPivot = Math.Round(((currentHigh + currentLow) / 2 + 0.01*displaySize)/displaySize)*displaySize;
directionalPivot = Math.Round((2*pp - centralPivot)/displaySize)* displaySize;
if (volSum > double.Epsilon)
previousVWAP = Math.Round(currentVolPriceSum/(currentVolSum*displaySize))* displaySize;
else
previousVWAP = 0.0;
if (noDailyData)
plotPivots = false;
else
plotPivots = true;
}
if (selectedSession != anaSessionTypePD43.UserDefined)
{
if (!existsHistDailyData || (existsHistDailyData && selectedSession != anaSessionTypePD43.DailyBars))
{
if (numberOfSessions == 1 || selectedSession == anaSessionTypePD43.ETH || (selectedSession == anaSessionTypePD43.RTH && activeSession == anaSessionCountPD43.First))
{
if (!existsHistDailyData)
currentClose = close;
if (!bridgePublicHoliday || selectedSession == anaSessionTypePD43.RTH)
{
currentHigh = high;
currentLow = low;
volSum = 0.0;
volPriceSum = 0.0;
}
else
{
currentHigh = Math.Max(currentHigh, high);
currentLow = Math.Min(currentLow, low);
volSum = currentVolSum;
volPriceSum = currentVolPriceSum;
}
currentVolSum = volSum + Volume[0];
currentVolPriceSum = volPriceSum + Typical[0]*Volume[0];
calcOpen = true;
}
else
{
volSum = 0.0;
volPriceSum = 0.0;
currentVolPriceSum = 0.0;
currentVolSum = 0.0;
calcOpen = false;
}
}
else
{
if (!bridgePublicHoliday || noCurrentDailyBar)
{
currentHigh = double.MinValue;
currentLow = double.MaxValue;
}
if (!bridgePublicHoliday)
{
volSum = 0.0;
volPriceSum = 0.0;
}
else
{
volSum = currentVolSum;
volPriceSum = currentVolPriceSum;
}
currentVolSum = volSum + Volume[0];
currentVolPriceSum = volPriceSum + Typical[0]*Volume[0];
calcOpen = true;
}
}
}
else if (selectedSession != anaSessionTypePD43.UserDefined && Bars.FirstBarOfSession)
{
if (FirstTickOfBar)
{
sessionCount = sessionCount + 1;
numberOfSessions = Math.Min(3, Math.Max(sessionCount, numberOfSessions));
}
if (existsHistDailyData && selectedSession == anaSessionTypePD43.DailyBars)
{
if (FirstTickOfBar)
{
volSum = currentVolSum;
volPriceSum = currentVolPriceSum;
}
currentVolSum = volSum + Volume[0];
currentVolPriceSum = volPriceSum + Typical[0]*Volume[0];
calcOpen = true;
}
else if (numberOfSessions == 1 || selectedSession == anaSessionTypePD43.ETH)
{
if (!existsHistDailyData)
currentClose = close;
currentHigh = Math.Max(currentHigh, high);
currentLow = Math.Min(currentLow, low);
if (FirstTickOfBar)
{
volSum = currentVolSum;
volPriceSum = currentVolPriceSum;
}
currentVolSum = volSum + Volume[0];
currentVolPriceSum = volPriceSum + Typical[0]*Volume[0];
calcOpen = true;
}
else if (selectedSession == anaSessionTypePD43.RTH && ((sessionCount == 1 && activeSession == anaSessionCountPD43.First) || (sessionCount == 2 &&
activeSession == anaSessionCountPD43.Second) || (sessionCount == 3 && activeSession == anaSessionCountPD43.Third)))
{
if (FirstTickOfBar)
{
volSum = 0.0;
volPriceSum = 0.0;
}
if (!existsHistDailyData)
currentClose = close;
currentHigh = high;
currentLow = low;
currentVolSum = Volume[0];
currentVolPriceSum = Typical[0]*Volume[0];
calcOpen = true;
}
else
calcOpen = false;
}
else if (selectedSession != anaSessionTypePD43.UserDefined && calcOpen)
{
if (selectedSession != anaSessionTypePD43.DailyBars)
{
if (!existsHistDailyData)
currentClose = close;
currentHigh = Math.Max(currentHigh, high);
currentLow = Math.Min(currentLow, low);
}
if (FirstTickOfBar)
{
volSum = currentVolSum;
volPriceSum = currentVolPriceSum;
}
currentVolSum = volSum + Volume[0];
currentVolPriceSum = volPriceSum + Typical[0]*Volume[0];
}
if (FirstTickOfBar)
{
if(plotPivots && !(selectedSession == anaSessionTypePD43.RTH && activeSession == anaSessionCountPD43.Third && numberOfSessions == 2))
{
PP.Set(pp);
R1.Set(r1);
S1.Set(s1);
R2.Set(r2);
S2.Set(s2);
R3.Set(r3);
S3.Set(s3);
R4.Set(r4);
S4.Set(s4);
R5.Set(r5);
S5.Set(s5);
if (showMidpivots && PivotFormula != anaPivotStylesPD43.Camarilla &&
PivotFormula != anaPivotStylesPD43.Fibonacci && PivotFormula != anaPivotStylesPD43.Jackson)
{
RMid.Set(rmid);
SMid.Set(smid);
R12Mid.Set(r12mid);
S12Mid.Set(s12mid);
R23Mid.Set(r23mid);
S23Mid.Set(s23mid);
R34Mid.Set(r34mid);
S34Mid.Set(s34mid);
R45Mid.Set(r45mid);
S45Mid.Set(s45mid);
}
PreviousHigh.Set(previousHigh);
PreviousLow.Set(previousLow);
PreviousClose.Set(previousClose);
if(PivotFormula != anaPivotStylesPD43.Camarilla)
{
CentralPivot.Set(centralPivot);
DirectionalPivot.Set(directionalPivot);
}
else
{
CentralPivot.Reset();
DirectionalPivot.Reset();
}
if (Instrument.MasterInstrument.InstrumentType != Cbi.InstrumentType.Index && Instrument.MasterInstrument.InstrumentType != Cbi.InstrumentType.Currency
&& previousVWAP > double.Epsilon && selectedSession != anaSessionTypePD43.UserDefined)
PVWAP.Set(previousVWAP);
else
PVWAP.Reset();
}
else
{
PP.Reset();
R1.Reset();
S1.Reset();
R2.Reset();
S2.Reset();
R3.Reset();
S3.Reset();
R4.Reset();
S4.Reset();
R5.Reset();
S5.Reset();
RMid.Reset();
SMid.Reset();
R12Mid.Reset();
S12Mid.Reset();
R23Mid.Reset();
S23Mid.Reset();
R34Mid.Reset();
S34Mid.Reset();
R45Mid.Reset();
S45Mid.Reset();
PreviousHigh.Reset();
PreviousLow.Reset();
PreviousClose.Reset();
CentralPivot.Reset();
DirectionalPivot.Reset();
PVWAP.Reset();
}
if (existsHistDailyData && selectedSession == anaSessionTypePD43.RTH
&& (PreviousClose[0] < PreviousLow[0] || PreviousClose[0] > PreviousHigh[0]))
DrawTextFixed("errortag3", errorData3, TextPosition.Center, errorBrush.Color, errorFont, Color.Transparent,Color.Transparent,0);
else
DrawTextFixed("errortag3", "", TextPosition.Center, errorBrush.Color, errorFont, Color.Transparent,Color.Transparent,0);
}
}
#region Properties
/// <summary>
/// </summary>
[Description("Pivot Formula Type")]
[GridCategory("Options")]
[Gui.Design.DisplayNameAttribute("Pivot formula")]
public anaPivotStylesPD43 PivotFormula
{
get { return pivotFormula; }
set { pivotFormula = value; }
}
/// <summary>
/// </summary>
[Description("Session - ETH or RTH - used for calculating pivots")]
[GridCategory("Options")]
[Gui.Design.DisplayNameAttribute("Calculate from session")]
public anaSessionTypePD43 PivotSession
{
get { return pivotSession; }
set { pivotSession = value; }
}
/// <summary>
/// </summary>
[Description("Session # used for calculating RTH pivots")]
[GridCategory("Options")]
[Gui.Design.DisplayNameAttribute("Select session (RTH only)")]
public anaSessionCountPD43 ActiveSession
{
get { return activeSession; }
set { activeSession = value; }
}
/// <summary>
/// </summary>
[Description("Select the settlement or close price used for calculating pivots.")]
[GridCategory("Options")]
[Gui.Design.DisplayNameAttribute("Settlement/Close")]
public anaCalcModePD43 CalcMode
{
get { return calcMode; }
set { calcMode = value; }
}
/// <summary>
/// </summary>
[Description("Option to show MidPivots")]
[GridCategory("Options")]
[Gui.Design.DisplayNameAttribute("Show midpivots")]
public bool ShowMidpivots
{
get { return showMidpivots; }
set { showMidpivots = value; }
}
[Description("Option to show plots for prior days")]
[GridCategory("Options")]
[Gui.Design.DisplayNameAttribute("Show prior days")]
public bool ShowPriorPeriods
{
get { return showPriorPeriods; }
set { showPriorPeriods = value; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore]
public DataSeries PP
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore]
public DataSeries R1
{
get { return Values[1]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore]
public DataSeries S1
{
get { return Values[2]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore]
public DataSeries R2
{
get { return Values[3]; }
}
/// <summary>
/// </summary>
[Browsable(false)]