-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathNebula v2.0.txt
1344 lines (1043 loc) · 59.5 KB
/
Nebula v2.0.txt
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
//@version=5
indicator(title="Nebula", shorttitle="Nebula v2.0", overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500, max_boxes_count=500)
const int vSqueeze = 4
const int vTramp = 4
const int vBands = 2
const int vRSI = 2
const int vLuxRev = 3
const int vEarlyRev = 2
const int vDeadRev = 2
const int vShark = 2
I_Like_Big_Butts_And_I_Cannot_Lie = input.bool(false, title="NOTE: Uncheck body/wick/border in your Settings for this indicator to display properly")
cloudType = input.string(title="Cloud Type: ", options=["None", "Simple", "Relative Strength", "Money Flow", "Commodity Channel"], defval="Relative Strength", group="Visible Settings")
sCandleType = input.string(title="Candle Coloring: ", options=["None", "Vector", "Waddah", "Squeeze", "Volume Delta"], defval="Waddah", group="Visible Settings")
Theme = input.string(title="Color Theme: ", options=["Standard", "Pinky and the Brain", "Color Blind", "Eye Popper"], defval="Standard", group="Visible Settings")
bShowHEMA = input.bool(false, "Show HEMA line", group="Visible Settings")
bShowPlus = input.bool(false, "Show plus sign to add", group="Visible Settings")
bShowBigPlus = input.bool(true, "Show bigger plus sign (Vodka Shot)", group="Visible Settings")
bEnhance1 = input.bool(true, "Enhance #1 if Buy/Sell signal nearby", group="Visible Settings")
bShowProfit = input.bool(true, "Show take profit suggestions", group="Visible Settings")
bShow921 = input.bool(false, "Show 9/21 EMA cross", group="Visible Settings")
bIgnoreDoji = input.bool(false, "Ignore dojis (only use on NQ, 1 min)", group="Basic Settings")
bNoCounterTrend = input.bool(false, "Don't show counter trend trades (only use on NQ, 1 min)", group="Basic Settings")
iProfit = input.int(5, "Minimum signals for take partial profit", minval=2, maxval=50, group="Basic Settings")
iMaxProfit = input.int(7, "Minimum signals for take ALL profit", minval=3, maxval=50, group="Basic Settings")
iMaxBody = input.int(1, "Body size to consider a doji", minval=1, maxval=4, group="Basic Settings")
//cfgBrightness = input.int(25, "Candle brightness for a blank candle", minval=1, maxval=100, group="Basic Settings")
//cfgBrightCloud = input.int(60, "Candle brightness for opposite cloud color signal", minval=1, maxval=100,group="Basic Settings")
//iMinCloud = input.int(2, "Minimum cloud width to signal in", minval=2, maxval=30, group="Basic Settings")
//sTidalWave = input.string(title="Tidal Wave Alerts: ", options=["None", "First Candle", "First Colored Candle", "First Value Candle"], defval="First Colored Candle", group="Tidal Wave Settings", tooltip="First Candle = first sign of a trend candle, Colored Candle = first trend candle that's the same color as Nebula candle")
//STPercent = input.int(44, "Candle brightness for [First Value Candle] option (1 to 99)", group="Tidal Wave Settings")
adxSqueeze = input.int(0, title="ADX Threshold for Tidal Wave", group="Tidal Wave Settings", tooltip="Anything over 19 filters out low volume periods. Set to 11 as a default, feel free to increase to get less noise")
bTrackBar = input.bool(false, "Show volume imbalances", group="Tidal Wave Settings")
iBarExtend = input.int(50, "Number of bars to extend line", maxval=500, minval=10, group="Tidal Wave Settings")
lWidth = input.int(3, "Line Width", group="Tidal Wave Settings")
lStyle = input.string(title="Line Style", options=["Solid", "Dotted", "Dashed"], defval="Dotted", group="Tidal Wave Settings")
sStyle = lStyle=="Solid" ? line.style_solid : lStyle=="Dashed" ? line.style_dashed : line.style_dotted
bExtend = lWidth==500 ? extend.right : extend.none
iLowCloud = input.int(80, title="Cloud Opacity Lower Limit (0=brightest, 100=invisible)", group="Advanced")
iHighCloud = input.int(50, title="Cloud Opacity Upper Limit (0=brightest, 100=invisible)", group="Advanced")
iTopBody = input.int(80, title="Top WAE Body Value", group="Advanced")
iTopBorder = input.int(33, title="Top WAE Border Value", group="Advanced")
iVolDeltaTop = input.int(300, title="Cumulative Volume Delta top end", group="Advanced")
ADX_Length = input.int(2, title="ADX_Length", group="Fantail VMA")
Weighting = input.float(10.0, title="Weighting", group="Fantail VMA")
MA_Length = input.int(6, minval=1, title="MA_Length", group="Fantail VMA")
colorBigGreen = Theme == "Standard" ? color.new(#00ff00, 0) : Theme == "Pinky and the Brain" ? color.new(#00f5f1, 0) : Theme == "Color Blind" ? color.new(#03fcf4, 0) : Theme == "Eye Popper" ? color.new(#00FF00, 0) : na
colorBigRed = Theme == "Standard" ? color.new(#ff0000, 0) : Theme == "Pinky and the Brain" ? color.new(#fc03f8, 0) : Theme == "Color Blind" ? color.new(#fca903, 0) : Theme == "Eye Popper" ? color.new(#FF0000, 0) : na
float iSource = 0.0
float MIN_CLOUD = 0.0
float MID_CLOUD = 0.0
float MAX_CLOUD = 0.0
var isLong78 = false
var isShort78 = false
iTPSignalCount = 0
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
adxlen = input(14, title="ADX Smoothing", group="ADX")
dilen = input(14, title="DI Length", group="ADX")
dirmov(len) =>
up5 = ta.change(high)
down5 = -ta.change(low)
plusDM = na(up5) ? na : (up5 > down5 and up5 > 0 ? up5 : 0)
minusDM = na(down5) ? na : (down5 > up5 and down5 > 0 ? down5 : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adxValue = adx(dilen, adxlen)
sigabove19 = adxValue > adxSqueeze
var arLabel = array.new_label(0)
f_AddChar(BarIndex, UpDown, Color, Char, Ticks, Size) =>
if (UpDown=="Up")
array.push(arLabel, label.new(x=bar_index, y=na, style=label.style_none, color=color.new(color.black, 100), textcolor=Color, text=Char, size=Size, yloc=yloc.belowbar))
else
array.push(arLabel, label.new(x=bar_index, y=na, style=label.style_none, color=color.new(color.black, 100), textcolor=Color, text=Char, size=Size, yloc=yloc.abovebar))
if array.size(arLabel) >= 498
ln = array.shift(arLabel)
label.delete(ln)
// =-=-=-=-=-=-=-=-=-=-=-=-= Cumulative Volume Delta © Ankit_1618 =-=-=-=-=-=-=-=-=-=-=-=-=-= //
upper_wick = close>open ? high-close : high-open
lower_wick = close>open ? open-low : close-low
spread = high-low
body_length = spread - (upper_wick + lower_wick)
percent_upper_wick = upper_wick/spread
percent_lower_wick = lower_wick/spread
percent_body_length = body_length/spread
buying_volume = close > open ? (percent_body_length + (percent_upper_wick + percent_lower_wick)/2)*volume : ((percent_upper_wick + percent_lower_wick)/2) * volume
selling_volume = close < open ? (percent_body_length + (percent_upper_wick + percent_lower_wick)/2)*volume : ((percent_upper_wick + percent_lower_wick)/2) * volume
cumulative_buying_volume = ta.ema(buying_volume,14)
cumulative_selling_volume = ta.ema(selling_volume,14)
cumulative_volume_delta = cumulative_buying_volume - cumulative_selling_volume
//plot(cumulative_volume_delta, color= cumulative_volume_delta>0 ? color.green : color.red, style=plot.style_columns, transp=61)
cCVDColor = color.white
cCVDBorder = color.white
cCVDWick = color.white
if cumulative_volume_delta > 0
cCVDColor := color.from_gradient(math.abs(cumulative_volume_delta), 0, iVolDeltaTop, color.new(colorBigGreen, 70), color.new(colorBigGreen, 0))
cCVDBorder := cCVDColor
cCVDWick := cCVDColor
else if cumulative_volume_delta < 0
cCVDColor := color.from_gradient(math.abs(cumulative_volume_delta), 0, iVolDeltaTop, color.new(colorBigRed, 70), color.new(colorBigRed, 0))
cCVDBorder := cCVDColor
cCVDWick := cCVDColor
plotcandle(sCandleType=="Volume Delta" ? open : na, high, low, close, color=cCVDColor, wickcolor=cCVDWick, bordercolor=cCVDBorder)
// =-=-=-=-=-=-=-=-=-=-=-=-= Dead Simple Reversal =-=-=-=-=-=-=-=-=-=-=-=-=-= //
c1 = close[1] < open[1] and close > open
c2 = close > open[1]
c3 = ta.lowest(low,3) < ta.lowest(low,50)[1] or ta.lowest(low,3) < ta.lowest(low,50)[2] or ta.lowest(low,3) < ta.lowest(low,50)[3]
buyDSR = c1 and c2 and c3
c4 = close[1] > open[1] and close < open
c5 = close < open[1]
c6 = ta.highest(high,3) > ta.highest(high,50)[1] or ta.highest(high,3) > ta.highest(high,50)[2] or ta.highest(high,3) > ta.highest(high,50)[3]
sellDSR = c4 and c5 and c6
if (buyDSR or sellDSR) or (buyDSR[1] or sellDSR[1])
iTPSignalCount := iTPSignalCount + vDeadRev
//plotshape(bDSR ? buyDSR : na, location=location.belowbar, style=shape.square, size=size.tiny)
//plotshape(bDSR ? sellDSR : na, location=location.abovebar, style=shape.square, size=size.tiny)
// =-=-=-=-=-=-=-=-=-=-=-=-= Reversal Signals [LuxAlgo] =-=-=-=-=-=-=-=-=-=-=-=-=-= //
bSh = 'Completed'
ptLT = 'Step Line w/ Diamonds'
ptSR = 'Circles'
eSh = 'Completed'
Bcmpltd = bSh == 'Completed'
var noShw = false
cmpltd = eSh == 'Completed'
noShw := eSh == 'None' ? false : true
type bar
float o = open
float h = high
float l = low
float c = close
int i = bar_index
type trb
int bSC
float bSH
float bSL
int sSC
float sSH
float sSL
type tre
int bCC
float bC8
float bCHt
float bCH
float bCL
float bCLt
float bCD
int sCC
float sC8
float sCHt
float sCH
float sCL
float sCLt
float sCT
bar b = bar.new()
var trb S = trb.new()
var tre C = tre.new()
noC = #00000000
rdC = #f23645
gnC = #089981
whC = #ffffff
blC = #2962ff
grC = #787b86
bgC = #00bcd4
shpD = shape.labeldown
shpU = shape.labelup
locA = location.abovebar
locB = location.belowbar
dspN = false
pltL = plot.style_circles
pltS = size.tiny
f_xLX(_p, _l) =>
(_l > _p and _l < _p[1]) or (_l < _p and _l > _p[1])
f_lnS(_s) =>
s = switch _s
'Circles' => plot.style_circles
'Step Line' => plot.style_steplinebr
'Step Line w/ Diamonds' => plot.style_steplinebr
ptLB = f_lnS(ptLT)
ptRS = f_lnS(ptSR)
con = b.c < b.c[4]
if con
S.bSC := S.bSC == 9 ? 1 : S.bSC + 1
S.sSC := 0
else
S.sSC := S.sSC == 9 ? 1 : S.sSC + 1
S.bSC := 0
pbS = (b.l <= b.l[3] and b.l <= b.l[2]) or (b.l[1] <= b.l[3] and b.l[1] <= b.l[2])
bShowUppies = ((S.bSC == 9 and not pbS) or (S.bSC == 9 and pbS) or (S.bSC[1] == 8 and S.sSC == 1)) and (barstate.isconfirmed)
//plotshape(bShowUppies ? 1 : na, title="Reversal Approaching", style=shape.xcross, location=location.belowbar, color=color.rgb(0, 255, 132), size=size.tiny)
bC8 = S.bSC[1] == 8 and S.sSC == 1
sR = ta.highest(9)
bSR = 0.0
bSR := S.bSC == 9 or bC8 ? sR : b.c > bSR[1] ? 0 : bSR[1]
if S.bSC == 1
S.bSL := b.l
if S.bSC > 0
S.bSL := math.min(b.l, S.bSL)
if b.l == S.bSL
S.bSH := b.h
bSD = 0.0
bSD := S.bSC == 9 ? 2 * S.bSL - S.bSH : b.c < bSD[1] or S.sSC == 9 ? 0 : bSD[1]
psS = (b.h >= b.h[3] and b.h >= b.h[2]) or (b.h[1] >= b.h[3] and b.h[1] >= b.h[2])
//if (S.sSC == 9 and not psS) or (S.sSC == 9 and psS) or (S.sSC[1] == 8 and S.bSC == 1) and BnoShw and barstate.isconfirmed
// f_AddCharStd(bar_index, "Down", colorBigRed, label.style_xcross, 2)
bShowDownies = ((S.sSC == 9 and not psS) or (S.sSC == 9 and psS) or (S.sSC[1] == 8 and S.bSC == 1)) and (barstate.isconfirmed)
//plotshape(bShowDownies ? 1 : na, title="Reversal Approaching", style=shape.xcross, location=location.abovebar, color=color.rgb(255, 0, 0), size=size.tiny)
if (bShowUppies or bShowDownies) or (bShowUppies[1] or bShowDownies[1])
iTPSignalCount := iTPSignalCount + vLuxRev
// =-=-=-=-=-=-=-=-=-=-=-=-= LuxAlgo - Market Structure (Fractal) =-=-=-=-=-=-=-=-=-=-=-=-=-= //
var float upOpen = na
var float upClose = na
var float downOpen = na
var float downClose = na
bGreenSignal = false
bRedSignal = false
length = 5 // default, min 3
type fractal
float value
int loc
bool iscrossed
var pT = int(length / 2)
n = bar_index
dhT = math.sum(math.sign(high - high[1]), pT)
dlT = math.sum(math.sign(low - low[1]), pT)
bullf = dhT == -pT and dhT[pT] == pT and high[pT] == ta.highest(length)
bearf = dlT == pT and dlT[pT] == -pT and low[pT] == ta.lowest(length)
bullf_count = ta.cum(bullf ? 1 : 0)
bearf_count = ta.cum(bearf ? 1 : 0)
var upperT = fractal.new()
var line lower_lvl = na
var label ms_lbl = na
var bull_ms_count = 0
var broken_sup = false
var os = 0
if bullf
upperT.value := high[pT]
upperT.loc := n-pT
upperT.iscrossed := false
if ta.crossover(close, upperT.value) and not upperT.iscrossed
upOpen := open
upClose := close
else if not broken_sup
lower_lvl.set_x2(n)
if close < lower_lvl.get_y2()
broken_sup := true
var lowerT = fractal.new()
var line upper_lvl = na
var broken_res = false
var bear_ms_count = 0
if bearf
lowerT.value := low[pT]
lowerT.loc := n-pT
lowerT.iscrossed := false
if ta.crossunder(close, lowerT.value) and not lowerT.iscrossed
downOpen := open
downClose := close
else if not broken_res
upper_lvl.set_x2(n)
if close > upper_lvl.get_y2()
broken_res := true
// ========================== MACD ================================
fast_ma = request.security(syminfo.tickerid, "", ta.ema(close, 12))
slow_ma = request.security(syminfo.tickerid, "", ta.ema(close, 26))
macd = fast_ma - slow_ma
signal = request.security(syminfo.tickerid, "", ta.ema(macd, 9))
float hist = macd - signal
trend_up = macd > signal
trend_dn = macd < signal
cross_UP = signal[1] >= macd[1] and signal < macd
cross_DN = signal[1] <= macd[1] and signal > macd
cross_UP_A = (signal[1] >= macd[1] and signal < macd) and macd > 0
cross_DN_B = (signal[1] <= macd[1] and signal > macd) and macd < 0
//trend_col = trend_up ? col_trnd_Up : trend_up ? col_macd : show_trend and trend_dn ? col_trnd_Dn: trend_dn ? col_macd : na
var bool histA_IsUp = false
var bool histA_IsDown = false
var bool histB_IsDown = false
var bool histB_IsUp = false
histA_IsUp := hist == hist[1] ? histA_IsUp[1] : hist > hist[1] and hist > 0
histA_IsDown := hist == hist[1] ? histA_IsDown[1] : hist < hist[1] and hist > 0
histB_IsDown := hist == hist[1] ? histB_IsDown[1] : hist < hist[1] and hist <= 0
histB_IsUp := hist == hist[1] ? histB_IsUp[1] : hist > hist[1] and hist <= 0
//hist_col = histA_IsUp ? col_grow_above : histA_IsDown ? col_fall_above : histB_IsDown ? col_grow_below : histB_IsUp ? col_fall_below :color.silver
cMDColor = color.white
cMDBorder = color.white
cMDWick = color.white
if histA_IsUp
cMDColor := color.from_gradient(math.abs(hist), 0, 3, color.new(colorBigGreen, 30), color.new(colorBigGreen, 0))
cMDBorder := colorBigGreen
cMDWick := cMDColor
else if histA_IsDown
cMDColor := color.from_gradient(math.abs(hist), 0, 3, color.new(colorBigGreen, 80), color.new(colorBigGreen, 30))
cMDBorder := colorBigGreen
cMDWick := cMDColor
if histB_IsUp
cMDColor := color.from_gradient(math.abs(hist), 0, 4, color.new(colorBigRed, 30), color.new(colorBigRed, 0))
cMDBorder := colorBigRed
cMDWick := cMDColor
else if histB_IsDown
cMDColor := color.from_gradient(math.abs(hist), 0, 4, color.new(colorBigRed, 80), color.new(colorBigRed, 30))
cMDBorder := colorBigRed
cMDWick := cMDColor
// plotcandle(sCandleType=="MACD" ? open : na, high, low, close, color=cMDColor, wickcolor=cMDWick, bordercolor=cMDBorder)
// ========================== Bixord: FantailVMA ================================
rsi = ta.rsi(close, 14)
mfi = ta.mfi(hlc3, 14)
maCCI = ta.sma(hlc3, 20)
cci = (hlc3 - maCCI) / (0.015 * ta.dev(hlc3, 20))
if cloudType=="Relative Strength"
iSource := rsi
MIN_CLOUD := 20
MID_CLOUD := 50
MAX_CLOUD := 80
if cloudType=="Money Flow"
iSource := mfi
MIN_CLOUD := 20
MID_CLOUD := 50
MAX_CLOUD := 80
if cloudType=="Commodity Channel"
iSource := cci
MIN_CLOUD := 20
MID_CLOUD := -100
MAX_CLOUD := 100
VMA=close
VarMA=close
MA=close
STR = high-low
sPDI = 0.0
sMDI = 0.0
ADX=0.0
ADXR=0.0
Hi = high
Hi1 = high[1]
Lo = low
Lo1 = low[1]
Close1= close[1]
Bulls1 = 0.5*(math.abs(Hi-Hi1)+(Hi-Hi1))
Bears1 = 0.5*(math.abs(Lo1-Lo)+(Lo1-Lo))
Bears = Bulls1 > Bears1 ? 0 : (Bulls1 == Bears1 ? 0 : Bears1)
Bulls = Bulls1 < Bears1 ? 0 : (Bulls1 == Bears1 ? 0 : Bulls1)
if (bar_index > 0)
sPDI := (Weighting*sPDI[1] + Bulls)/(Weighting+1)
sMDI := (Weighting*sMDI[1] + Bears)/(Weighting+1)
TR = math.max(Hi-Lo,Hi-Close1)
if (bar_index > 0)
STR := (Weighting*STR[1] + TR)/(Weighting+1)
PDI = STR > 0 ? sPDI/STR : 0
MDI = STR > 0 ? sMDI/STR: 0
DX = (PDI + MDI) > 0 ? math.abs(PDI - MDI)/(PDI + MDI) : 0
if (bar_index > 0)
ADX := (Weighting*ADX[1] + DX)/(Weighting+1)
vADX = ADX
adxlow = ta.lowest(ADX, ADX_Length)
adxmax = ta.highest(ADX, ADX_Length)
ADXmin = math.min(1000000.0, adxlow)
ADXmax = math.max(-1.0, adxmax)
Diff = ADXmax - ADXmin
Const = Diff > 0 ? (vADX- ADXmin)/Diff : 0
if (bar_index > 0)
VarMA:=((2-Const)*VarMA[1]+Const*close)/2
FanVMA = ta.sma(VarMA,MA_Length)
// ========================== McGinley Dynamic ================================
mg = 0.0
mg := na(mg[1]) ? ta.ema(close, 14) : mg[1] + (close - mg[1]) / (14 * math.pow(close/mg[1], 4))
bCloudGreen = FanVMA > mg
bCloudRed = not bCloudGreen
// ========================== Waddah Attar Explosion v1 by LazyBear ================================
sensitivity = input.int(150, title="Sensitivity", group="WAE")
fastLength = input.int(20, title="FastEMA Length", group="WAE")
slowLength = input.int(40, title="SlowEMA Length", group="WAE")
channelLength = input.int(20, title="BB Channel Length", group="WAE")
multWAE = input.float(2.0, title="BB Stdev Multiplier", group="WAE")
calc_macd(source, fastLength, slowLength) =>
fastMA = ta.ema(source, fastLength)
slowMA = ta.ema(source, slowLength)
fastMA - slowMA
calc_BBUpper(source, length, mult) =>
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
basis + dev
calc_BBLower(source, length, mult) =>
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
basis - dev
upper = calc_BBUpper(close, channelLength, multWAE)
lower = calc_BBLower(close, channelLength, multWAE)
t1 = (calc_macd(close, fastLength, slowLength) - calc_macd(close[1], fastLength, slowLength))*sensitivity
e1 = (upper - lower)
trendUpWAE = (t1 >= 0) ? t1 : 0
trendDownWAE = (t1 < 0) ? (-1*t1) : 0
iCandleTrans = trendUpWAE > 0 ? math.round(math.abs(trendUpWAE - e1)) : math.round(math.abs(trendDownWAE - e1))
cBodyColor = color.white
cBorderColor = color.white
cWickColor = color.white
if (trendUpWAE > e1 and trendUpWAE > 0)
cBodyColor := color.from_gradient(math.abs(trendUpWAE - e1), 1, iTopBody, color.new(colorBigGreen, 70), color.new(colorBigGreen, 0))
cBorderColor := color.from_gradient(math.abs(trendUpWAE - e1), 1, iTopBorder, color.new(colorBigGreen, 70), color.new(colorBigGreen, 0))
cWickColor := color.new(colorBigGreen, 0)
if (trendUpWAE < e1 and trendUpWAE > 0)
cBodyColor := color.new(colorBigGreen, 90)
cBorderColor := color.from_gradient(math.abs(e1 - trendUpWAE), 1, iTopBody, color.new(colorBigGreen, 70), color.new(colorBigGreen, 0))
cWickColor := color.new(colorBigGreen, 30)
if (trendDownWAE > e1 and trendDownWAE > 0)
cBodyColor := color.from_gradient(math.abs(trendDownWAE - e1), 1, iTopBody, color.new(colorBigRed, 50), color.new(colorBigRed, 0))
cBorderColor := color.from_gradient(math.abs(trendDownWAE - e1), 1, iTopBorder, color.new(colorBigRed, 50), color.new(colorBigRed, 0))
cWickColor := color.new(colorBigRed, 0)
if (trendDownWAE < e1 and trendDownWAE > 0)
cBodyColor := color.new(colorBigRed, 90)
cBorderColor := color.from_gradient(math.abs(e1 - trendDownWAE), 1, iTopBody, color.new(colorBigRed, 50), color.new(colorBigRed, 0))
cWickColor := color.new(colorBigRed, 30)
plotcandle(sCandleType=="Waddah" ? open : na, high, low, close, "", color=cBodyColor, wickcolor=cWickColor, bordercolor=cBorderColor)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= TRAMPOLINE =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
// Idea from "Serious Backtester" - https://www.youtube.com/watch?v=2hX7qTamOAQ
// Defaults are optimized for 30 min candles
iBBThreshold = input.float(0.0015, minval=0.0, title="Bollinger Lower Threshold", tooltip="0.003 for daily, 0.0015 for 30 min candles", group="TRAMPOLINE Settings")
RSIThreshold = input.int(25, minval=1, title="RSI Lower Threshold", tooltip="Normally 25", group="TRAMPOLINE Settings")
RSIDown = input.int(72, minval=1, title="RSI Upper Threshold", tooltip="Normally 75", group="TRAMPOLINE Settings")
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="TRAMPOLINE Settings")
rsiSourceInput = input(close, "RSI Source", group="TRAMPOLINE Settings")
lengthBB = input.int(20, minval=1, group="TRAMPOLINE Bollinger Bands")
srcBB = input(close, title="Source", group="TRAMPOLINE Bollinger Bands")
multBB = input.float(2.0, minval=0.001, maxval=50, title="StdDev", group="TRAMPOLINE Bollinger Bands")
offsetBB = input.int(0, "Offset", minval = -500, maxval = 500, group="TRAMPOLINE Bollinger Bands")
isRed = close < open
isGreen = close > open
basisBB = ta.sma(srcBB, lengthBB)
devBB = multBB * ta.stdev(srcBB, lengthBB)
upperBB = basisBB + devBB
lowerBB = basisBB - devBB
downBB = low < lowerBB or high < lowerBB
upBB = low > upperBB or high > upperBB
bbw = (upperBB - lowerBB) / basisBB
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsiM = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
back1 = isRed[1] and rsiM[1] <= RSIThreshold and close[1] < lowerBB[1] and bbw[1] > iBBThreshold
back2 = isRed[2] and rsiM[2] <= RSIThreshold and close[2] < lowerBB[2] and bbw[2] > iBBThreshold
back3 = isRed[3] and rsiM[3] <= RSIThreshold and close[3] < lowerBB[3] and bbw[3] > iBBThreshold
back4 = isRed[4] and rsiM[4] <= RSIThreshold and close[4] < lowerBB[4] and bbw[4] > iBBThreshold
back5 = isRed[5] and rsiM[5] <= RSIThreshold and close[5] < lowerBB[5] and bbw[5] > iBBThreshold
for1 = isGreen[1] and rsiM[1] >= RSIDown and close[1] > upperBB[1] and bbw[1] > iBBThreshold
for2 = isGreen[2] and rsiM[2] >= RSIDown and close[2] > upperBB[2] and bbw[2] > iBBThreshold
for3 = isGreen[3] and rsiM[3] >= RSIDown and close[3] > upperBB[3] and bbw[3] > iBBThreshold
for4 = isGreen[4] and rsiM[4] >= RSIDown and close[4] > upperBB[4] and bbw[4] > iBBThreshold
for5 = isGreen[5] and rsiM[5] >= RSIDown and close[5] > upperBB[5] and bbw[5] > iBBThreshold
weGoUp = isGreen and (back1 or back2 or back3 or back4 or back5) and (high > high[1]) and barstate.isconfirmed
upThrust = weGoUp and not weGoUp[1] and not weGoUp[2] and not weGoUp[3] and not weGoUp[4]
weGoDown = isRed and (for1 or for2 or for3 or for4 or for5) and (low < low[1]) and barstate.isconfirmed
downThrust = weGoDown and not weGoDown[1] and not weGoDown[2] and not weGoDown[3] and not weGoDown[4]
if (upThrust or downThrust) or (upThrust[1] or downThrust[1])
iTPSignalCount := iTPSignalCount + vTramp
//plotshape(bShowTramp and upThrust ? hl2 : na, title="Trampoline", text="T", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.new(colorBigGreen, 50), textcolor=color.white)
//plotshape(bShowTramp and downThrust ? hl2 : na, title="Trampoline", text="T", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.new(colorBigRed, 50), textcolor=color.white)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Squeeze Relaxer version 2.1 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
// Average Directional Index
sqTolerance = input.int(2, title="Squeeze Tolerance (lower = more sensitive)", group="Relaxing Settings", tooltip="How many bars to look back on the squeeze indicator")
adxSqueezeQ = input.int(21, title="ADX Threshold for TTM Squeeze", group="Relaxing Settings", tooltip="Anything over 19 filters out low volume periods. Set to 11 as a default, feel free to increase to get less noise")
adxValueQ = adx(dilen, adxlen)
sigabove19Q = adxValueQ > adxSqueezeQ
var cGreen = 0
var cRed = 0
var pos = false
var neg = false
sqlength = 20
multQ = 2.0
lengthKC = 20
multKC = 1.5
useTrueRange = true
source = close
basis = ta.sma(source, sqlength)
dev1 = multKC * ta.stdev(source, sqlength)
upperBBsq = basis + dev1
lowerBBsq = basis - dev1
ma = ta.sma(source, lengthKC)
rangeQ = high - low
rangema = ta.sma(rangeQ, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBBsq > lowerKC) and (upperBBsq < upperKC)
sqzOff = (lowerBBsq < lowerKC) and (upperBBsq > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
avg1 = math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC))
avg2 = math.avg(avg1, ta.sma(close, lengthKC))
val = ta.linreg(close - avg2, lengthKC, 0)
pos := false
neg := false
// if squeeze is bright RED, increment by one
if (val < nz(val[1]) and val < 5 and not sqzOn)
cRed := cRed + 1
// if squeeze is bright GREEN, increment by one
if (val > nz(val[1]) and val > 5 and not sqzOn)
cGreen := cGreen + 1
// if bright RED squeeze is now dim, momentum has changed. Is ADX also above 19? - add a marker to chart
if (val > nz(val[1]) and cRed > sqTolerance and val < 5 and not pos[1] and sigabove19 == true)
cRed := 0
pos := true
// if bright GREEN squeeze is now dim, momentum has changed. Is ADX also above 19? - add a marker to chart
if (val < nz(val[1]) and cGreen > sqTolerance and val > 5 and not neg[1] and sigabove19 == true)
cGreen := 0
neg := true
buySignal1 = pos and barstate.isconfirmed
sellSignal1 = neg and barstate.isconfirmed
if (buySignal1 or sellSignal1) or (buySignal1[1] or sellSignal1[1])
iTPSignalCount := iTPSignalCount + vSqueeze
//plotshape(bShowSqueeze and pos ? pos : na, title="Squeeze Buy Signal", style=shape.diamond, location=location.belowbar, color=color.rgb(255, 230, 0), size=size.tiny)
//plotshape(bShowSqueeze and neg ? neg : na, title="Squeeze Sell Signal", style=shape.diamond, location=location.abovebar, color=color.rgb(255, 230, 0), size=size.tiny)
cSQColor = color.white
cSQBorder = color.white
cSQWick = color.white
if val > 0
if val > nz(val[1])
cSQColor := color.from_gradient(math.abs(val), 0, 30, color.new(colorBigGreen, 50), color.new(colorBigGreen, 0))
cSQBorder := colorBigGreen
cSQWick := cSQColor
if val < nz(val[1])
cSQColor := color.new(colorBigGreen, 70)
cSQBorder := color.new(color.black, 100)
cSQWick := cSQColor
else
if val < nz(val[1])
cSQColor := color.from_gradient(math.abs(val), 0, 30, color.new(colorBigRed, 50), color.new(colorBigRed, 0))
cSQBorder := colorBigRed
cSQWick := cSQColor
if val > nz(val[1])
cSQColor := color.new(colorBigRed, 50)
cSQBorder := color.new(color.black, 100)
cSQWick := cSQColor
plotcandle(sCandleType=="Squeeze" ? open : na, high, low, close, color=cSQColor, wickcolor=cSQWick, bordercolor=cSQBorder)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= VECTOR CANDLES =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
import TradersReality/Traders_Reality_Lib/2 as trLib
color redVectorColor = colorBigRed
color greenVectorColor = colorBigGreen
color violetVectorColor = input.color(title='Violet',defval=color.fuchsia, inline='vectors', group="Vector Candle Settings")
color blueVectorColor = input.color(title='Blue', defval=color.rgb(83, 144, 249), inline='vectors', tooltip='Bull bars are green and bear bars are red when the bar is with volume >= 200% of the average volume of the 10 previous bars, or bars where the product of candle spread x candle volume is >= the highest for the 10 previous bars.\n Bull bars are blue and bear are violet when the bar is with with volume >= 150% of the average volume of the 10 previous bars.', group="Vector Candle Settings")
color regularCandleUpColor = input.color(title='Regular: Up Candle', defval=color.new(#02a433, 99), inline='nonVectors', group="Vector Candle Settings")
color regularCandleDownColor = input.color(title='Regular: Down Candle', defval=color.new(#a10101, 99), inline='nonVectors', tooltip='Bull bars are light gray and bear are dark gray when none of the red/green/blue/violet vector conditions are met.', group="Vector Candle Settings")
bool overrideSym = false
string pvsraSym = ''
bool colorOverride = true
pvsraVolume(overrideSymbolX, pvsraSymbolX, tickerIdX) =>
request.security(overrideSymbolX ? pvsraSymbolX : tickerIdX, '', [volume,high,low,close,open], barmerge.gaps_off, barmerge.lookahead_off)
[pvsraVolume, pvsraHigh, pvsraLow, pvsraClose, pvsraOpen] = pvsraVolume(overrideSym, pvsraSym, syminfo.tickerid)
[pvsraColor, alertFlag, averageVolume, volumeSpread, highestVolumeSpread] = trLib.calcPvsra(pvsraVolume, pvsraHigh, pvsraLow, pvsraClose, pvsraOpen, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, regularCandleDownColor, regularCandleUpColor)
bVectorGreen = pvsraColor == greenVectorColor
bVectorRed = pvsraColor == redVectorColor
plotcandle(sCandleType=="Vector" ? open : na, high, low, close, color=pvsraColor, wickcolor=pvsraColor, bordercolor=pvsraColor)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= TOTAL RECALL =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
if (bVectorGreen and (close[0] == upClose[0] or close[1] == upClose[1] or close[2] == upClose[2] or close[3] == upClose[3]))
bGreenSignal := true
//plotshape(bGreenSignal and bShowEarlyReversal and barstate.isconfirmed ? 1 : na, title="Reversal Approaching", style=shape.cross, location=location.abovebar, color=color.yellow, size=size.tiny)
//plotcandle(open, high, low, close, "", color=pvsraColor, wickcolor=pvsraColor, bordercolor=color.rgb(255, 0, 0))
if (bVectorRed and (close[0] == downClose[0] or close[1] == downClose[1] or close[2] == downClose[2] or close[3] == downClose[3]))
bRedSignal := true
//plotshape(bRedSignal and bShowEarlyReversal and barstate.isconfirmed ? 1 : na, title="Reversal Approaching", style=shape.cross, location=location.belowbar, color=color.yellow, size=size.tiny)
//plotcandle(open, high, low, close, "", color=pvsraColor, wickcolor=pvsraColor, bordercolor=color.rgb(0, 255, 132))
if (bGreenSignal or bRedSignal) or (bGreenSignal[1] or bRedSignal[1])
iTPSignalCount := iTPSignalCount + vEarlyRev
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= THE SHARK =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
bApply25and75 = input(false, title="Apply 25/75 RSI rule", group="Shark Settings")
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
ema400 = ta.ema(close, 400)
ema800 = ta.ema(close, 800)
wapwap = ta.vwap(close)
bTouchedLine = (ema50<high and ema50>low) or (ema200<high and ema200>low) or (ema400<high and ema400>low) or (ema800<high and ema800>low) or (wapwap<high and wapwap>low)
basis5 = ta.sma(rsiM, 30)
dev = 2.0 * ta.stdev(rsiM, 30)
upper7 = basis5 + dev
lower7 = basis5 - dev
bBelow25 = rsiM < 26
bAbove75 = rsiM > 74
if not bApply25and75
bBelow25 := true
bAbove75 := true
bShowSharkUp = (rsiM < lower7 and bBelow25) and barstate.isconfirmed
bShowSharkDown = (rsiM > upper7 and bAbove75) and barstate.isconfirmed
if (bShowSharkUp or bShowSharkDown) or (bShowSharkUp[1] or bShowSharkDown[1])
iTPSignalCount := iTPSignalCount + vShark
//plotchar(bShowShark and bShowSharkUp ? hlcc4 : na, char="🦈", title="Shark", location=location.belowbar, size=size.tiny)
//plotchar(bShowShark and bShowSharkDown ? hlcc4 : na, char="🦈", title="Shark", location=location.abovebar, size=size.tiny)
///////////////////////////////////////////////////////////////////////
showAllMA = false
showBasisPlot = false
showWatchSignals = true
group3 = "Ultimate Buy Sell"
requireWatchSignals = true
watchSignalLookback = input.int(35, title="# of bars back to use Watch Signals", group=group3, step=1, tooltip="How many bars back to consider a Watch signal valid. Longer values tend to create more inaccurate B/S signals. The reasoning is that as volatility (range of price fluctuations) stabilizes, the bollinger bands tighten, and when price makes a sudden move, it generates a watch signal and then buy or sell signal, fails and then reverses suddenly. We don't want to count these down the road.")
useSignalWaiting = false
signalWaitPeriod = input.int(5, title="# of bars before signals are allowed ", group=group3, step=1, tooltip="How many bars after a buy or sell signal to wait before allowing all watch Signals as well as buy and sell signals to be generated.")
group4 = "Ultimate Buy Sell"
rsiSource = input(close, title="RSI Data Source", group=group4)
rsiLength = input.int(32, title="RSI Length", minval=1, group=group4, tooltip="RSI is not visible, but is used for trade signals. RSI crossing various lines generates signals.")
rsiMaType = "RMA"
rsiMaType1 = "WMA"
rsiBasisLength = input.int(32, title="RSI Basis Length", minval=1, group=group4)
rsiMultiplier = input.float(2, minval=1, maxval=3, step=0.1, title="RSI Band Multiplier", group=group4, tooltip="This is the standard deviation, and affects Watch signals, which affect Buy and Sell signals.")
wmaLength = input.int(3, title="Smoothing Length", minval=1, group=group4)
useRsiWatchSignals = input(true, title="RSI Watch Signals", group=group4, tooltip = "If the RSI Crosses over the lower Bollinger Band it creates a buy watch signal. If it crosses under the upper band it creates a sell watch signal.")
group5 = "Ultimate Buy Sell"
priceBasisLength = input.int(20, title="Price BBand Basis Length", group=group5, tooltip="Sets the length to calculate the Price Bollinger Bands and corresponding basis line.")
priceMaType = "SMA"
priceInnerMultiplier = input.float(2, minval=1, maxval=4, step=0.1, title="Price Inner BB Multiplier", group=group5, tooltip="This is the standard deviation for the inner Price Bollinger Band which does not affect signals.")
priceOuterMultiplier = input.float(2.5, minval=2, maxval=6, step=0.1, title="Price Outer BB Multiplier", group=group5, tooltip="This is the standard deviation for the outer Price Bollinger Band and does affect watch signals, which affect Buy and Sell signals.")
usePriceBandWatchSignals = input(true, title="Bollinger Band Watch Signals", group=group5, tooltip= "If price crosses the Bollinger Bands this creates a watch signal")
group6 = "Ultimate Buy Sell"
atrPeriod = input.int(30, title="ATR Period", group=group6)
maPeriod = input.int(10, title="ATR MA Period", group=group6)
atrMult = input.float(1.5, minval=1, step=0.1, title="ATR Band multiplier", group=group6, tooltip = "Can make the ATR bands wider.")
atrMaType = input.string("WMA", title="ATR Moving Average Type", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA"], group=group6, tooltip="The moving average used to calculate the ATR moving average. Currently has no effect on signals.")
useAtrWatchSignals = input(true, title="ATR watch signals", group=group6)
group8 = "Ultimate Buy Sell"
useRsiSignals = input(true, title="RSI crossing Basis", group=group8, tooltip="Uses RSI crossing RSI basis.")
use75Signals = input(true, title="RSI crossing under 75", group=group8, tooltip="Sell signals from crossing under RSI 75")
use25Signals = input(true, title="RSI crossing over 25", group=group8, tooltip="Buy signals from crossing over RSI 25")
useRsiMa = input(true, title="Rsi Crossing a Moving Average", group=group8, tooltip="Signals based on RSI crossing a custom length moving average rather than the Basis of the Bollinger Bands. This allows you to change the Bollinger Band moving average type used in the calculation (which will change the shape of the bands) and cross a different moving average without changing watch signal generation. To see these effects, use the Ultimate RSI indicator.")
rsiMaLength = input.int(24, title="Length of additional RSI MA", inline="rsiMa", minval=1, group=group8, tooltip="Adds another moving average to the RSI that will not affect the Bollinger Bands. This can be used for signals without compromising the watch signals if using a WMA or other moving averages types for the Bands.")
rsiMaType2 = input.string("WMA", title="Moving Average Type", inline="rsiMa", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA"], group=group8)
filterBuySell = true
group11 = "Ultimate Buy Sell"
fast_length = input.int(12, title="Fast Length", group=group11, tooltip="Set the fast length for the MACD indicator.")
slow_length = input.int(26, title="Slow Length", group=group11, tooltip="Set the slow length for the MACD indicator.")
signal_length = input.int(title="Smoothing", minval=1, maxval=50, defval=9, group=group11, tooltip="Set the smoothing period for the MACD indicator.")
sma_source = input.string(title="MACD Line MA Type", defval="EMA", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA"], group=group11, tooltip="Select the moving average type for the MACD line.")
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA"], group=group11, tooltip="Select the moving average type for the MACD signal line.")
// ATR with bands
atrMa(src, Length, type) =>
switch type
"SMA" => ta.sma(src, Length)
"EMA" => ta.ema(src, Length)
"WMA" => ta.wma(src, Length)
"HMA" => ta.hma(src, Length)
"VWMA" => ta.vwma(src, Length)
"RMA" => ta.rma(src, Length)
atrValue = ta.atr(atrPeriod)
atrMaValue = atrMa(close, maPeriod, atrMaType)
upperAtrBand = atrMaValue + atrValue * atrMult
middleAtrBand = atrMaValue
lowerAtrBand = atrMaValue - atrValue * atrMult
bbUpper = atrMaValue + atrValue + atrMult * ta.stdev(close, maPeriod)
bbLower = atrMaValue - atrValue - atrMult * ta.stdev(close, maPeriod)
maType(src, length, type) =>
switch type
"SMA" => ta.sma(src, length)
"EMA" => ta.ema(src, length)
"WMA" => ta.wma(src, length)
"HMA" => ta.hma(src, length)
"VWMA" => ta.vwma(src, length)
"RMA" => ta.rma(src, length)
fast_ma := maType(close, fast_length, sma_source)
slow_ma := maType(close, slow_length, sma_source)
macd := fast_ma - slow_ma
signal := maType(macd, signal_length, sma_signal)
hist := macd - signal
up := ta.rma(math.max(ta.change(rsiSource), 0), rsiLength)
down := ta.rma(-math.min(ta.change(rsiSource), 0), rsiLength)
rsi := down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMa(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"WMA" => ta.wma(source, length)
"HMA" => ta.hma(source, length)
"VWMA" => ta.vwma(source, length)
"RMA" => ta.rma(source, length)
rsiBasis = rsiMa(rsi, rsiBasisLength, rsiMaType1)
rsiDeviation = ta.stdev(rsi, rsiBasisLength)
upperRsi = rsiBasis + rsiMultiplier * rsiDeviation
lowerRsi = rsiBasis - rsiMultiplier * rsiDeviation
rsiMa = rsiMa(rsi, rsiMaLength, rsiMaType2)
priceMa(src, Length, type) =>
switch type
"SMA" => ta.sma(src, Length)
"EMA" => ta.ema(src, Length)
"WMA" => ta.wma(src, Length)
"HMA" => ta.hma(src, Length)
"VWMA" => ta.vwma(src, Length)
"RMA" => ta.rma(src, Length)
calculateBollingerBands(src, priceBasisLength, priceInnerMultiplier, priceOuterMultiplier, priceMaType) =>
priceBasis = priceMa(src, priceBasisLength, priceMaType)
priceInnerDeviation = priceInnerMultiplier * ta.stdev(src, priceBasisLength)
priceOuterDeviation = priceOuterMultiplier * ta.stdev(src, priceBasisLength)
[priceBasis, priceBasis + priceInnerDeviation, priceBasis - priceInnerDeviation, priceBasis + priceOuterDeviation, priceBasis - priceOuterDeviation]
[priceBasis, upperPriceInner, lowerPriceInner, upperPriceOuter, lowerPriceOuter] = calculateBollingerBands(close, priceBasisLength, priceInnerMultiplier, priceOuterMultiplier, priceMaType)
priceCrossOverInner = ta.crossover(close, lowerPriceInner) // Price over outer band
priceCrossUnderInner = ta.crossunder(close, upperPriceInner) // Price under outer band
rsiCrossOverLower = ta.crossover(rsi, lowerRsi) // RSI over lower band
rsiCrossUnderUpper = ta.crossunder(rsi, upperRsi) // RSI under upper band
rsiCrossOverBasis = ta.crossover(rsi, rsiBasis)
rsiCrossUnderBasis = ta.crossunder(rsi, rsiBasis)
rsiCrossOverMa = ta.crossover(rsi, rsiMa)
rsiCrossUnderMa = ta.crossunder(rsi, rsiMa)
rsiCrossUnder75 = ta.crossunder(rsi, 75) // RSI crossunder 75
rsiCrossUnder70 = ta.crossunder(rsi, 70) // RSI crossunder 70
rsiCrossUnder50 = ta.crossunder(rsi, 50) // RSI crossover 50
rsiCrossOver50 = ta.crossover(rsi, 50) // RSI crossover 50
rsiCrossOver30 = ta.crossover(rsi, 30) // RSI crossover 30
rsiCrossOver25 = ta.crossover(rsi, 25) // RSI crossover 25
priceCrossOverBasis = ta.crossover(close, priceBasis)
priceCrossUnderBasis = ta.crossunder(close, priceBasis)
macdBuy = ta.crossover(macd, signal)
macdSell = ta.crossunder(macd, signal)
highUnderAtrLower = ta.crossunder(high, lowerAtrBand)
lowOverAtrUpper = ta.crossover(low, upperAtrBand)
watchesInsideYellowRsi = false
buyAndSellInsideYellowRsi = false
var bool bought = false
var bool sold = false
var bool signalsBlocked = false
var int[] buyWatchArray = array.new_int(na)
var int[] sellWatchArray = array.new_int(na)
var int lastSignalBarIndex = na
bool plotBuy = false
bool plotSell = false
bool plotBuyBG = false
bool plotSellBG = false
buyWatch1 = (usePriceBandWatchSignals) and (priceCrossOverInner and not rsiCrossOverLower) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
buyWatch2 = (useRsiWatchSignals) and (rsiCrossOverLower and not priceCrossOverInner) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
buyWatch3 = (usePriceBandWatchSignals) and (priceCrossOverInner and rsiCrossOverLower) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
buyWatch4 = (usePriceBandWatchSignals) and (priceCrossOverInner) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
buyWatch5 = (useRsiWatchSignals) and (rsiCrossOverLower) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
buyWatch6 = (useRsiWatchSignals) and (rsiCrossOver25) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
buyWatch7 = (useAtrWatchSignals and highUnderAtrLower) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
sellWatch1 = (usePriceBandWatchSignals) and (priceCrossUnderInner and not rsiCrossUnderUpper) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
sellWatch2 = (useRsiWatchSignals) and (rsiCrossUnderUpper and not priceCrossUnderInner) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
sellWatch3 = (usePriceBandWatchSignals) and (priceCrossUnderInner and rsiCrossUnderUpper) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
sellWatch4 = (usePriceBandWatchSignals) and (priceCrossUnderInner) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
sellWatch5 = (useRsiWatchSignals) and (rsiCrossUnderUpper) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
sellWatch6 = (useRsiWatchSignals) and (rsiCrossUnder75) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
sellWatch7 = (useAtrWatchSignals) and (lowOverAtrUpper) and (barstate.isconfirmed) and (not watchesInsideYellowRsi) and (not signalsBlocked)
bool buyWatched = buyWatch1 or buyWatch2 or buyWatch3 or buyWatch4 or buyWatch5 or buyWatch6 or buyWatch7 // or buyWatch8
bool sellWatched = sellWatch1 or sellWatch2 or sellWatch3 or sellWatch4 or sellWatch5 or sellWatch6 or sellWatch7 // or sellWatch8
array.push(buyWatchArray, buyWatched ? 1 : na)
array.push(sellWatchArray, sellWatched ? 1 : na)
while array.size(buyWatchArray) > watchSignalLookback
array.shift(buyWatchArray)
while array.size(sellWatchArray) > watchSignalLookback
array.shift(sellWatchArray)
buyWatchSumMet = (array.sum(buyWatchArray) >= 1)
sellWatchSumMet = (array.sum(sellWatchArray) >= 1)
buyWatchMet = (buyWatchSumMet)
sellWatchMet = (sellWatchSumMet)
combinedBuySignals = rsiCrossOverBasis or rsiCrossOver25 or rsiCrossOverMa // or buySignal7 or buySignal8
combinedSellSignals = rsiCrossUnderBasis or rsiCrossUnder75 or rsiCrossUnderMa // or sellSignal7 or sellSignal8
buySignals = ((not requireWatchSignals and combinedBuySignals) or (requireWatchSignals and buyWatchMet and combinedBuySignals))
sellSignals = ((not requireWatchSignals and combinedSellSignals) or (requireWatchSignals and sellWatchMet and combinedSellSignals))
if (buySignals) and (not buyAndSellInsideYellowRsi) and (not buyWatched) and (not signalsBlocked)
plotBuyBG := true
else if (sellSignals) and (not buyAndSellInsideYellowRsi) and (not sellWatched) and (not signalsBlocked)
plotSellBG := true
else
plotBuyBG := false
plotSellBG := false
if (buySignals) and (barstate.isconfirmed) and (not buyAndSellInsideYellowRsi) and (not buyWatched) and (not signalsBlocked)
bought := true
sold := false
plotBuy := true
lastSignalBarIndex := bar_index
array.clear(buyWatchArray)
array.clear(sellWatchArray)
else if (sellSignals) and (barstate.isconfirmed) and (not buyAndSellInsideYellowRsi) and (not sellWatched) and (not signalsBlocked)
sold := true
bought := false
plotSell := true
lastSignalBarIndex := bar_index
array.clear(sellWatchArray)
array.clear(buyWatchArray)
else
plotBuy := false
plotSell := false
//plotshape(bBuySell and plotBuy and trendUpWAE > 0 ? true : na, title="BUY/LONG", color=color.new(color.black, 100), location=location.belowbar, textcolor=colorBigGreen, text="Buy", size=size.tiny, style=shape.labelup)
//plotshape(bBuySell and plotSell and trendDownWAE > 0 ? true : na, title="SELL/SHORT", color=color.new(color.black, 100), location=location.abovebar, textcolor=colorBigRed, text="Sell", size=size.tiny, style=shape.labeldown)
// ===================================== VODKA SHOT ==================================================================