Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

BB & KB Squeeze & TGL CROSS NEW for Amibroker (AFL)

Rating:
3 / 5 (Votes 7)
Tags:
amibroker

Using BBSqueeze in trading.
You can buy/sell at the first/second signal, as you consider.

Screenshots

Indicator / Formula

Copy & Paste Friendly
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
// BB & KB AREA COLOR SQUEEZE
 
_SECTION_BEGIN("Bollinger Bands");
//P = ParamField("Price field",-1);
PeriodsBB = Param("PeriodsBB", 15, 2, 300, 1 );
WidthBB = Param("WidthBB", 2, 0, 10, 0.05 );
//Color = ParamColor("Color", colorCycle );
//Style = ParamStyle("Style");
//Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
//Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
Plot( BBandTop( C, PeriodsBB, WidthBB ), "\nBBTop" + _PARAM_VALUES(), colorBlue , styleLine+styleThick );
Plot( BBandBot( C, PeriodsBB, WidthBB ), "\nBBBot" + _PARAM_VALUES(), colorBlue , styleLine+styleThick ); 
_SECTION_END();
 
_SECTION_BEGIN("Keltner Bands");
//P = ParamField("Price field",-1);
PeriodsKB = Param("PeriodsKB", 15, 2, 300, 1 );
WidthKB = Param("WidthKB", 2, 0, 10, 0.05 );
//Color = ParamColor("Color", colorCycle );
//Style = ParamStyle("Style", styleLine | styleNoLabel);
 
CenterLine = MA( C, PeriodsBB ); // OBSERVATIE: CenterLine= BBMid= KMid ;
 
KTop   = CenterLine + WidthKB * ATR( PeriodsKB );
KBot = CenterLine - WidthKB * ATR( PeriodsKB );
 
//Plot( KTop, "KBTop" + _PARAM_VALUES(), Color, Style );
//Plot( KBot, "KBBot" + _PARAM_VALUES(), Color, Style );
Plot( KTop, "\nKBTop" + _PARAM_VALUES(), colorRed , styleLine+styleThick );
Plot( KBot, "\nKBBot" + _PARAM_VALUES(), colorRed , styleLine+styleThick );
_SECTION_END();
 
bbupper= BBandTop( C, PeriodsBB, WidthBB ) ;
bblower= BBandBot( C, PeriodsBB, WidthBB ) ;
bbmid= (bbupper+bblower)/2 ;
bbmidcol= IIf(bbmid>=Ref(bbmid,-1),colorBlue,colorAqua ) ;
//Plot(bbmid,"\nBBMid",colorBlue,styleLine) ;
Plot(bbmid,"\nBBMid",bbmidcol,styleDots+styleThick ) ;
 
kupper= KTop ;
klower= KBot ;
kmid= (ktop+kbot)/2 ;
//Plot(kmid,"\nKMid",colorRed,styleLine) ;
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//XXXXXXXXXX HEIKIN ASHI DERZI EXACT FORMULA BEGIN DDDDDDDDDDDDDDDDD
 
_SECTION_BEGIN("HA Looping ( no AMA() )");
//SetChartOptions(0,chartShowArrows|chartShowDates);
///////////////////////////////////////////////////////////
//
// Heikin Ashi - Calculated Properly with no use of AMA
//
// JF Derzi, December 2012
//
//
 
HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4;
HaOpen[0]  = (HaClose[0] + Open[0]) / 2;
HaHigh[0]  = Max( High[0], Max( HaClose[0], HaOpen[0] ) );
HaLow[0]   = Min( Low[0], Min( HaClose[0], HaOpen[0] ) );
 
for (i=1; i<BarCount; i++)
    {
    HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i]) / 4;
    Haopen[i]  = (HaClose[i-1] + HaOpen[i-1]) / 2; // Here is the problem when using Arrays: Haopen always uses its own previous value
    HaHigh[i]  = Max( High[i], Max( HaClose[i], HaOpen[i] ) );
    Halow[i]   = Min( Low[i], Min( HaClose[i], HaOpen[i] ) );
}
 
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "HA", colorBlack, styleCandle );
 
 
barcolorha = IIf(HaClose>=HaOpen,colorGreen,colorRed);
SetBarFillColor(IIf(HaClose>=HaOpen,colorBrightGreen,colorOrange));
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "\nHeikinAshiDerzi", barcolorha, styleCandle );
 
 
//--------------------------------------------------------------------------------------------------------
 
// Heikin Ashi & C>O and C>Ref(C,-1)
/*
barcolorha = IIf(HaClose>=HaOpen AND C>O and C>Ref(C,-1),colorGreen,
             IIf(HaClose<HaOpen AND C<O and C<Ref(C,-1),colorRed,colorBlue ) ) ;
SetBarFillColor(IIf(HaClose>=HaOpen AND C>O and C>Ref(C,-1),colorBrightGreen ,
                IIf(HaClose<HaOpen AND C<O and C<Ref(C,-1),colorRed,colorBlue ) ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "\nHeikinAshiDerzi", barcolorha, styleCandle );
*/
 
//--------------------------------------------------------------------------------------------------------------
 
//Title = Name()+" "+Date()+" Heikin Ashi -- HaOpen:"+NumToStr(HaOpen,1.2,True)+" / HaHigh:"+NumToStr(HaHigh,1.2,True)+
//        " / HaLow:"+NumToStr(Halow,1.2,True)+" HaClose:"+NumToStr(Haclose,1.2, True);
 
_SECTION_END();
 
HAup= HaClose>=HaOpen ;
haDelta= HaClose-HaOpen ;
MAhaDelta= MA(haDelta,3) ;
haDeltaUpMA= haDelta>MA(haDelta,3) ;
 
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXHEIKIN ASHI EXACT FORMULA END DDDDDDDDDDDDDDDDDDDDDDDD
 
//PRICE
 
_SECTION_BEGIN("Price");
//SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%)Vol " +
            WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
//Plot( C, "", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
 
//barcolorc= IIf(C>O AND C>Ref(C,-1), colorBlue,
//           IIf(C<O AND C<Ref(C,-1), colorRed, colorTan)); //MODEL MODEL MODEL 3 CULORI
//SetBarFillColor( IIf(C>O AND C>Ref(C,-1), colorBrightGreen,
//                 IIf(C<O AND C<Ref(C,-1), colorOrange, colorTan))); //MODEL MODEL MODEL 3 CULORI
//Plot( C, "", barcolorc, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
//Plot( C, "", barcolorc, styleBar+styleThick );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
// BB & KB AREA COLOR SQUEEZE
 
//IsSignal =    bbUpper <= kUpper AND bbLower >= kLower;
// OBSERVATIE: KMid= BBMid ;
 
IsSqueeze= ( bbupper<=kupper AND bblower>=klower ) ;
 
IsSqueezeCol= IIf(issqueeze, colorAqua,colorPink) ;
PlotOHLC(bbupper,bbupper,bblower,bblower,"",issqueezecol,styleCloud) ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//RIBBON TMV BEGIN RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
 
_SECTION_BEGIN("MultipleRibbon");
// You plot a Ribbon by calling the function as follows: MultiRibbon("Color", "Ribbon Number", "Name To Display");
// The "Ribbon Number" is simply the order of the ribbon, starting with 1 as the bottom Ribbon. You can add as many
// ribbons as you want, until you run out of chart space. Just keep track of the 'Serial Number' (Ribbon Number). :-)
 
 
RibbonThickness = Param("RibbonThickness", 8, 1, 15, 0.1);
Font                = ParamList("Font:","Arial|Calibri|Futura|Tahoma|Times New Roman");
"";
function GfxConvertBarToPixelX(Bar)
{
 lvb = Status("lastvisiblebar"); fvb = Status("firstvisiblebar");
 pxchartleft = Status("pxchartleft"); pxchartwidth = Status("pxchartwidth");
 return pxchartleft + Bar  * pxchartwidth / (Lvb - fvb + 1);
}
 
procedure MultiRibbon(RibbonColor, Position, Label)
{
 LineColor  = colorLightGrey;
 Position   = RibbonThickness * Position;
 x2 = Status("pxchartright");
 y2 = Status("pxchartbottom");
 
 RibbonColor = IIf(GfxConvertBarToPixelX(BarIndex()-Status("firstvisiblebarindex")) > y2/1.5 * (RibbonThickness/100) * 18 ,
               RibbonColor, colorYellow);
 
 Plot(0, "", LineColor, styleOwnScale | styleNoLabel, 0, 100);
 Plot(Position, "", LineColor, styleOwnScale | styleNoLabel, 0, 100);
 Plot(Position, "", RibbonColor, styleArea | styleOwnScale | styleNoLabel, 0, 100);
 
 GfxSetTextColor(colorBlack);
 GfxSelectFont(Font, y2/1.5 * (RibbonThickness/100), 400);
 GfxDrawText(Label, 8, y2 * 1.001 -(y2 * Position/100) , y2/1.5 * (RibbonThickness/100) * 17, y2, 2 + 32 + 256);
  
}
 
//=================================================================================================================
//=================================================================================================================
 
//TREND ADVISOR
 
pointer[0] = 0;
 
/* Phase filter */
 
/*
Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200)) ;
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200) ;
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
*/
 
Cond1 = C>=MA(C,50) AND C<MA(C,200) AND MA(C,50)<MA(C,200);
Cond2 = C>=MA(C,50) AND C>=MA(C,200) AND MA(C,50)<MA(C,200) ;
Cond3 = C>=MA(C,50) AND C>=MA(C,200) AND MA(C,50)>=MA(C,200) ;
Cond4 = C<MA(C,50) AND C>=MA(C,200) AND MA(C,50)>=MA(C,200);
Cond5 = C<MA(C,50) AND C<MA(C,200) AND MA(C,50)>=MA(C,200);
Cond6 = C<MA(C,50) AND C<MA(C,200) AND MA(C,50)<MA(C,200);
 
 
for (i = 1; i < BarCount; i++)
{
 
  if (Cond1[i])
    pointer[i] = 1;
  if (Cond2[i])
    pointer[i] = 2;
  if (Cond3[i])
    pointer[i] = 3;
  if (Cond4[i])
    pointer[i] = 4;
  if (Cond5[i])
    pointer[i] = 5;
  if (Cond6[i])
    pointer[i] = 6;
 
}
 
/* Plot Graphic */
GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdvisor", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));
 
Cond = pointer<4 ;
Condmy = pointer<=4 ;
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//GRAPHIC MODIFIED BULL&BEAR VOLUME CHYNTHIA
 
_SECTION_BEGIN("BullBearVolume");
  
C1 = Ref(C, -1);
uc = C > C1; dc = C <= C1;
ud = C > O; dd = C <= O;
  
green = 1; blue = 2; yellow = 3; red = 4; white = 5;
 
VType = IIf(ud,            
            IIf(uc, green, yellow),
         IIf(dd,
            IIf(dc, red, blue), white));
  
  
gv = IIf(VType == green, V, 0);
yv = IIf(VType == yellow, V, 0);
rv = IIf(VType == red, V, 0);
bv = IIf(VType == blue, V, 0);
  
uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */
dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */
  
/* create moving average period parameters */
VolPer = Param("Adjust Vol. MA per.", 21, 1, 255, 1);
ConvPer = Param("Adjust Conv. MA per.", 7, 1, 255, 1);
  
/* create triple exponential moving avearges of separate up and down volume moving averages */
MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
MAtv = TEMA(V, VolPer );//total volume
  
/* Switch for Horizontal lines indicating current level of positive and negative volume
    for ease in comparing to past highs/lows - toggle via parmameter window */
OscillatorOnly = Param("ShowOscillatorOnly", 0, 0, 1, 1);
CompareBullVolume = Param("ShowBullLevel", 1, 0, 1, 1);
if(CompareBullvolume AND !OscillatorOnly){
//Plot(SelectedValue(MAuv), "", colorGreen, styleLine);
}
  
CompareBearVolume = Param("ShowBearLevel", 1, 0, 1, 1);
if(CompareBearVolume AND !OscillatorOnly){
//Plot(SelectedValue(MAdv), "", colorRed, styleLine);
}
  
/* Volume Segment Switches - toggle via parameter window */
bullvolume = Param("ShowBullVolume", 1, 0, 1, 1);
bearvolume = Param("ShowBearVolume", 1, 0, 1, 1);
totalvolume = Param("ShowTEMA(TotalVolume)", 1, 0, 1, 1);
  
/* plot volume lines and histograms if toggled on: */
bearToFront = Param("ShowBearVolinFront", 0, 0, 1, 1);
if(bearToFront AND !OscillatorOnly){
//Plot(MAdv, "", colorRed, styleNoLabel);
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "AverageBullVolume", colorGreen, styleThick+styleNoLabel);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "AverageBearVolume", colorRed, styleThick+styleNoLabel);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "", colorOrange, styleNoLabel);
//PlotOHLC( 0 , MAdv , 0 , MAdv , "", colorOrange, styleCloud | styleNoRescale|styleNoLabel);
 
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "", colorLime, styleNoLabel);
//PlotOHLC( 0 , MAuv , O ,MAuv , "", colorLime, styleCloud | styleNoRescale|styleNoLabel);
 
}
if(totalVolume AND !OscillatorOnly){
//Plot(MAtv, "TEMA(TotalVolume)", colorLightBlue );
//PlotOHLC( 0 , MAtv , 0 , MAtv , "", colorLightBlue, styleCloud | styleNoRescale|styleNoLabel);
  
}
 
/*
Buy=Cross(MAuv,MAdv);
Sell=Cross(MAdv,MAuv);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBlue);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
Filter=Buy OR Sell;
Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy);
*/
 
//AddColumn(Close,"Close");AddColumn(Volume,"Total Volume");AddColumn(Buy,"Buy"); AddColumn(Sell,"sell");
  
/* better visibility of zero line: */
//Plot(0, "", colorViolet, 1);
  
/* Rise/Fall Convergence variables:  */
Converge = (TEMA(MAuv - MAdv, ConvPer));
Converge1 = Ref(Converge, -1);
ConvergeUp = Converge > Converge1;
ConvergeOver = Converge > 0;
rising = ConvergeUp AND ConvergeOver;
falling = !ConvergeUp AND ConvergeOver;
  
/* Rise/Fall Convergence Oscillator Switch  - toggle via parameter window - (provides a better view
      of resulting combination of battling bull/bear volume forces) */
convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
if(convergenceOscillator OR OscillatorOnly){
//Plot(Converge, "AmimalsWar", colorBrown, 1|styleLeftAxisScale|styleNoLabel|styleThick);
//Plot(0,"", colorViolet, 1|styleLeftAxisScale|styleNoLabel);
}
  
/********************************************************
 Convergence Rise/Fall Shadows:
  
 (provides a more easily visible display of rising and falling  bull/bear volume convergence) - toggle via parameter window
  
-posiitive Volume exceeding negative Volume: Light shadow
-negative volume exceeding positive volume: dark shadow
-if you use standard gray background - best shadows are:
-my greys: 14 = (216, 216, 216); 15 = (168, 168, 168));
-best substitute? using AB color constants?
-light: colorpalegreen; dark: colorRose;?
-(depends on your color scheme - customize to your tastes)
**********************************************************/
  
/* uncomment if you use my custom color greys: */
riseFallColor = IIf(rising, colorLime,colorOrange); //my custom shadow greys
  
/* comment out if you use my custom color gray shadows: */
/* riseFallColor = IIf(rising, colorPaleGreen,colorRose); */
  
/* Rise/Fall Convergence Plot Switch - toggle via parameter window */
riseFallShadows = Param("ShowRiseFallShadows", 0, 0, 1, 1);
if(riseFallShadows){
//Plot(IIf(rising OR falling, 1, 0), "", riseFallColor, styleArea|styleOwnScale|styleNoLabel);
}
GraphXSpace = 0.5;
_SECTION_END();
 
/*
_SECTION_BEGIN("Background");
    SetChartBkColor(ParamColor("Outer panel",colorBlack)); // color of outer border
    SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
    tchoice=Param("Title Selection ",2,1,2,1);
_SECTION_END();
*/
 
BullV= MAuv>MAdv ;
UpV= ( MAuv>MAdv AND MFI()>MA(MFI(),7) ) ;
UporV= ( MAuv>MAdv OR MFI()>MA(MFI(),7) ) ;
DnV= ( MAuv<MAdv AND MFI()<MA(MFI(),7) ) ;
DnorV= ( MAuv<MAdv OR MFI()<MA(MFI(),7) ) ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//CLEAR METHOD
 
//LISTING 1
 
upsw = 0;
Hh = Lh = H[ 0 ];
Hl = Ll = L[ 0 ];
 
for( i = 0; i < BarCount; i++ )
{
  Ch = H[ i ];
  Cl = L[ i ];
 
  if( upsw == 1 )
  {
    Hh = Max( Ch, Hh );
    hL = Max( Cl, Hl );
      
    if( Ch < Hl )
    {
      upsw = 0;
      Ll = Cl;
      Lh = Ch;
    }
  }
    
  if( upsw == 0 )
  {
    Ll = Min( Cl, Ll );
    Lh = Min( Ch, Lh );
 
    if( Cl > Lh )
    {
      upsw = 1;
      Hh = Ch;
      Hl = Cl;
    }
  }
 
  Hla[ i ] = Hl;
  Lha[ i ] = Lh;
  upswa[ i ] = upsw;
}
    
//Plot( IIf( upswa == 1, Hla, Null ), "SwLine", ColorRGB( 64, 128, 128), styleThick );
//Plot( IIf( upswa == 0, Lha, Null ), "SwLine", ColorRGB( 128, 64, 128), styleThick  );
//Plot( IIf( upswa == 1, Hla, Null ), "\nSwLine", colorBlue  , styleDots );
//Plot( IIf( upswa == 0, Lha, Null ), "\nSwLine", colorRed , styleDots );
 
 
//Plot( C, "Price", IIf( upswa == 1,
//      ColorBlend( colorGreen, colorWhite ),
//      ColorBlend( colorRed, colorWhite )), styleBar+styleThick );
//Plot( C, "Price", IIf( upswa == 1,
//      ColorBlend( colorLime , colorWhite ),
//      ColorBlend( colorRed, colorWhite )), styleBar+styleThick ); 
 
CpClear= upswa == 1 ;
VdClear= upswa == 0 ;
 
//Buy= Cross(upswa ,0) ;
//Sell= Cross(1,upswa) ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//FORMULE RIBBON TREND MOMENTUM VOLUME
 
Stochup= StochK()>StochD() ;
macdup= MACD()>Signal() ;
macdup0= MACD()>0 ;
Hist= MACD()-Signal() ;
Histup= Hist>Ref(Hist,-1) ;
pdiupmdi= PDI()>MDI() ;
uptrend= ( MACD()>Signal() AND PDI()>MDI() ) ;
dntrend= ( MACD()<Signal() AND PDI()<MDI() ) ;
rsiupma7= RSI()>MA(RSI(),7) ;
CCIUP0= CCI()>0 ;
MFIUPMA7= MFI()>MA(MFI(),7) ;
myup= (pdiupmdi AND macdup0 AND cciup0 AND histup AND stochup AND upswa == 1 ) ;
 
 
//YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
 
//RIBBONS TREND MOMENTUM VOLUME
 
//R8=========================== TREND ===============================================================
 
r1 = IIf( uptrend ,colorGreen ,
     IIf( dntrend , colorRed,colorTan ) ) ;
//---------------------------------------------------------------------------------------------------
 
//R1============================= MOMENTUM ====================================================
 
r2 = IIf( rsiupma7 AND cciup0,colorGreen ,
     IIf( !rsiupma7 AND !cciup0, colorRed,colorTan ) ) ; 
 
//-----------------------------------------------------------------------------------------------
 
//R1============================== VOLUME ====================================================
 
r3 = IIf( mfiupma7 AND bullv,colorGreen ,
     IIf( !mfiupma7 AND !bullv, colorRed,colorTan ) ) ;     
 
//-------------------------------------------------------------------------------------------
//YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
 
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
MultiRibbon( r3,   1, "VOLUME");
MultiRibbon( r2,   2, "MOMENTUM");
MultiRibbon( r1,   3, "TREND");
 
// RIBBON TMV END RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
 
//VSTOP 2
 
_SECTION_BEGIN("Volatility 2");
// Just Re-share
// E.M.Pottasch, Jul 2010
// from Metastock formula, link: http://stocata.org/metastock/stop_trail_atr.html
// added separate parameters for upward and downward market environment
 
function vstop_func(trBull,trBear)
{
    trailArray[ 0 ] = C[ 0 ]; // initialize
    for( i = 1; i < BarCount; i++ )
    {
        prev = trailArray[ i - 1 ];
  
        if (C[ i ] > prev AND C[ i - 1 ] > prev)
        {
            trailArray[ i ] = Max(prev,C[ i ] - trBull[ i ]);
        }
        else if (C[ i ] < prev AND C[ i - 1 ] < prev)
        {
            trailArray[ i ] = Min(prev,C[ i ] + trBear[ i ]);
        }
        else if (C[ i ] > prev)
        {
            trailArray[ i ] = C[ i ] - trBull[ i ];
        }
        else
        {
            trailArray[ i ] = C[ i ] + trBear[ i ];
        }
    }
    return trailArray;
}
 
//trailLong= Support= SellStop ;
//trailShort= Resistance= BuyStop ;
 
//per = Param("per",20, 1, 150, 1);
//multBull = Param("multBull",2, 1, 4, 0.05);
//multBear = Param("multBear",2, 1, 4, 0.05);
per = Param("ATRper",14, 1, 150, 1);
multBear = Param("kRes",1.7, 0, 4, 0.05);
multBull = Param("kSup",1.7, 0, 4, 0.05);
 
trBull = multBull * ATR(per);
trBear = multBear * ATR(per);
 
trailArray = vstop_func(trBull,trBear);
 
//SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
//SetChartOptions(0, chartShowDates);
//Plot(IIf(trailArray > C,trailArray,Null),"\ntrailShort",ParamColor("ColorTrailShort",ColorRGB(255,0,0)),styleStaircase);
//Plot(IIf(trailArray < C,trailArray,Null),"\ntrailLong",ParamColor("ColorTrailLong",ColorRGB(0,255,0)),styleStaircase);
//Plot(IIf(trailArray > C,trailArray,Null),"\nBuyStop",colorRed,styleStaircase+styleThick);
//Plot(IIf(trailArray < C,trailArray,Null),"\nSellStop",colorBlue,styleStaircase+styleThick);
trailARRAYcolor= IIf(C>trailARRAY,colorBlue,colorRed) ;
//Plot(trailArray,"\nVSTOP",trailARRAYcolor,styleLine+styleThick) ;
//Plot(trailArray,"\nVSTOP",trailARRAYcolor,8+16) ;
//Plot(trailArray,"\nVSTOP",trailARRAYcolor,styledots) ;
//Plot( C, "\nCandle",colorWhite, styleCandle );
BuystopNew= C>trailARRAY ;
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//TRAILING STOP LOSS WITH HIGH AND LOW
/*
// STAMP CODE NAME
GfxSelectFont("Tahoma", 15, 700 );
GfxSetBkColor( colorGreen );
GfxSetTextColor(colorBlack);
GfxTextOut("High Low Trailing Stop",Status("pxwidth")/1.25,Status("pxheight")/50);
GraphXSpace=5; */
 
//====== Original TT by X ========
//------ Setting -----------------
SetOption("InitialEquity",1000000);
SetTradeDelays( 0, 0, 0, 0 );
RoundLotSize = 100;
BuyPrice=Close;
SellPrice=Close;
SetOption("maxopenpositions",1);
PositionSize=-100;
 
PcntOffset = 0;
function Hstop_func()
{
    trailHL[ 0 ] = L[ 0 ]; // initialize
    for( i = 1; i < BarCount; i++ )
    {
        prev = trailHL[ i - 1 ];
  
        if (C[ i ] >= prev AND C[ i - 1 ] >= prev)// Long Side This Day and Previous Day > Trailing
        {
 
            if(H[i]>H[i-1])// Make New High
                trailHL[ i ] = (Max(prev,L[i-1]))*(1-PcntOffset/100);
            else // No New high
                trailHL[ i ] = prev;
        }
        else if (C[ i ] < prev AND C[ i - 1 ] < prev)// Short Side This Day and Previous Day < Trailing
        {
            if(L[i]<L[i-1])// Make New Low
                trailHL[ i ] = (Min(prev,H[i-1]))*(1+PcntOffset/100);
            else
                trailHL[ i ] = prev;
        }
        else if (C[ i ] < prev AND C[ i - 1 ] >= prev)// Short Point
        {
            trailHL[ i ] = (Max(H[i],H[i-1]))*(1+PcntOffset/100);//C[ i ] - trBull[ i ];           
            stoploss[i-1]=1;
        }
        else //Long Point
        {
            trailHL[ i ] = (L[i])*(1-PcntOffset/100);//C[ i ] + trBear[ i ];   
             
        }
    }
    return trailHL;
}
 
 
trailHL = Hstop_func();
//Plot( trailHL,"\nStopLossHL",IIf(C<trailHL,colorRed,colorBlue),styleLine+styleThick);
 
CpHL= C>trailHL ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//GRAPHIC MODIFIED BULL&BEAR VOLUME CHYNTHIA
 
_SECTION_BEGIN("BullBearVolume");
  
C1 = Ref(C, -1);
uc = C > C1; dc = C <= C1;
ud = C > O; dd = C <= O;
  
green = 1; blue = 2; yellow = 3; red = 4; white = 5;
 
VType = IIf(ud,            
            IIf(uc, green, yellow),
         IIf(dd,
            IIf(dc, red, blue), white));
  
  
gv = IIf(VType == green, V, 0);
yv = IIf(VType == yellow, V, 0);
rv = IIf(VType == red, V, 0);
bv = IIf(VType == blue, V, 0);
  
uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */
dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */
  
/* create moving average period parameters */
VolPer = Param("Adjust Vol. MA per.", 21, 1, 255, 1);
ConvPer = Param("Adjust Conv. MA per.", 7, 1, 255, 1);
  
/* create triple exponential moving avearges of separate up and down volume moving averages */
MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
MAtv = TEMA(V, VolPer );//total volume
  
/* Switch for Horizontal lines indicating current level of positive and negative volume
    for ease in comparing to past highs/lows - toggle via parmameter window */
OscillatorOnly = Param("ShowOscillatorOnly", 0, 0, 1, 1);
CompareBullVolume = Param("ShowBullLevel", 1, 0, 1, 1);
if(CompareBullvolume AND !OscillatorOnly){
//Plot(SelectedValue(MAuv), "", colorGreen, styleLine);
}
  
CompareBearVolume = Param("ShowBearLevel", 1, 0, 1, 1);
if(CompareBearVolume AND !OscillatorOnly){
//Plot(SelectedValue(MAdv), "", colorRed, styleLine);
}
  
/* Volume Segment Switches - toggle via parameter window */
bullvolume = Param("ShowBullVolume", 1, 0, 1, 1);
bearvolume = Param("ShowBearVolume", 1, 0, 1, 1);
totalvolume = Param("ShowTEMA(TotalVolume)", 1, 0, 1, 1);
  
/* plot volume lines and histograms if toggled on: */
bearToFront = Param("ShowBearVolinFront", 0, 0, 1, 1);
if(bearToFront AND !OscillatorOnly){
//Plot(MAdv, "", colorRed, styleNoLabel);
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "AverageBullVolume", colorGreen, styleThick+styleNoLabel);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "AverageBearVolume", colorRed, styleThick+styleNoLabel);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "", colorOrange, styleNoLabel);
//PlotOHLC( 0 , MAdv , 0 , MAdv , "", colorOrange, styleCloud | styleNoRescale|styleNoLabel);
 
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "", colorLime, styleNoLabel);
//PlotOHLC( 0 , MAuv , O ,MAuv , "", colorLime, styleCloud | styleNoRescale|styleNoLabel);
 
}
if(totalVolume AND !OscillatorOnly){
//Plot(MAtv, "TEMA(TotalVolume)", colorLightBlue );
//PlotOHLC( 0 , MAtv , 0 , MAtv , "", colorLightBlue, styleCloud | styleNoRescale|styleNoLabel);
  
}
 
/*
Buy=Cross(MAuv,MAdv);
Sell=Cross(MAdv,MAuv);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBlue);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
Filter=Buy OR Sell;
Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy);
*/
 
//AddColumn(Close,"Close");AddColumn(Volume,"Total Volume");AddColumn(Buy,"Buy"); AddColumn(Sell,"sell");
  
/* better visibility of zero line: */
//Plot(0, "", colorViolet, 1);
  
/* Rise/Fall Convergence variables:  */
Converge = (TEMA(MAuv - MAdv, ConvPer));
Converge1 = Ref(Converge, -1);
ConvergeUp = Converge > Converge1;
ConvergeOver = Converge > 0;
rising = ConvergeUp AND ConvergeOver;
falling = !ConvergeUp AND ConvergeOver;
  
/* Rise/Fall Convergence Oscillator Switch  - toggle via parameter window - (provides a better view
      of resulting combination of battling bull/bear volume forces) */
convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
if(convergenceOscillator OR OscillatorOnly){
//Plot(Converge, "AmimalsWar", colorBrown, 1|styleLeftAxisScale|styleNoLabel|styleThick);
//Plot(0,"", colorViolet, 1|styleLeftAxisScale|styleNoLabel);
}
  
/********************************************************
 Convergence Rise/Fall Shadows:
  
 (provides a more easily visible display of rising and falling  bull/bear volume convergence) - toggle via parameter window
  
-posiitive Volume exceeding negative Volume: Light shadow
-negative volume exceeding positive volume: dark shadow
-if you use standard gray background - best shadows are:
-my greys: 14 = (216, 216, 216); 15 = (168, 168, 168));
-best substitute? using AB color constants?
-light: colorpalegreen; dark: colorRose;?
-(depends on your color scheme - customize to your tastes)
**********************************************************/
  
/* uncomment if you use my custom color greys: */
riseFallColor = IIf(rising, colorLime,colorOrange); //my custom shadow greys
  
/* comment out if you use my custom color gray shadows: */
/* riseFallColor = IIf(rising, colorPaleGreen,colorRose); */
  
/* Rise/Fall Convergence Plot Switch - toggle via parameter window */
riseFallShadows = Param("ShowRiseFallShadows", 0, 0, 1, 1);
if(riseFallShadows){
//Plot(IIf(rising OR falling, 1, 0), "", riseFallColor, styleArea|styleOwnScale|styleNoLabel);
}
GraphXSpace = 0.5;
_SECTION_END();
 
/*
_SECTION_BEGIN("Background");
    SetChartBkColor(ParamColor("Outer panel",colorBlack)); // color of outer border
    SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
    tchoice=Param("Title Selection ",2,1,2,1);
_SECTION_END();
*/
 
BullV= MAuv>MAdv ;
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//AROON OSCILLATOR
/*
Description:
 
Aroon is Sanskrit word meaning "dawn's early light" or the change from night to day.
The Aroon indicator allows you to anticipate changes in security prices from trending to trading range.
The indicator uses two lines: Aroon Up and Aroon Down. Aroon Down is a measure of
how close the current bar is to the most recent lowest Low bar found in the last N bars.
Aroon Up is a measure of how close the current bar is to the most recent highest High bar found in the last N bars.
Additionally Aroon oscillator can be defined as the difference between the Aroon Up and Aroon Down indicators.
For more information on the Aroon indicator see the article written by Tushar Chande
in the September 1995 issue of Technical Analysis of Stocks & Commodities magazine.
 
Aroon indicator ranges from 0 to 100 and it is drawn with additional 30/70 levels.
The default period is 14 days. The indicator works as follows: if a security makes a new 14-day high,
the Aroon Up = 100; when the security makes a new 14-day low, the Aroon Down = 100;
when there was no new high in 14 days, the Aroon Up = 0; and consequently when there was no new low for 14 days, the Aroon Down = 0.
Aroon indicator is an another way (in addition to VHF and ADX indicators) of detemining if market is trending or not.
 
"The Aroon Oscillator indicates an upward trend when it is above zero and a downward trend when it is below zero.";
"The farther away the oscillator is from the zero line, the stronger the trend.";
 
The Aroon indicator allows you to anticipate changes in security prices from trending to trading range.
The indicator uses two lines: Aroon Up AND Aroon Down. Aroon Down is a measure of how Close the current bar is
to the most recent Lowest Low bar found in the last N bars. Aroon Up is a measure of how Close the current bar is
to the most recent Highest High bar found in the last N bars. Additionally Aroon oscillator can be defined as
the difference between the Aroon Up AND Aroon Down indicators.
Aroon indicator ranges from 0 to 100 AND it is drawn with additional 30/70 levels.
The default period is 14 days. The indicator works as follows: if a security makes a new 14-Day High,
the Aroon Up = 100; when the security makes a new 14-Day Low, the Aroon Down = 100;
when there was no new High in 14 days, the Aroon Up = 0; AND consequently
when there was no new Low for 14 days, the Aroon Down = 0.
Aroon indicator is an another way (in addition to VHF AND ADX indicators) of detemining if market is trending OR NOT.
*/
 
AroonPer = Param("AroonPer",14,4,45,1);
 
AroonUp = 100 * (AroonPer - (HHVBars(H, AroonPer + 1))) / AroonPer;
AroonDn = 100 * (AroonPer - (LLVBars(L, AroonPer + 1))) / AroonPer;
AroonOsc = AroonUp - AroonDn;
 
//pdimdicol= IIf(pdimdi>0 AND pdimdi>Ref(pdimdi,-1),colorGreen,
//           IIf(pdimdi<0 AND pdimdi<Ref(pdimdi,-1),colorRed,colorTan ) ) ;
 
Arooncol= IIf(aroonosc>0 AND aroonosc>Ref(aroonosc,-1) OR aroonosc>=50,colorGreen,
          IIf(aroonosc<0 AND aroonosc<Ref(aroonosc,-1),colorRed,colorTan ) ) ;
 
//Plot(AroonOsc, "Aroon Oscillator("+AroonPer+")", IIf(AroonOsc > 0,colorLime,colorRed), styleHistogram| styleThick);
//Plot(AroonOsc, "Aroon Oscillator("+AroonPer+")", arooncol, styleDots );
//Plot(AroonOsc, "", arooncol, styleHistogram| styleThick);
//PlotGrid(-50, colorBrown);
//PlotGrid(50, colorBrown);
 
//Plot(-50,"", colorBlue ,styleLine );
//Plot(50, "",colorRed ,styleLine );
//Plot(0, "",colorBrown,styleLine );
 
AroonOscUp0= AroonOsc>0 ;
AroonOscUp50= AroonOsc>=50 ;
AroonOscUp= AroonOsc>Ref(AroonOsc,-1) ;
AroonOscUpUp= ( AroonOsc>0 AND AroonOsc>=Ref(AroonOsc,-1) ) ;
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//CLEAR METHOD
 
//LISTING 1
 
upsw = 0;
Hh = Lh = H[ 0 ];
Hl = Ll = L[ 0 ];
 
for( i = 0; i < BarCount; i++ )
{
  Ch = H[ i ];
  Cl = L[ i ];
 
  if( upsw == 1 )
  {
    Hh = Max( Ch, Hh );
    hL = Max( Cl, Hl );
      
    if( Ch < Hl )
    {
      upsw = 0;
      Ll = Cl;
      Lh = Ch;
    }
  }
    
  if( upsw == 0 )
  {
    Ll = Min( Cl, Ll );
    Lh = Min( Ch, Lh );
 
    if( Cl > Lh )
    {
      upsw = 1;
      Hh = Ch;
      Hl = Cl;
    }
  }
 
  Hla[ i ] = Hl;
  Lha[ i ] = Lh;
  upswa[ i ] = upsw;
}
    
//Plot( IIf( upswa == 1, Hla, Null ), "SwLine", ColorRGB( 64, 128, 128), styleThick );
//Plot( IIf( upswa == 0, Lha, Null ), "SwLine", ColorRGB( 128, 64, 128), styleThick  );
//Plot( IIf( upswa == 1, Hla, Null ), "\nSwLine", colorBlue  , styleDots );
//Plot( IIf( upswa == 0, Lha, Null ), "\nSwLine", colorRed , styleDots );
 
 
//Plot( C, "Price", IIf( upswa == 1,
//      ColorBlend( colorGreen, colorWhite ),
//      ColorBlend( colorRed, colorWhite )), styleBar+styleThick );
//Plot( C, "Price", IIf( upswa == 1,
//      ColorBlend( colorLime , colorWhite ),
//      ColorBlend( colorRed, colorWhite )), styleBar+styleThick ); 
 
CpClear= upswa == 1 ;
VdClear= upswa == 0 ;
 
//Buy= Cross(upswa ,0) ;
//Sell= Cross(1,upswa) ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//COUNTBACK LINE
 
//* Stephane Carrasset's Countback Line (CBL) popularized by Daryl Guppy
 
//Refer to amibroker posting 30th December 2004 */
 
//nR=2;
nR= Param("nR",2,1,20,1,0) ;
 
Cbl[nR]=Null;
 
bCBL=False;
 
for( i=nR; i < BarCount; i++)
 
{
 
if( (Low[i-2]<Low[i-1]) && (Low[i-1]<Low[i]) )
 
{
 
Cbl[i] = Low[i-2];
 
bCBL = True;
 
}
 
else if (bCBL)
 
{
 
if (Low[i] < Cbl[i-1])
 
{
 
Cbl[i] = Cbl[i-1];
 
bCBL = False;
 
}
 
else
 
{
 
n = nR;
 
minval[i] = Low[i];
 
breakloop= False;
 
for (j = 1; NOT(breakloop) && j <= i; j++)
 
{
 
if (Low[i-j] < minval[i])
 
{
 
if (n>1)
 
{
 
minval[i] = Low[i-j];
 
n--;
 
}
 
else
 
{
 
Cbl[i] = Low[i-j];
 
breakloop=True;
 
}
 
}
 
}
 
if (Cbl[i] < Cbl[i-1])
 
Cbl[i] = Cbl[i-1];
 
}
 
}
 
else
 
{
 
Cbl[i] = Cbl[i-1];
 
}
 
if (Cbl[i]==0)
 
Cbl[i] = Cbl[i-1];
 
}
 
CBLcol= IIf(C>CBL,colorBlue,colorRed) ;
//Plot(Cbl,"\nCBL",colorRed,styleLine+styleThick);
//Plot(Cbl,"\nCBL",CBLcol,styleLine+styleThick);
 
//Plot(C,"",-1,64);
 
_SECTION_END();
 
CpCBL= C>CBL ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//TREND ADVISOR
 
pointer[0] = 0;
 
/* Phase filter */
 
/*
Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200)) ;
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200) ;
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
*/
 
Cond1 = C>=MA(C,50) AND C<MA(C,200) AND MA(C,50)<MA(C,200);
Cond2 = C>=MA(C,50) AND C>=MA(C,200) AND MA(C,50)<MA(C,200) ;
Cond3 = C>=MA(C,50) AND C>=MA(C,200) AND MA(C,50)>=MA(C,200) ;
Cond4 = C<MA(C,50) AND C>=MA(C,200) AND MA(C,50)>=MA(C,200);
Cond5 = C<MA(C,50) AND C<MA(C,200) AND MA(C,50)>=MA(C,200);
Cond6 = C<MA(C,50) AND C<MA(C,200) AND MA(C,50)<MA(C,200);
 
 
for (i = 1; i < BarCount; i++)
{
 
  if (Cond1[i])
    pointer[i] = 1;
  if (Cond2[i])
    pointer[i] = 2;
  if (Cond3[i])
    pointer[i] = 3;
  if (Cond4[i])
    pointer[i] = 4;
  if (Cond5[i])
    pointer[i] = 5;
  if (Cond6[i])
    pointer[i] = 6;
 
}
 
/* Plot Graphic */
GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdvisor", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));
 
Cond = pointer<4 ;
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//FORMULE
stochup=  StochK()>StochD()  ;
stochupmy= ( StochK()>StochD() OR StochK()>80) ;
stochdn80= StochK()<80 ;
stochup19= StochK()>19 ;
MACDup= MACD()>Signal() ;
MACDup0= MACD()>0 ;
Hist= MACD()-Signal() ;
Histup= Hist>Ref(Hist,-1) ;
MFIupma7= MFI()>MA(MFI(),7) ;
MFIdn80= MFI()<80 ;
MFIup50= MFI()>50 ;
MFIup30= MFI()>30 ;
Cupo= C>O ;
CCIup0= CCI()>0 ;
CCIupMA7= CCI()>MA(CCI(),7) ;
MA20up= MA(C,20)>=Ref(MA(C,20),-1) ;
MA10upMA15= MA(C,10)>MA(C,15) ;
MA5upma10= MA(C,5)>MA(C,10) ;
EMA50up= (EMA(C,50)>=Ref(EMA(C,50),-1) OR C>=EMA(C,50)) ;
Cupma20= C>MA(C,20) ;
Cupma50= C>MA(C,50) ;
PDIupmdi= PDI()>MDI() ;
PDIup20= PDI()>20 ;
PDIup18= PDI()>18 ;
Uptrend=  (MACD()>Signal() AND PDI()>MDI())   ;
Dntrend=  (MACD()<Signal() AND PDI()<MDI())   ;
ADX50= ADX()<50 ;
ADXup18= ADX()>18 ;
ADXupup= (ADX()>18 AND ADX()>Ref(ADX(),-1) OR ADX()>20 ) ;
HAup= haClose>=haOpen ;
CupSAR= C>SAR(0.02,0.2) ;
RSIup50= RSI()>50 ;
RSIupMA7= RSI()>MA(RSI(),7) ;
UpV= (MAuv>MAdv AND MFI()>MA(MFI(),7)) ;
DnV=  (MAuv<MAdv AND MFI()<MA(MFI(),7))   ;
UpORV= (MAuv>MAdv OR MFI()>MA(MFI(),7))  ;
CupSAR= C>SAR() ;
LimADX= ADX()<49 AND ADX()>18 ;
Cuptop1= C>BBandTop( C,20,1 ) ;
MyUp= ( macdup0 AND pdiupmdi AND histup AND stochup AND cciup0 AND upv ) ;
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//PARAMTOGGLE
 
// This combines indicators into one timing Signal
//function ParamOptimize( description, default, minv, maxv, step )
//    { return Optimize(description, Param(description,default, minv, maxv, step ), minv, maxv, step ); }
tgl = ParamToggle("Result", "AND logic|Compare");
// switch test calculation and compare the results
if(tgl)
{
myBuy =   issqueeze AND haup AND ( ( macdup AND rsiupma7 ) OR myup ) ;
myShort = !buystopnew AND !cuptop1 AND !haup OR
          !macdup AND !cuptop1 AND !haup OR
          DNTREND AND DNV ;
}
else
{
myBuy   = IIf( ( bbupper<=kupper AND bblower>=klower ) AND haClose>=haOpen AND ( ( MACD()>Signal() AND RSI()>MA(RSI(),7) ) OR
                        ( macdup0 AND pdiupmdi AND histup AND stochup AND cciup0 AND upv ) )    ,1,0);
myShort = IIf( C<trailARRAY AND C<BBandTop( C,20,1 ) AND haClose<haOpen OR
               MACD()<Signal() AND C<BBandTop( C,20,1 ) AND haClose<haOpen OR
               (MACD()<Signal() AND PDI()<MDI()) AND (MAuv<MAdv AND MFI()<MA(MFI(),7))   ,1,0);
}
 
//Buy = ExRem(myBuy, myShort) ;
//Sell = ExRem(myShort, myBuy) ;
 
Buy= Cross(mybuy,myshort) ;
Sell= Cross(myshort,mybuy) ;
 
StrongBuy =  Buy AND Cross(MACD(),Signal()) OR
             Buy AND Cross(RSI(),MA(RSI(),7)) OR
             Buy AND Cross( C,trailARRAY ) OR
             Buy AND Cross(PDI(),MDI()) OR
             Buy AND Cross(StochK(),StochD()) AND Stochdn80 OR
             Buy AND Cross(C,CenterLine) ;
MediumBuy = Buy AND uporv ;
WeakBuy = Buy ;
 
StrongSell = Sell AND Cross(BBandTop( C,20,1 ),C ) OR
             Sell AND Cross(Signal(),MACD()) OR
             Sell AND Cross(80,StochK() ) OR
             Sell AND Cross(trailARRAY,C ) OR
             Sell AND Cross(CenterLine,C) ;
MediumSell = Sell AND !stochup AND stochdn80 AND !haup ;
WeakSell = Sell ;
 
 
/*
PlotShapes(IIf(StrongBuy,shapeUpTriangle,shapeNone),colorBlue,0,Low,Offset=-20);
PlotShapes(IIf(MediumBuy,shapeUpArrow,shapeNone),colorBlue,0,Low,Offset=-20);
PlotShapes(IIf(WeakBuy,shapeHollowUpArrow,shapeNone),colorBlue,0,Low,Offset=-20);
PlotShapes(IIf(StrongSell,shapeDownTriangle,shapeNone),colorRed,0,High,Offset=-20);
PlotShapes(IIf(MediumSell,shapeDownArrow,shapeNone),colorRed,0,High,Offset=-20);
PlotShapes(IIf(WeakSell,shapeHollowDownArrow,shapeNone),colorRed,0,High,Offset=-20);
*/
 
PlotShapes(IIf(StrongBuy,shapeUpTriangle,shapeNone),colorBlue,0,haLow,Offset=-10);
PlotShapes(IIf(MediumBuy,shapeUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10);
PlotShapes(IIf(WeakBuy,shapeHollowUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10);
PlotShapes(IIf(StrongSell,shapeDownTriangle,shapeNone),colorRed,0,haHigh,Offset=-10);
PlotShapes(IIf(MediumSell,shapeDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10);
PlotShapes(IIf(WeakSell,shapeHollowDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10);
 
//PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10);
//PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10);
 
//PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,trailArray);
//PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,trailArray);
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2 comments

1. morgen

I think, this is a more reliable calculation for BBSqueeze, without Keltner Bands, for a certain specific evolution of a stock volatility :

//======================================================

//BBSQUEEZE = BANDWIDTH <= BANDWIDTHMA

bandwidth= ( ( bbtop-bbbot ) / bbmid ) * 100 ;
//Plot(bandwidth,"\nBBBandWidth %", colorRed,styleLine+styleThick) ;
bandwidthmaper= Param("BandWidthMAper",200,3,300,1,0) ;
bandwidthma= MA(bandwidth,bandwidthmaper) ;
//Plot(bandwidthma,"\nBandWidthMA",colorBlue,styleLine+styleThick) ;

IsSqueeze= bandwidth<=bandwidthma ;
IsSqCol= IIf(bandwidth<=bandwidthma, colorAqua,colorPink) ;
PlotOHLC(bbtop,bbtop,bbbot,bbbot,"\nBandWidth<=BandWidthMA",issqcol,styleCloud) ;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2. still_learning

This line: bandwidthma= MA ;
can’t be correct as written? i.e. MA (of what)?
Perhaps, it should be: bandwidthma= MA (bandwidth, bandwidthmaper); ???

Leave Comment

Please login here to leave a comment.

Back