-
Notifications
You must be signed in to change notification settings - Fork 0
/
TLF
1634 lines (1544 loc) · 102 KB
/
TLF
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
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lame_khan369
// Refactor +
//@version=5
indicator("TheLameFactory V1.9",
shorttitle="TLF 1.9",
overlay=false,
format=format.price,
max_bars_back= 1000,
dynamic_requests= true)
// timeframe="",
// timeframe_gaps = true)
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Universal §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░{ {Universal Variables}
//-----------------------------------------------------------------------------
// Setting -- Groups, Tooltips, Colors, Display --
//-----------------------------------------------------------------------------{ {Setting}
//////////////////////////////////////////////// Groups ////////////////////////////////////////////////////{
UniGp = "███🌎Universal Setting🌎███" //Universal Setting
loPFGp = "Long Price Range -- Range Start -- Range End" //Long Price Range
SoPFGp = "Short Price Range -- Range Start -- Range End" //Short Price Range
DGp = " --- 📺 Display 📺 ---" //Display
SigGp = " --- 🚥 Signal Display 🚥 ---" //Display
brcolGP = " 📊 Bar Display 📊" //Display
brCcolGP = "Custom Bar Color 👨🎨" //Display
bgcolGP = " 🌁 Background Display 🌁" //Display
bgCcolGP = "Custom Background Color 👨🎨" //Display
lnPlotGp = " 📉 Line Display Setting -- Bull -- Bear -- Custom 📈" //Display
lnCcolGP = "Custom Line Color 👨🎨" //Display
bBGp = " --- 🐻 Confirmations 🐂 ---" //Confirmations
TMGp = " ✅ Trend Magic Multi TF -- Source[CCI - UpT - DownT]" //Trend Magic
TMTFCGp = "TM TFC -- CCI Period -- ATR Period --ATR Multiplier" //Trend Magic
TMaltGp = "TM Alt -- Res -- CCI Period -- ATR Period --ATR Multiplier" //Trend Magic
TMTF1Gp = "TM TF1 -- TF -- CCI Period -- ATR Period --ATR Multiplier" //Trend Magic
TMTF2Gp = "TM TF2 -- TF -- CCI Period -- ATR Period --ATR Multiplier" //Trend Magic
BBMGp = " ✅ BB Magic -- Source -- Length -- Multiplier--Diff?" //BB Magic
BBMaltGp = "BB Magic Alt -- Res -- Length -- Multiplier--Diff?" //BB Magic
SCLGP = " ✅ Scalping Line Multi TF -- Source" //Scalping Line
SCLTFCGP = "SCL TFC -- Percent -- Main Period -- Signal Period" //Scalping Line
SCLAltGP = "SCL Alt -- Alternate Resolution" //Scalping Line
SCLTF1GP = "SCL TF1 -- Timeframe" //Scalping Line
MAGp = " ✅ MA Confirmation -- Source" //MA
MAOCCG = "Open/Close/Cross MA Strategy -- Diff?" //O.C.C
MACGp = "Corrected MA [Cross-Diff]-- Length -- Threshold" //C.MA
MAfltrGp = "MA filter -- Length -- Extreme?" //MA Filter
MADfGp = "MA Diff" //MA Df
CEGp = " ✅ Chandelier Exit -- ATR [period, Multi] -- close?" //Chandelier Exit
RsiGp = " ✅ RSI -- Source -- period -- Overbought -- OverSold" //RSI
VwapGp = " ✅ VWAP -- Source --Anchor -- stdevMulti" //VWAP
AdxGp = " ✅ ADX Threshold--Diff--Length--Smooth--Thre" //ADX
//}
//////////////////////////////////////////////// Tooltips ////////////////////////////////////////////////////{
BubeT = "Enable Bull/Bear Condition"
TFT = "Choose Timeframe"
MAtypeT = "Choose MA type"
SCLsrcT = "Universal Scalping Line source"
SCLcrossuseT = "Enable Scaliping Line Crossover/Crossunder Confirmation"
SCLrangeuseT = "Enable Scaliping Line Range Confirmation"
SCLT = "Larger %: more sensitive to price deviations from the moving average (MA), more Signals
\nSmaller Main period: more sensitive to price deviations, more Signals\n
Smaller Signal period: more sensitive to price deviations, more Signals"
PWMApT = "Power value\nOnly applicable for PWMA MA type"
MAsrcT = "MA universal source\nHas no impact on Open/Close/Cross Strategy"
MAfltlxtT = "Use High and Low for Filter instead of Close price"
ceuseclT = "Use Close price Extremums"
//}
//////////////////////////////////////////////// Colors ////////////////////////////////////////////////////{
green = color.green
red = color.red
gray = color.gray
white = color.white
blue = color.blue
green100 = #008000FF
lime100 = #00FF00FF
red100 = #FF0000FF
aqua100 = #00FFFFFF
darkred100 = #8B0000FF
gray100 = #808080FF
//}
//////////////////////////////////////////////// Display Formats ////////////////////////////////////////////////////{
dw_Y = display.data_window
dw_N = display.all - display.data_window
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// T&P Filter -- Time & Price Filters --
//-----------------------------------------------------------------------------{ {Time & Price}
//Time Filter
tFltruse = input.bool(false, "", inline = "TFltr", group = UniGp)
tFltrID = input.time(timestamp("2024-10-5 10:09:03 +0300")," Time ⏯️", inline = "TFltr", group = UniGp)
tFltr = tFltruse == true ? time >= tFltrID : true
//Long Price Range
rLouse = input.bool(false, "", inline = "LoPR", group = loPFGp)
rLoP1 = input.price(522, " Start", inline = "LoPR", group = loPFGp)
rLoP2 = input.price(520, " End", inline = "LoPR", group = loPFGp)
longInRange = rLouse == true ? low >= rLoP2 and low <= rLoP1 : true
//Short Price Range
rSouse = input.bool(false, "", inline = "SoPR", group = SoPFGp)
rSoP1 = input.price(560, " Start", inline = "SoPR", group = SoPFGp)
rSoP2 = input.price(580, " End", inline = "SoPR", group = SoPFGp)
shortInRange = rSouse == true ? high >= rSoP1 and high <= rSoP2 : true
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// Display -- Display Conditions --
//-----------------------------------------------------------------------------{ {Display setting inputs}
///////////////////////// Signal Display ////////////////////////////////////////////////////////////////////{
//Buy/Sell Display
_dBS = input.bool(false, "Show Buy/Sell Signals", inline = "bs1", group = DGp)
bullcol = input.color(lime100, "", inline = "bs1", group = DGp)
bearcol = input.color(red100, "", inline = "bs1", group = DGp)
//}
///////////////////////// Signal Plots ////////////////////////////////////////////////////////////////////{
//Signal Overlay False Display
_Sig_BuBe = input.bool(true, "Bull-Bear", inline = "1", group = SigGp)
_Sig_TM_TFC = input.bool(true, "TM-TFC", inline = "1", group = SigGp)
_Sig_TM_Alt = input.bool(true, "TM-Alt", inline = "1", group = SigGp)
_Sig_TM_TF1 = input.bool(true, "TM-TF1", inline = "1", group = SigGp)
_Sig_TM_TF2 = input.bool(true, "TM-TF2", inline = "1", group = SigGp)
_Sig_BBM = input.bool(true, "BBM", inline = "1", group = SigGp)
_Sig_BBM_Alt = input.bool(true, "BBM_Alt", inline = "1", group = SigGp)
_Sig_SLC_TFC = input.bool(true, "SCL-TFC", inline = "1", group = SigGp)
_Sig_SLC_Alt = input.bool(true, "SCL-Alt", inline = "1", group = SigGp)
_Sig_SLC_TF1 = input.bool(true, "SCLL-TF1", inline = "1", group = SigGp)
_Sig_MA_OCCrng = input.bool(true, "MA.OCC_Range", inline = "1", group = SigGp)
_Sig_MA_OCCDf = input.bool(true, "MA.OCC_Diff", inline = "1", group = SigGp)
_Sig_CMA_Crs = input.bool(true, "CMA.Crs", inline = "1", group = SigGp)
_Sig_CMA_Df = input.bool(true, "CMA.Diff", inline = "1", group = SigGp)
_Sig_MA_fltr = input.bool(true, "MA.Filter", inline = "1", group = SigGp)
_Sig_MA_Df = input.bool(true, "MA.Diff", inline = "1", group = SigGp)
_Sig_CE_rng = input.bool(true, "C.E", inline = "1", group = SigGp)
_Sig_RSI = input.bool(true, "RSI", inline = "1", group = SigGp)
_Sig_VWAP = input.bool(true, "VWAP", inline = "1", group = SigGp)
_Sig_ADX_thr = input.bool(true, "ADX.Thr", inline = "1", group = SigGp)
_Sig_ADX_Df = input.bool(true, "ADX.Diff", inline = "1", group = SigGp)
//}
///////////////////////// Bar Color Display ////////////////////////////////////////////////////////////////////{
brcoluse = input.bool(false, "Color Bars with Signals", inline = "b1", group = brcolGP)
brbullcol = input.color(lime100, "", inline = "b1", group = brcolGP)
brbearcol = input.color(red100, "", inline = "b1", group = brcolGP)
//User input to choose signals to efect colors for bar Color
_bC_BuBe = input.bool(false, "Bull-Bear", inline = "1", group = brCcolGP)
_bC_TM_TFC = input.bool(false, "TM-TFC", inline = "1", group = brCcolGP)
_bC_TM_Alt = input.bool(false, "TM-Alt", inline = "1", group = brCcolGP)
_bC_TM_TF1 = input.bool(false, "TM-TF1", inline = "1", group = brCcolGP)
_bC_TM_TF2 = input.bool(false, "TM-TF2", inline = "1", group = brCcolGP)
_bC_BBM = input.bool(false, "BBM", inline = "1", group = brCcolGP)
_bC_BBM_Alt = input.bool(false, "BBM_Alt", inline = "1", group = brCcolGP)
_bC_SLC_TFC = input.bool(false, "SCL-TFC", inline = "1", group = brCcolGP)
_bC_SLC_Alt = input.bool(false, "SCL-Alt", inline = "1", group = brCcolGP)
_bC_SLC_TF1 = input.bool(false, "SCLL-TF1", inline = "1", group = brCcolGP)
_bC_MA_OCCrng = input.bool(false, "MA.OCC_Range", inline = "1", group = brCcolGP)
_bC_MA_OCCDf = input.bool(false, "MA.OCC_Diff", inline = "1", group = brCcolGP)
_bC_CMA_Crs = input.bool(false, "CMA.Crs", inline = "1", group = brCcolGP)
_bC_CMA_Df = input.bool(false, "CMA.Diff", inline = "1", group = brCcolGP)
_bC_MA_fltr = input.bool(false, "MA.Filter", inline = "1", group = brCcolGP)
_bC_MA_Df = input.bool(false, "MA.Diff", inline = "1", group = brCcolGP)
_bC_CE_rng = input.bool(false, "C.E", inline = "1", group = brCcolGP)
_bC_RSI = input.bool(false, "RSI", inline = "1", group = brCcolGP)
_bC_VWAP = input.bool(false, "VWAP", inline = "1", group = brCcolGP)
_bC_ADX_thr = input.bool(false, "ADX.Thr", inline = "1", group = brCcolGP)
_bC_ADX_Df = input.bool(false, "ADX.Diff", inline = "1", group = brCcolGP)
//}
///////////////////////// Background Color Display ////////////////////////////////////////////////////////////////////{
bgcoluse = input.bool(false, "Color Background with Signals", inline = "b1", group = bgcolGP)
bgbullcolID = input.color(lime100, "", inline = "b1", group = bgcolGP)
bgbearcolID = input.color(red100, "", inline = "b1", group = bgcolGP)
bgtrans = input.int(96, "Transp.", inline = "b1", group = bgcolGP)
bgbullcol = color.new(bgbullcolID,bgtrans)
bgbearcol = color.new(bgbearcolID,bgtrans)
bgNANcol = color.new(gray100,bgtrans)
//User input to choose signals to efect colors for Background Color
_bgC_BuBe = input.bool(false, "Bull-Bear", inline = "1", group = bgCcolGP)
_bgC_TM_TFC = input.bool(false, "TM-TFC", inline = "1", group = bgCcolGP)
_bgC_TM_Alt = input.bool(false, "TM-Alt", inline = "1", group = bgCcolGP)
_bgC_TM_TF1 = input.bool(false, "TM-TF1", inline = "1", group = bgCcolGP)
_bgC_TM_TF2 = input.bool(false, "TM-TF2", inline = "1", group = bgCcolGP)
_bgC_BBM = input.bool(false, "BBM", inline = "1", group = bgCcolGP)
_bgC_BBM_Alt = input.bool(false, "BBM_Alt", inline = "1", group = bgCcolGP)
_bgC_SLC_TFC = input.bool(false, "SCL-TFC", inline = "1", group = bgCcolGP)
_bgC_SLC_Alt = input.bool(false, "SCL-Alt", inline = "1", group = bgCcolGP)
_bgC_SLC_TF1 = input.bool(false, "SCLL-TF1", inline = "1", group = bgCcolGP)
_bgC_MA_OCCrng = input.bool(false, "MA.OCC_Range", inline = "1", group = bgCcolGP)
_bgC_MA_OCCDf = input.bool(false, "MA.OCC_Diff", inline = "1", group = bgCcolGP)
_bgC_CMA_Crs = input.bool(false, "CMA.Crs", inline = "1", group = bgCcolGP)
_bgC_CMA_Df = input.bool(false, "CMA.Diff", inline = "1", group = bgCcolGP)
_bgC_MA_fltr = input.bool(false, "MA.Filter", inline = "1", group = bgCcolGP)
_bgC_MA_Df = input.bool(false, "MA.Diff", inline = "1", group = bgCcolGP)
_bgC_CE_rng = input.bool(false, "C.E", inline = "1", group = bgCcolGP)
_bgC_RSI = input.bool(false, "RSI", inline = "1", group = bgCcolGP)
_bgC_VWAP = input.bool(false, "VWAP", inline = "1", group = bgCcolGP)
_bgC_ADX_thr = input.bool(false, "ADX.Thr", inline = "1", group = bgCcolGP)
_bgC_ADX_Df = input.bool(false, "ADX.Difff", inline = "1", group = bgCcolGP)
//}
///////////////////////// Line Plot Display ////////////////////////////////////////////////////////////////////{
//T.M Plot inputs
TMTFCP = input.bool(false, "Trend Magic - TFC", inline = "TMtfc", group = lnPlotGp)
TMtfcbullcol = input.color(lime100, "", inline = "TMtfc", group = lnPlotGp)
TMtfcbearcol = input.color(red100, "", inline = "TMtfc", group = lnPlotGp)
TMtfccuscol = input.bool(false, "Custom Color", inline = "TMtfc", group = lnPlotGp)
//BBM Plot inputs
BBMP = input.bool(false, "B.B Magic ", inline = "BBM", group = lnPlotGp)
bbmbullcol = input.color(lime100, "", inline = "BBM", group = lnPlotGp)
bbmbearcol = input.color(red100, "", inline = "BBM", group = lnPlotGp)
bbmcuscol = input.bool(false, "Custom Color", inline = "BBM", group = lnPlotGp)
//MA Plot inputs
MAOCCP = input.bool(false, "MA - OCC ", inline = "MAOCC", group = lnPlotGp)
MAOCCbullcol = input.color(lime100, "", inline = "MAOCC", group = lnPlotGp)
MAOCCbearcol = input.color(red100, "", inline = "MAOCC", group = lnPlotGp)
MAOCCcuscol = input.bool(false, "Custom Color", inline = "MAOCC", group = lnPlotGp)
MACOP = input.bool(false, "MA - Corrected ", inline = "MAC", group = lnPlotGp)
MACObullcol = input.color(lime100, "", inline = "MAC", group = lnPlotGp)
MACObearcol = input.color(red100, "", inline = "MAC", group = lnPlotGp)
MACOcuscol = input.bool(false, "Custom Color", inline = "MAC", group = lnPlotGp)
MAfltrP = input.bool(false, "MA - Filter ", inline = "MAF", group = lnPlotGp)
MAfltrbullcol = input.color(lime100, " ", inline = "MAF", group = lnPlotGp)
MAfltrbearcol = input.color(red100, "", inline = "MAF", group = lnPlotGp)
MAfltrcuscol = input.bool(false, "Custom Color", inline = "MAF", group = lnPlotGp)
MADfP = input.bool(false, "MA - Diff ", inline = "MAD", group = lnPlotGp)
MADfbullcol = input.color(lime100, " ", inline = "MAD", group = lnPlotGp)
MADfbearcol = input.color(red100, "", inline = "MAD", group = lnPlotGp)
MADfcuscol = input.bool(false, "Custom Color", inline = "MAD", group = lnPlotGp)
//Chandelier Exit Plot inputs
ceP = input.bool(false, "Chandelier Exit ", inline = "CE", group = lnPlotGp)
cebullcol = input.color(lime100, " ", inline = "CE", group = lnPlotGp)
cebearcol = input.color(red100, "", inline = "CE", group = lnPlotGp)
cecuscol = input.bool(false, "Custom Color", inline = "CE", group = lnPlotGp)
//
VWAPP = input.bool(false, "VWAP ", inline = "VWAP", group = lnPlotGp)
vwapbullcol = input.color(lime100, " ", inline = "VWAP", group = lnPlotGp)
vwapbearcol = input.color(red100, "", inline = "VWAP", group = lnPlotGp)
vwapcuscol = input.bool(false, "Custom Color", inline = "VWAP", group = lnPlotGp)
//User input to choose signals to efect colors for Line Plots
lnbullcol = input.color(lime100, "", inline = "b1", group = lnCcolGP)
lnbearcol = input.color(red100, "", inline = "b1", group = lnCcolGP)
_C_BuBe = input.bool(false, "Bull-Bear", inline = "1", group = lnCcolGP)
_C_TM_TFC = input.bool(false, "TM-TFC", inline = "1", group = lnCcolGP)
_C_TM_Alt = input.bool(false, "TM-Alt", inline = "1", group = lnCcolGP)
_C_TM_TF1 = input.bool(false, "TM-TF1", inline = "1", group = lnCcolGP)
_C_TM_TF2 = input.bool(false, "TM-TF2", inline = "1", group = lnCcolGP)
_C_BBM = input.bool(false, "BBM", inline = "1", group = lnCcolGP)
_C_BBM_Alt = input.bool(false, "BBM_Alt", inline = "1", group = lnCcolGP)
_C_SLC_TFC = input.bool(false, "SCL-TFC", inline = "1", group = lnCcolGP)
_C_SLC_Alt = input.bool(false, "SCL-Alt", inline = "1", group = lnCcolGP)
_C_SLC_TF1 = input.bool(false, "SCLL-TF1", inline = "1", group = lnCcolGP)
_C_MA_OCCrng = input.bool(false, "MA.OCC_Range", inline = "1", group = lnCcolGP)
_C_MA_OCCDf = input.bool(false, "MA.OCC_Diff", inline = "1", group = lnCcolGP)
_C_CMA_Crs = input.bool(false, "CMA.Crs", inline = "1", group = lnCcolGP)
_C_CMA_Df = input.bool(false, "CMA.Diff", inline = "1", group = lnCcolGP)
_C_MA_fltr = input.bool(false, "MA.Filter", inline = "1", group = lnCcolGP)
_C_MA_Df = input.bool(false, "MA.Diff", inline = "1", group = lnCcolGP)
_C_CE_rng = input.bool(false, "C.E", inline = "1", group = lnCcolGP)
_C_RSI = input.bool(false, "RSI", inline = "1", group = lnCcolGP)
_C_VWAP = input.bool(false, "VWAP", inline = "1", group = lnCcolGP)
_C_ADX_thr = input.bool(false, "ADX.Thr", inline = "1", group = lnCcolGP)
_C_ADX_Df = input.bool(false, "ADX.Diff", inline = "1", group = lnCcolGP)
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// Functions -- Universal Fx --
//-----------------------------------------------------------------------------{ {Functions}
//////////////////////////////////////////////// MA Function ///////////////////////////////////////////////////////////{
//DEMA MA Fx
variantDoubleEmaFx(src, len) =>
v2 = ta.ema(src, len)
v6 = 2 * v2 - ta.ema(v2, len)
v6
//TEMA MA Fx
variantTripleEmaFx(src, len) =>
v2 = ta.ema(src, len)
v7 = 3 * (v2 - ta.ema(v2, len)) + ta.ema(ta.ema(v2, len), len) // Triple Exponential
v7
//ZEMA MA Fx
variantZerolagEmaFx(src, len) =>
lag = (len - 1) / 2
emaSrc = src + src - src[lag]
v10 = ta.ema(emaSrc, len)
v10
//SSMA MA Fx
variantSuperSmootherFx(src, len) =>
a1 = math.exp(-1.414 * 3.14159 / len)
b1 = 2 * a1 * math.cos(1.414 * 3.14159 / len)
c2 = b1
c3 = -a1 * a1
c1 = 1 - c2 - c3
v9 = 0.0
v9 := c1 * (src + nz(src[1])) / 2 + c2 * nz(v9[1]) + c3 * nz(v9[2])
v9
//TMA MA Fx
variantTriangularSmaFx(src,len) =>
sma1 = ta.sma(src, len)
sma2 = ta.sma(sma1,len)
sma2
//PWMA Fx
pwmaFx(src, len, power) =>
sum = 0.0
weightSum = 0.0
for i = 0 to len - 1
weight = math.pow(len - i, power)
sum := sum + nz(src[i]) * weight
weightSum := weightSum + weight
sum / weightSum
//VAR MA Fx
cmoFx(src, len) =>
valpha = 2 / (len + 1)
vud1 = src > src[1] ? src - src[1] : 0
vdd1 = src < src[1] ? src[1] - src : 0
vUD = math.sum(vud1, 9)
vDD = math.sum(vdd1, 9)
vCMO = nz((vUD - vDD) / (vUD + vDD))
VAR = 0.0
VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])
VAR
//Wild MA Fx
wild_ma(src, length) =>
_wild = 0.0
_wild := nz(_wild[1]) + (src - nz(_wild[1])) / length
_wild
//MA Fx
_ma(src, type, length, power) =>
float result = switch type
"SMA" => ta.sma (src, length)
"EMA" => ta.ema (src, length)
"HMA" => ta.hma (src, length)
"WMA" => ta.wma (src, length)
"VWMA" => ta.vwma (src, length)
"SMMA" => ta.rma (src, length)
"DEMA" => variantDoubleEmaFx (src, length)
"TEMA" => variantTripleEmaFx (src, length)
"ZEMA" => variantZerolagEmaFx (src, length)
"SSMA" => variantSuperSmootherFx (src, length)
"TMA" => variantTriangularSmaFx (src, length)
"CCI" => ta.cci (src, length)
"RSI" => ta.rsi (src, length)
"CMO" => cmoFx (src, length)
"WildMA" => wild_ma (src, length)
"PWMA" => pwmaFx (src, length, power)
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// Variables -- Variables --
//-----------------------------------------------------------------------------{ {Variables}
/////////////////////////////////////////// Confirmation Variables /////////////////////////////////////////////////////{
//Bull-Bear{
var bool bullbarID = false
var bool bearbarID = false
var bool _bullbar = true
var bool _bearbar = true
var int _SigBuBeID = 0
var int _SigBuBe = 0
//}
//Trend Magic{
var bool TMTFCLoID = false
var bool TMTFCSoID = false
var bool TMTFCLong = true
var bool TMTFCShort = true
var int _SigTMTFCID = 0
var int _SigTMTFC = 0
//
var bool TMAltLoID = false
var bool TMAltSoID = false
var bool TMAltLong = true
var bool TMAltShort = true
var int _SigTMAltID = 0
var int _SigTMAlt = 0
//
var bool TMTF1LoID = false
var bool TMTF1SoID = false
var bool TMTF1Long = true
var bool TMTF1Short = true
var int _SigTMTF1ID = 0
var int _SigTMTF1 = 0
//
var bool TMTF2LoID = false
var bool TMTF2SoID = false
var bool TMTF2Long = true
var bool TMTF2Short = true
var int _SigTMTF2ID = 0
var int _SigTMTF2 = 0
//}
//BB Magic{
var bool BBMLoID = false
var bool BBMSoID = false
var bool BBMLong = true
var bool BBMShort = true
var int _SigBBMID = 0
var int _SigBBM = 0
//
var bool BBMAltLoID = false
var bool BBMAltSoID = false
var bool BBMAltLong = true
var bool BBMAltShort = true
var int _SigBBMAltID = 0
var int _SigBBMAlt = 0
//}
//SCL{
var bool SCLTFCLoID = false
var bool SCLTFCSoID = false
var bool SCLTFCLong = true
var bool SCLTFCShort = true
var int _SigSCLTFCID = 0
var int _SigSCLTFC = 0
//
var bool SCLAltLoID = false
var bool SCLAltSoID = false
var bool SCLAltLong = true
var bool SCLAltShort = true
var int _SigSCLAltID = 0
var int _SigSCLAlt = 0
//
var bool SCLTF1LoID = false
var bool SCLTF1SoID = false
var bool SCLTF1Long = true
var bool SCLTF1Short = true
var int _SigSCLTF1ID = 0
var int _SigSCLTF1 = 0
//}
//MA{
//O.C.C
//O.C.C Cross
var bool MAOCCLoID = false
var bool MAOCCSoID = false
var bool MAOCCLong = true
var bool MAOCCShort = true
var int _SigMAOCCID = 0
var int _SigMAOCC = 0
//O.C.C Diff
var bool MAOCCDfLoID = false
var bool MAOCCDfSoID = false
var bool MAOCCDfLong = true
var bool MAOCCDfShort = true
var int _SigMAOCCDfID = 0
var int _SigMAOCCDf = 0
//CMA
//CMA Cross
var bool MACcrsLoID = false
var bool MACcrsSoID = false
var bool MACcrsLong = true
var bool MACcrsShort = true
var int _SigMACcrsID = 0
var int _SigMACcrs = 0
//CMA Diff
var bool MACDfLoID = false
var bool MACDfSoID = false
var bool MACDfLong = true
var bool MACDfShort = true
var int _SigMACDfID = 0
var int _SigMACDf = 0
//MA Filter
var bool MAfltrLoID = false
var bool MAfltrSoID = false
var bool MAfltrLong = true
var bool MAfltrShort = true
var int _SigMAfltrID = 0
var int _SigMAfltr = 0
//MA Df
var bool MADfLoID = false
var bool MADfSoID = false
var bool MADfLong = true
var bool MADfShort = true
var int _SigMADfID = 0
var int _SigMADf = 0
//}
//Chandelier Exit{
var bool ceLoID = false
var bool ceSoID = false
var bool ceLong = true
var bool ceShort = true
var int _SigceID = 0
var int _Sigce = 0
//}
//RSI{
var bool rsiLoID = false
var bool rsiSoID = false
var bool rsiLong = true
var bool rsiShort = true
var int _SigrsiID = 0
var int _Sigrsi = 0
//}
//VWAP{
var bool vwapLoID = false
var bool vwapSoID = false
var bool vwapLong = true
var bool vwapShort = true
var int _SigvwapID = 0
var int _Sigvwap = 0
//}
//ADX{
//ADX Strong
var bool adxStrongID = false
var bool adxStrong = true
var int _SigADXstrID = 0
var int _SigADXstr = 0
//ADX Df
var bool adxDfID = false
var bool adxDf = true
var int _SigADXDfID = 0
var int _SigADXDf = 0
//}
//}
//-----------------------------------------------------------------------------}
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░}
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Confirmations §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░{ {Confirmations}
// //-----------------------------------------------------------------------------
// // Bull/Bear -- Bull/Bear --
// //-----------------------------------------------------------------------------{ {Bull/Bear}
// /////////////////////////////////////////// Bull/Bear //////////////////////////////////////////////////////////////////{
// bubeuse = input.bool(false, "Enable Bull/Bear", group = bBGp, tooltip = BubeT)
// bullbarID := close > open
// bearbarID := close < open
// _bullbar := bubeuse == false ? true : bullbarID
// _bearbar := bubeuse == false ? true : bearbarID
// _SigBuBeID := bullbarID ? 1 : bearbarID ? -1 : 0
// _SigBuBe := _bullbar ? 1 : _bearbar ? -1 : 0
// //}
/////////////////////////////////////////// Bull/Bear CTRL /////////////////////////////////////////////////////////////{
// plot(_Sig_BuBe==true? 0 : na, "Bull.Bear", _SigBuBeID == 1 ? lime100 : _SigBuBeID == -1 ? red100 : gray100)
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// CCI/Trend Magic -- Trend confirmation --
//-----------------------------------------------------------------------------{ {Trend Magic}
//////////////////////////////////////////////// Trend Magic Multi TF inputs ////////////////////////////////////{
ccisrc = input(close, " ", inline = "TMsrc", group = TMGp)
cci_upTsrc = input(low, "", inline = "TMsrc", group = TMGp)
cci_downTsrc= input(high, "", inline = "TMsrc", group = TMGp)
//TM TFC inputs
tmTFCuse = input.bool(false, "Enable T.M TFC", inline = "TMTFC", group = TMTFCGp)
tmTFCcciP = input(20, "", inline = "TMTFC", group = TMTFCGp) ///💡check 10 or 12
tmTFCATRp = input(5, "", inline = "TMTFC", group = TMTFCGp)
tmTFCATRmul = input(1, "", inline = "TMTFC", group = TMTFCGp)
tmTFCthrLo = input(0, "Long CCI threshold", inline = "TFCTR", group = TMTFCGp)
tmTFCthrSo = input(0, "Short CCI threshold", inline = "TFCTR", group = TMTFCGp)
//TM Alt
tmAltuse = input.bool(false, "", inline = "TMAlt", group = TMaltGp)
tmAltResV = input.int(6, "", inline = "TMAlt", group = TMaltGp)
tmAltcciP = input(20, "", inline = "TMAlt", group = TMaltGp)
tmAltATRp = input(5, "", inline = "TMAlt", group = TMaltGp)
tmAltATRmul = input(1, "", inline = "TMAlt", group = TMaltGp)
tmAltthrLo = input(0, "Long CCI threshold", inline = "TFATR", group = TMaltGp)
tmAltthrSo = input(0, "Short CCI threshold", inline = "TFATR", group = TMaltGp)
//TM TF1 inputs
tmTF1use = input.bool(false, "", inline = "TMTF1", group = TMTF1Gp)
tmTF1tf = input.timeframe("3", "", inline = "TMTF1", group = TMTF1Gp)
tmTF1cciP = input(20, "", inline = "TMTF1", group = TMTF1Gp)
tmTF1ATRp = input(5, "", inline = "TMTF1", group = TMTF1Gp)
tmTF1ATRmul = input(1, "", inline = "TMTF1", group = TMTF1Gp)
tmTF1thrLo = input(0, "Long CCI threshold", inline = "TF1TR", group = TMTF1Gp)
tmTF1thrSo = input(0, "Short CCI threshold", inline = "TF1TR", group = TMTF1Gp)
//TM TF2 inputs
tmTF2use = input.bool(false, "", inline = "TMTF2", group = TMTF2Gp)
tmTF2tf = input.timeframe("15", "", inline = "TMTF2", group = TMTF2Gp)
tmTF2cciP = input(20, "", inline = "TMTF2", group = TMTF2Gp)
tmTF2ATRp = input(5, "", inline = "TMTF2", group = TMTF2Gp)
tmTF2ATRmul = input(1, "", inline = "TMTF2", group = TMTF2Gp)
tmTF2thrLo = input(0, "Long CCI threshold", inline = "TF1TR", group = TMTF2Gp)
tmTF2thrSo = input(0, "Short CCI threshold", inline = "TF1TR", group = TMTF2Gp)
//}
//////////////////////////////////////////////// Trend Magic Multi TF Calculations ////////////////////////////////////{
//TM TFC Calculation
float cciTFC_ATR = ta.atr(tmTFCATRp)
cciTFC_upT = low - cciTFC_ATR * tmTFCATRmul
cciTFC_downT = high + cciTFC_ATR * tmTFCATRmul
float cciTFC = ta.cci(ccisrc, tmTFCcciP)
//TM TFC Trend Magic Calculation
float TMTFC = 0.0
TMTFC := cciTFC >= 0 ? (cciTFC_upT < nz(TMTFC[1]) ? nz(TMTFC[1]) : cciTFC_upT) :
(cciTFC_downT > nz(TMTFC[1]) ? nz(TMTFC[1]) : cciTFC_downT)
//TM Alt Calculation
tmAltcciPm = tmAltcciP * tmAltResV
tmAltATRpm = tmAltATRp * tmAltResV
float cciAlt_ATR = ta.atr(tmAltATRpm)
cciAlt_upT = low - cciAlt_ATR * tmAltATRmul
cciAlt_downT = high + cciAlt_ATR * tmAltATRmul
float cciAlt = ta.cci(ccisrc, tmAltcciPm)
//TM Alt Trend Magic Calculation
float TMAlt = 0.0
TMAlt := cciAlt >= 0 ? (cciAlt_upT < nz(TMAlt[1]) ? nz(TMAlt[1]) : cciAlt_upT) :
(cciAlt_downT > nz(TMAlt[1]) ? nz(TMAlt[1]) : cciAlt_downT)
//TM TF1 Calculation
float cciTF1_ATR = request.security(syminfo.tickerid, tmTF1tf, ta.atr(tmTF1ATRp))
float cciTF1low = request.security(syminfo.tickerid, tmTF1tf, low)
float cciTF1high = request.security(syminfo.tickerid, tmTF1tf, high)
float cciTF1_upT = request.security(syminfo.tickerid, tmTF1tf, cciTF1low - cciTF1_ATR * tmTF1ATRmul)
float cciTF1_downT = request.security(syminfo.tickerid, tmTF1tf, cciTF1high + cciTF1_ATR * tmTF1ATRmul)
float cciTF1 = request.security(syminfo.tickerid, tmTF1tf, ta.cci(ccisrc, tmTF1cciP))
float TMTF1 = 0.0
TMTF1 := cciTF1 >= 0 ? (cciTF1_upT < nz(TMTF1[1]) ? nz(TMTF1[1]) : cciTF1_upT) :
(cciTF1_downT > nz(TMTF1[1]) ? nz(TMTF1[1]) : cciTF1_downT)
//TM TF2 Calculation
float cciTF2_ATR = request.security(syminfo.tickerid, tmTF2tf, ta.atr(tmTF2ATRp))
float cciTF2low = request.security(syminfo.tickerid, tmTF2tf, low)
float cciTF2high = request.security(syminfo.tickerid, tmTF2tf, high)
float cciTF2_upT = request.security(syminfo.tickerid, tmTF2tf, cciTF2low - cciTF2_ATR * tmTF2ATRmul)
float cciTF2_downT = request.security(syminfo.tickerid, tmTF2tf, cciTF2high + cciTF2_ATR * tmTF2ATRmul)
float cciTF2 = request.security(syminfo.tickerid, tmTF2tf, ta.cci(ccisrc, tmTF2cciP))
float TMTF2 = 0.0
TMTF2 := cciTF2 >= 0 ? (cciTF2_upT < nz(TMTF2[1]) ? nz(TMTF2[1]) : cciTF2_upT) :
(cciTF2_downT > nz(TMTF2[1]) ? nz(TMTF2[1]) : cciTF2_downT)
//}
//////////////////////////////////////////////// Trend Magic Multi TF Conditions ////////////////////////////////////{
//TM TFC Conditions
TMTFCLoID := tmTFCthrLo == tmTFCthrSo ? (cciTFC > tmTFCthrLo ? true : false) : (cciTFC >= tmTFCthrLo ? true : false)
TMTFCSoID := tmTFCthrLo == tmTFCthrSo ? (cciTFC < tmTFCthrSo ? true : false) : (cciTFC <= tmTFCthrSo ? true : false)
TMTFCLong := tmTFCuse == false ? true : TMTFCLoID
TMTFCShort := tmTFCuse == false ? true : TMTFCSoID
_SigTMTFCID := TMTFCLoID ? 1 : TMTFCSoID ? -1 : 0
// _SigTMTFC := TMTFCLong ? 1 : TMTFCShort? -1 : 0
//TM Alt Conditions
TMAltLoID := tmAltthrLo == tmAltthrSo ? (cciAlt > tmAltthrLo ? true : false) : (cciAlt >= tmAltthrLo ? true : false)
TMAltSoID := tmAltthrLo == tmAltthrSo ? (cciAlt < tmAltthrSo ? true : false) : (cciAlt <= tmAltthrSo ? true : false)
TMAltLong := tmAltuse == false ? true : TMAltLoID
TMAltShort := tmAltuse == false ? true : TMAltSoID
_SigTMAltID := TMAltLoID ? 1 : TMAltSoID ? -1 : 0
// _SigTMAlt := TMAltLong ? 1 : TMAltShort? -1 : 0
//TM TF1 Conditions
TMTF1LoID := tmTF1thrLo == tmTF1thrSo ? (cciTF1 > tmTF1thrLo ? true : false) : (cciTF1 >= tmTF1thrLo ? true : false)
TMTF1SoID := tmTF1thrLo == tmTF1thrSo ? (cciTF1 < tmTF1thrSo ? true : false) : (cciTF1 <= tmTF1thrSo ? true : false)
TMTF1Long := tmTF1use == false ? true : TMTF1LoID
TMTF1Short := tmTF1use == false ? true : TMTF1SoID
_SigTMTF1ID := TMTF1LoID ? 1 : TMTF1SoID ? -1 : 0
// _SigTMTF1 := TMTF1Long ? 1 : TMTF1Short ? -1 : 0
//TM TF2 Conditions
TMTF2LoID := tmTF2thrLo == tmTF2thrSo ? (cciTF2 > tmTF2thrLo ? true : false) : (cciTF2 >= tmTF2thrLo ? true : false)
TMTF2SoID := tmTF2thrLo == tmTF2thrSo ? (cciTF2 < tmTF2thrSo ? true : false) : (cciTF2 <= tmTF2thrSo ? true : false)
TMTF2Long := tmTF2use == false ? true : TMTF2LoID
TMTF2Short := tmTF2use == false ? true : TMTF2SoID
_SigTMTF2ID := TMTF2LoID ? 1 : TMTF2SoID ? -1 : 0
// _SigTMTF2 := TMTF2Long ? 1 : TMTF2Short ? -1 : 0
//}
//////////////////////////////////////////////// Trend Magic Multi TF CTRL ////////////////////////////////////{
//TM and CCI Value Plots
// plot(TMTFC, "V_TM.TFC", TMTFCLoID ? green : TMTFCSoID ? red : gray, display = dw_Y)
// plot(cciTFC, "V_CCI.TFC", TMTFCLoID ? green : TMTFCSoID ? red : gray, display = dw_Y)
// plot(TMAlt, "V_TM.Alt", TMAltLoID ? green : TMAltSoID ? red : gray, display = dw_Y)
// plot(cciAlt, "V_CCI.Alt", TMAltLoID ? green : TMAltSoID ? red : gray, display = dw_Y)
// plot(TMTF1, "V_TM.TF1", TMTF1LoID ? green : TMTF1SoID ? red : gray, display = dw_Y)
// plot(cciTF1, "V_CCI.TF1", TMTF1LoID ? green : TMTF1SoID ? red : gray, display = dw_Y)
// plot(TMTF2, "V_TM.TF2", TMTF2LoID ? green : TMTF2SoID ? red : gray, display = dw_Y)
// plot(cciTF2, "V_CCI.TF2", TMTF2LoID ? green : TMTF2SoID ? red : gray, display = dw_Y)
//Signal ID CTRL
plot(_Sig_TM_TFC == true ? 1 : na, "TM.TFC", _SigTMTFCID == 1 ? lime100 : _SigTMTFCID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_TM_Alt == true ? 11 : na, "TM.Alt", _SigTMAltID == 1 ? lime100 : _SigTMAltID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_TM_TF1 == true ? 111 : na, "TM.TF1", _SigTMTF1ID == 1 ? lime100 : _SigTMTF1ID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_TM_TF2 == true ? 1111 : na, "TM.TF2", _SigTMTF2ID == 1 ? lime100 : _SigTMTF2ID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// BB Magic -- Trend confirmation --
//-----------------------------------------------------------------------------{ {BB Magic}
//////////////////////////////////////////////// BB Magic inputs ////////////////////////////////////////////////{
bbmuse = input.bool(false, "", inline = "BB", group = BBMGp)
bbmsrc = input(close, "", inline = "BB", group = BBMGp)
bbmleng = input.int(20, "", inline = "BB", group = BBMGp)
bbmmult = input.float(2.0, "", inline = "BB", group = BBMGp)
bbmDfuse = input.bool(false, "", inline = "BB", group = BBMGp)
bbmAltuse = input.bool(false, "", inline = "BB", group = BBMaltGp)
bbmAltV = input.int(6, "", inline = "BB", group = BBMaltGp)
bbmAltleng = input.int(20, "", inline = "BB", group = BBMaltGp)
bbmAltmult = input.float(2.0, "", inline = "BB", group = BBMaltGp)
bbmAltDfuse = input.bool(false, "", inline = "BB", group = BBMaltGp)
//}
//////////////////////////////////////////////// BB Magic Calculations ////////////////////////////////////////////////{
//BBM Calculations
[bbmmiddle, bbmupper, bbmlower] = ta.bb(bbmsrc, bbmleng, bbmmult)
bb_magic = bbmlower
bb_magic := nz(bb_magic[1], bb_magic)
bbmDIR_UP = 1
bbmDIR_DN = -1
bbmDir = bbmDIR_DN
if close < bb_magic and bbmDir == bbmDIR_UP
bbmDir := bbmDIR_DN
if close > bb_magic and bbmDir == bbmDIR_DN
bbmDir := bbmDIR_UP
if bbmlower > bb_magic and bbmDir == bbmDIR_UP
bb_magic := bbmlower
if bbmupper < bb_magic and bbmDir == bbmDIR_DN
bb_magic := bbmupper
//BBM Alt Calculations
bbmAltlengm = bbmAltleng * bbmAltV
[bbmAltmiddle, bbmAltupper, bbmAltlower] = ta.bb(bbmsrc, bbmAltlengm, bbmAltmult)
bb_magicAlt = bbmAltlower
bb_magicAlt := nz(bb_magicAlt[1], bb_magicAlt)
bbmAltDIR_UP = 1
bbmAltDIR_DN = -1
bbmAltDir = bbmAltDIR_DN
if close < bb_magicAlt and bbmAltDir == bbmAltDIR_UP
bbmAltDir := bbmAltDIR_DN
if close > bb_magicAlt and bbmAltDir == bbmAltDIR_DN
bbmAltDir := bbmAltDIR_UP
if bbmAltlower > bb_magicAlt and bbmAltDir == bbmAltDIR_UP
bb_magicAlt := bbmAltlower
if bbmAltupper < bb_magicAlt and bbmAltDir == bbmAltDIR_DN
bb_magicAlt := bbmAltupper
//}
//////////////////////////////////////////////// BB Magic Conditions ////////////////////////////////////////////////{
//BBM Conditions
bbmDfV = bb_magic - bb_magic[1]
bool bbmDfLo = bbmDfuse == false ? true : bbmDfV > 0
bool bbmDfSo = bbmDfuse == false ? true : bbmDfV < 0
BBMLoID := bbmDir == bbmDIR_UP and bbmDfLo
BBMSoID := bbmDir == bbmDIR_DN and bbmDfSo
BBMLong := bbmuse == false ? true : BBMLoID
BBMShort := bbmuse == false ? true : BBMSoID
_SigBBMID := BBMLoID ? 1 : BBMSoID ? -1 : 0
_SigBBM := BBMLong ? 1 : BBMShort ? -1 : 0
//BBM Alt Conditions
bbmAltDfV = bb_magicAlt - bb_magicAlt[1]
bool bbmAltDfLo = bbmAltDfuse == false ? true : bbmAltDfV > 0
bool bbmAltDfSo = bbmAltDfuse == false ? true : bbmAltDfV < 0
BBMAltLoID := bbmAltDir == bbmAltDIR_UP and bbmAltDfLo
BBMAltSoID := bbmAltDir == bbmAltDIR_DN and bbmAltDfSo
BBMAltLong := bbmAltuse == false ? true : BBMAltLoID
BBMAltShort := bbmAltuse == false ? true : BBMAltSoID
_SigBBMAltID := BBMAltLoID ? 1 : BBMAltSoID ? -1 : 0
_SigBBMAlt := BBMAltLong ? 1 : BBMAltShort ? -1 : 0
//}
//////////////////////////////////////////////// BB Magic CTRL ////////////////////////////////////////////////{
//BB Magic value CTRL
// plot(bb_magic, "V_BBM", BBMLoID ? green : BBMSoID ? red : gray, display = dw_Y)
// plot(bb_magicAlt, "V_BBM_Alt", BBMAltLoID ? green : BBMAltSoID ? red : gray, display = dw_Y)
//BB Magic Signal CTRL
plot(_Sig_BBM == true ? 2 : na, "BBM", _SigBBMID == 1 ? lime100 : _SigBBMID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_BBM_Alt == true ? 22 : na, "BBM_Alt", _SigBBMAltID == 1 ? lime100 : _SigBBMAltID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// Scalping Line -- Trend confirmation --
//-----------------------------------------------------------------------------{ {Scalping Line}
/////////////////////////////////////////// Scalping Line Multi TF inputs ////////////////////////////////////////{
SCLsrc = input(close, "Scalping Line source", group = SCLGP, tooltip = SCLsrcT)
//SCL TFC inputs
SCLTFCuse = input.bool(false, "Enable SCL TFC", inline = "SCLTFC", group = SCLTFCGP)
slcTFCper = input.float(1.0, "", step=0.1, minval=0, inline = "SCLTFC", group = SCLTFCGP)
slcTFCmainper = input(100, "", inline = "SCLTFC", group = SCLTFCGP)
slcTFCSigper = input(7, "", tooltip = SCLT, inline = "SCLTFC", group = SCLTFCGP)
slcTFCMAtype = input.string("SMA", "Moving Average Type", inline = "SCLTFCMA", group = SCLTFCGP,
options = ["SMA","EMA","HMA","WMA","VWMA","SMMA","DEMA","TEMA","ZEMA","SSMA","TMA","CCI","RSI","CMO", "WildMA", "PWMA"])
slcpowTFC = input.int(2, "PWMA Power", tooltip = PWMApT, inline = "SCLTFCMA", group = SCLTFCGP)
//SCL Alt inputs
SCLAltuse = input.bool(false, "Enable SCL Alternate Resolution",inline = "SCLAlt", group = SCLAltGP)
SCLResV = input.int(6, "", inline = "SCLAlt", group = SCLAltGP)
slcAltper = input.float(1.0, "%", step=0.1, minval=0, inline = "SCLAlt1", group = SCLAltGP)
slcAltmainper = input(100, "Main P.", inline = "SCLAlt1", group = SCLAltGP)
slcAltSigper = input(7, "Signal P.", tooltip = SCLT, inline = "SCLAlt1", group = SCLAltGP)
slcAltMAtype = input.string("SMA", "Moving Average Type", inline = "SCLAltMA", group = SCLAltGP,
options = ["SMA","EMA","HMA","WMA","VWMA","SMMA","DEMA","TEMA","ZEMA","SSMA","TMA","CCI","RSI","CMO", "WildMA", "PWMA"])
slcpowAlt = input.int(2, "PWMA Power", tooltip = PWMApT, inline = "SCLAltMA", group = SCLAltGP)
//SCL TF1 inputs
SCLTF1rangeuse = input.bool(false, "Enable SCL TF1", inline = "SCLTF1", group = SCLTF1GP)
slcTF1 = input.timeframe("1", " Timeframe", inline = "SCLTF1", group = SCLTF1GP)
slcTF1per = input.float(1.0, "%", step=0.1, minval=0, inline = "SCLTF11", group = SCLTF1GP)
slcTF1mainper = input(99, "Main P.", inline = "SCLTF11", group = SCLTF1GP)
slcTF1Sigper = input(7, "Signal P.", tooltip = SCLT, inline = "SCLTF11", group = SCLTF1GP)
slcTF1MAtype = input.string("SMA", "Moving Average Type", inline = "SCLTF1MA", group = SCLTF1GP,
options = ["SMA","EMA","HMA","WMA","VWMA","SMMA","DEMA","TEMA","ZEMA","SSMA","TMA","CCI","RSI","CMO", "WildMA", "PWMA"])
slcpowTF1 = input.int(2, "PWMA Power", tooltip = PWMApT, inline = "SCLTF1MA", group = SCLTF1GP)
//}
/////////////////////////////////////////// Scalping Line Multi TF Calculations ////////////////////////////////////////{
//TFC Calculations
//TFC double smoothed MA
var float sclTFCma = _ma(SCLsrc, slcTFCMAtype, math.ceil(slcTFCmainper/2), slcpowTFC)
sclMATFC = _ma(sclTFCma, slcTFCMAtype, math.floor(slcTFCmainper / 2) + 1, slcpowTFC)
//TFC ssMA
sclTFCssMA = sclMATFC>close+sclMATFC*slcTFCper/100 ? sclMATFC : sclMATFC<close-sclMATFC*slcTFCper/100 ? sclMATFC : close
//TFC Signal Line
sclTFCSigL = _ma(SCLsrc, slcTFCMAtype, slcTFCSigper, slcpowTFC)
//TFC Scalp Line
sclTFCSclpL = sclTFCSigL - sclTFCssMA
//
//Alt Calculations
slcAltmainperm = slcAltmainper * SCLResV
slcAltSigperm = slcAltSigper * SCLResV
//Alt double smoothed MA
var float sclAltma = _ma(SCLsrc, slcAltMAtype, math.ceil(slcAltmainperm/2), slcpowAlt)
sclMAAlt = _ma(sclAltma, slcAltMAtype, math.floor(slcAltmainperm / 2) + 1, slcpowAlt)
//Alt ssMA
sclAltssMA = sclMAAlt>close+sclMAAlt*slcAltper/100 ? sclMAAlt : sclMAAlt<close-sclMAAlt*slcAltper/100 ? sclMAAlt : close
//Alt Signal Line
sclAltSigL = _ma(SCLsrc, slcAltMAtype, slcAltSigperm, slcpowAlt)
//Alt Scalp Line
sclAltSclpL = sclAltSigL - sclAltssMA
//
//TF1 Calculations
//TF1 double smoothed MA
var float sclTF1ma = request.security(syminfo.tickerid, slcTF1, _ma (SCLsrc, slcTF1MAtype, math.ceil(slcTF1mainper / 2),slcpowTF1))
sclMATF1 = request.security(syminfo.tickerid, slcTF1, _ma (sclTF1ma, slcTF1MAtype, math.floor(slcTF1mainper / 2) + 1,slcpowTF1))
//FT1 SSMA
sclTF1ssMA = sclMATF1>request.security(syminfo.tickerid, slcTF1, close)+sclMATF1*slcTF1per/100 ? sclMATF1 :
sclMATF1<request.security(syminfo.tickerid, slcTF1, close)-sclMATF1*slcTF1per/100 ? sclMATF1 :
request.security(syminfo.tickerid, slcTF1, close)
//TF1 Signal Line
sclTF1SigL = request.security(syminfo.tickerid, slcTF1, _ma(SCLsrc, slcTF1MAtype, slcTF1Sigper, slcpowTF1))
//TF1 Scalp Line
sclTF1SclpL = sclTF1SigL - sclTF1ssMA
//}
/////////////////////////////////////////// Scalping Line Multi TF Conditions ////////////////////////////////////////{
//SCL TFC Conditions
SCLTFCLoID := sclTFCSclpL < 0
SCLTFCSoID := sclTFCSclpL > 0
SCLTFCLong := SCLTFCuse == false ? true : SCLTFCLoID
SCLTFCShort := SCLTFCuse == false ? true : SCLTFCSoID
_SigSCLTFCID := SCLTFCLoID ? 1 : SCLTFCSoID ? -1 : 0
_SigSCLTFC := SCLTFCLong ? 1 : SCLTFCShort ? -1 : 0
//SCL Alt Conditions
SCLAltLoID := sclAltSclpL < 0
SCLAltSoID := sclAltSclpL > 0
SCLAltLong := SCLAltuse == false ? true : SCLAltLoID
SCLAltShort := SCLAltuse == false ? true : SCLAltSoID
_SigSCLAltID := SCLAltLoID ? 1 : SCLAltSoID ? -1 : 0
_SigSCLAlt := SCLAltLong ? 1 : SCLAltShort ? -1 : 0
//SCL TF1 Conditions
SCLTF1LoID := sclTF1SclpL < 0
SCLTF1SoID := sclTF1SclpL > 0
SCLTF1Long := SCLTF1rangeuse == false ? true : SCLTF1LoID
SCLTF1Short := SCLTF1rangeuse == false ? true : SCLTF1SoID
_SigSCLTF1ID := SCLTF1LoID ? 1 : SCLTF1SoID ? -1 : 0
_SigSCLTF1 := SCLTF1Long ? 1 : SCLTF1Short ? -1 : 0
//}
/////////////////////////////////////////// Scalping Line Multi TF CTRL ////////////////////////////////////////{
//Value CTRL
// plot(sclTFCSclpL, "V_SCL.TFC", SCLTFCLoID ? green : SCLTFCSoID ? red : gray, display = dw_Y)
// plot(sclAltSclpL, "V_SCL.Alt", SCLAltLoID ? green : SCLAltSoID ? red : gray, display = dw_Y)
// plot(sclTF1SclpL, "V_SCL.TF1", SCLTF1LoID ? green : SCLTF1SoID ? red : gray, display = dw_Y)
//Signal ID CTRL
plot(_Sig_SLC_TFC == true ? 3 : na, "SCL.TFC", _SigSCLTFCID == 1 ? lime100 : _SigSCLTFCID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_SLC_Alt == true ? 33 : na, "SCL.Alt", _SigSCLAltID == 1 ? lime100 : _SigSCLAltID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_SLC_TF1 == true ? 33 : na, "SCL.TF1", _SigSCLTF1ID == 1 ? lime100 : _SigSCLTF1ID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// MA -- Trend confirmation --
//-----------------------------------------------------------------------------{ {MA}
//////////////////////////////////////////////// MA inputs ///////////////////////////////////////////////////////////
//MA universal source
masrc = input(close, "MA Universal source", tooltip = MAsrcT, group = MAGp)
//////////////////////////////////////////////// Open-Close-Cross ///////////////////////////////////////////////////{
//OCC Strategy inputs
maOCCuse = input.bool(false, "Enable O.C.C ", inline = "OCC1", group = MAOCCG)
maOCCDfuse = input.bool(false, "Diff?", inline = "OCC1", group = MAOCCG)
maOCCDfTre = input.float(0.1, " Threshold", inline = "OCC1", group = MAOCCG)
maOCClen = input.int(20, "Length", minval = 1, inline = "OCC1", group = MAOCCG)
maOCCresuse = input.bool(false, "Alternate Resolution? ", inline = "OCC2", group = MAOCCG)
maOCCAltRes = input.int(6, "Resolution Multiplier", inline = "OCC2", group = MAOCCG)
MAOCCtype = input.string("EMA", "Moving Average Type", inline = "OCCMA", group = MAOCCG,
options = ["SMA","EMA","HMA","WMA","VWMA","SMMA","DEMA","TEMA","ZEMA","SSMA","TMA","CCI","RSI","CMO", "WildMA", "PWMA"])
maOCCpow = input.int(2, "PWMA Power", tooltip = PWMApT, inline = "OCCMA", group = MAOCCG)
//O.C.C Calculations
maOCCres = maOCCresuse ? maOCCAltRes : 1
maClosSer = _ma(close, MAOCCtype, maOCClen, maOCCpow)
maOpenSer = _ma(open, MAOCCtype, maOCClen, maOCCpow)
maClosSerRs = _ma(close, MAOCCtype, maOCClen * maOCCres, maOCCpow)
maOpenSerRs = _ma(open, MAOCCtype, maOCClen * maOCCres, maOCCpow)
maOCCClosRsDf = maClosSerRs * 100 - maClosSerRs[1] * 100
maOCCOpenrsDf = maOpenSerRs * 100 - maOpenSerRs[1] * 100
//O.C.C Conditions
//O.C.C Range-Cross
MAOCCLoID := maClosSerRs > maOpenSerRs
MAOCCSoID := maClosSerRs < maOpenSerRs
MAOCCLong := maOCCuse == false ? true : MAOCCLoID
MAOCCShort := maOCCuse == false ? true : MAOCCSoID
_SigMAOCCID := MAOCCLoID ? 1 : MAOCCSoID ? -1 : 0
_SigMAOCC := MAOCCLong ? 1 : MAOCCShort ? -1 : 0
//O.C.C Diff
MAOCCDfLoID := maOCCClosRsDf >= maOCCDfTre or maOCCClosRsDf >= maOCCDfTre
MAOCCDfSoID := maOCCOpenrsDf <= maOCCDfTre * -1 or maOCCOpenrsDf <= maOCCDfTre * -1
MAOCCDfLong := maOCCDfuse == false ? true : MAOCCDfLoID
MAOCCDfShort := maOCCDfuse == false ? true : MAOCCDfSoID
_SigMAOCCDfID := MAOCCDfLoID ? 1 : MAOCCDfSoID ? -1 : 0
_SigMAOCCDf := MAOCCDfLong ? 1 : MAOCCDfShort ? -1 : 0
//O.C.C CTRL
// plot(maClosSerRs, "V_OCC.Close", MAOCCLoID ? green : MAOCCSoID ? red : gray, display = dw_Y)
// plot(maOpenSerRs, "V_OCC.Open", MAOCCLoID ? green : MAOCCSoID ? red : gray, display = dw_Y)
plot(_Sig_MA_OCCrng == true ? 4 : na, "OCC_Range", _SigMAOCCID == 1 ? lime100 : _SigMAOCCID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_MA_OCCDf == true ? 44 : na, "OCC_Diff", _SigMAOCCDfID == 1? lime100 : _SigMAOCCDfID == -1? red100 : gray100, display = dw_Y, precision = 0)
//}
//////////////////////////////////////////////// Corrected MA ////////////////////////////////////////////////////////{
//Corrected MA inputs
maCcrsuse = input.bool(false, "Cross?", inline = "CMA", group = MACGp)
maCDfuse = input.bool(false, "Diff?", inline = "CMA", group = MACGp)
maCDfTre = input.float(0.1, "Threshold", inline = "CMA", group = MACGp)
maClen = input.int(35, "Length", minval = 1, inline = "CMA", group = MACGp)
maCtype = input.string("SMA", "Moving Average Type", inline = "CMAMA", group = MACGp,
options = ["SMA","EMA","HMA","WMA","VWMA","SMMA","DEMA","TEMA","ZEMA","SSMA","TMA","CCI","RSI","CMO", "WildMA", "PWMA"])
maCpow = input.int(2, "PWMA Power", tooltip = PWMApT, inline = "CMAMA", group = MACGp)
//Corrected MA calculations
maC = _ma(masrc, maCtype, maClen, maCpow)
cma = maC
v1 = ta.variance(masrc, maClen)
v2 = math.pow(nz(cma[1], cma) - maC, 2)
v3 = v1 == 0 or v2 == 0 ? 1 : v2 / (v1 + v2)
var tolerance = math.pow(10, -5)
float err = 1
// Gain Factor
float kPrev = 1
float k = 1
for i = 0 to 5000
if err > tolerance
k := v3 * kPrev * (2 - kPrev)
err := kPrev - k
kPrev := k
cma := nz(cma[1], masrc) + k * (maC - nz(cma[1], masrc))
//Corrected MA Conditions
//CMA Cross
MACcrsLoID := maC > cma
MACcrsSoID := maC < cma
MACcrsLong := maCcrsuse == false ? true : MACcrsLoID
MACcrsShort := maCcrsuse == false ? true : MACcrsSoID
_SigMACcrsID := MACcrsLoID ? 1 : MACcrsSoID ? -1 : 0
_SigMACcrs := MACcrsLong ? 1 : MACcrsShort ? -1 : 0
//CMA Df
float cmaDf = cma *100 - cma[1] * 100
MACDfLoID := cmaDf >= maCDfTre
MACDfSoID := cmaDf <= maCDfTre * -1
MACDfLong := maCDfuse == false ? true : MACDfLoID
MACDfShort := maCDfuse == false ? true : MACDfSoID
_SigMACDfID := MACDfLoID ? 1 : MACDfSoID ? -1 : 0
_SigMACDfID := MACDfLoID ? 1 : MACDfSoID ? -1 : 0
//Corrected MA CTRL
// plot(cma, "V_CMA", MACDfLoID ? green : MACDfSoID ? red : gray, display = dw_Y)
// plot(cma, "V_CMA_DfV", MACDfLoID ? green : MACDfSoID ? red : gray, display = dw_Y)
plot(_Sig_CMA_Crs == true ? 5 : na, "CMA.Cross", _SigMACcrsID == 1 ? lime100 : _SigMACcrsID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
plot(_Sig_CMA_Df == true ? 55 : na, "CMA.Df", _SigMACDfID == 1 ? lime100 : _SigMACDfID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
//}
//////////////////////////////////////////////// MA Filter ////////////////////////////////////////////////////////////{
//MA Filter inputs
mafltruse = input.bool(false, "Enable MA Filter", inline = "MAF", group = MAfltrGp)
mafltrlen = input.int(50, " Length", minval = 1, inline = "MAF", group = MAfltrGp)
mafltxtruse = input.bool(false, "Extreme?", tooltip= MAfltlxtT, inline = "MAF", group = MAfltrGp)
MAfltrtype = input.string("EMA", "Moving Average Type", inline = "MAFMA", group = MAfltrGp,
options = ["SMA","EMA","HMA","WMA","VWMA","SMMA","DEMA","TEMA","ZEMA","SSMA","TMA","CCI","RSI","CMO", "WildMA", "PWMA"])
mafltrpow = input.int(2, "PWMA Power", tooltip = PWMApT, inline = "MAFMA", group = MAfltrGp)
//MA Filter calculations
float MAfltr = _ma(masrc, MAfltrtype, mafltrlen, mafltrpow)
MAfltsrcLoTB = mafltxtruse ? low : close
MAfltsrcSoTB = mafltxtruse ? high : close
//MA Filter conditions
MAfltrLoID := MAfltr < MAfltsrcLoTB
MAfltrSoID := MAfltr > MAfltsrcSoTB
MAfltrLong := mafltruse == false ? true : MAfltrLoID
MAfltrShort := mafltruse == false ? true : MAfltrSoID
_SigMAfltrID := MAfltrLoID ? 1 : MAfltrSoID ? -1 : 0
_SigMAfltr := MAfltrLong ? 1 : MAfltrShort ? -1 : 0
//MA Filter CTRL
// plot(MAfltr, "V_MA.Filter", MAfltrLoID ? green : MAfltrSoID ? red : gray, display = dw_Y)
plot(_Sig_MA_fltr == true ? 6 : na, "MA.Filter", _SigMAfltrID == 1 ? lime100 : _SigMAfltrID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
//}
//////////////////////////////////////////////// MA Diff //////////////////////////////////////////////////////////////{
//MA Diff inputs
maDfuse = input.bool(false, "Enable MA Df", inline = "MADf", group = MADfGp)
maDfTre = input.float(0.1, "Threshold", inline = "MADf", group = MADfGp)
maDflen = input.int(20, " Length", minval = 1, inline = "MADf", group = MADfGp)
MADftype = input.string("EMA", "Moving Average Type", inline = "MADfMA", group = MADfGp,
options = ["SMA","EMA","HMA","WMA","VWMA","SMMA","DEMA","TEMA","ZEMA","SSMA","TMA","CCI","RSI","CMO", "WildMA", "PWMA"])
maDfpow = input.int(2, "PWMA Power", tooltip = PWMApT, inline = "MADfMA", group = MADfGp)
//MA Diff calculations
float MADf = _ma(masrc, MADftype, maDflen, maDfpow)
_MA_Df = MADf*100 - MADf[1]*100
//MA Diff conditions
MADfLoID := _MA_Df >= maDfTre
MADfSoID := _MA_Df <= maDfTre * -1
MADfLong := maDfuse == false ? true : MADfLoID
MADfShort := maDfuse == false ? true : MADfSoID
_SigMADfID := MADfLoID ? 1 : MADfSoID ? -1 : 0
_SigMADf := MADfLong ? 1 : MADfShort ? -1 : 0
//MA Diff CTRL
// plot(MADf, "V_MA.Diff", MADfLoID ? green : MADfSoID ? red : gray, display = dw_Y)
plot(_Sig_MA_Df == true ? 7 : na, "MA.Filter", _SigMADfID == 1 ? lime100 : _SigMADfID == -1 ? red100 : gray100, display = dw_Y, precision = 0)
//}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------
// Chandelier Exit -- Trend confirmation --
//-----------------------------------------------------------------------------{ {Chandelier Exit}
//////////////////////////////////////////////// CE inputs ///////////////////////////////////////////////////////////{
ceuse = input.bool(false, "Enable Chandelier Exit", inline = "CE", group=CEGp)
cepr = input(22, "", inline = "CE", group=CEGp)
cemult = input(3, "", inline = "CE", group=CEGp)