-
Notifications
You must be signed in to change notification settings - Fork 7
/
Moving Averages Refurbished.pine
1453 lines (1317 loc) · 70.6 KB
/
Moving Averages Refurbished.pine
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
// @author=andre_007
// @version=5
// @Author andre_007
// @description Moving Averages Refurbished
// @License This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @Thanks and credits:
// TradingView
// PineCoders
// CrackingCryptocurrency
// MightyZinger
// Alex Orekhov (everget)
// alexgrover
// paragjyoti2012
// Franklin Moormann (cheatcountry)
indicator(title='Moving Averages Refurbished', shorttitle='MAR', format=format.inherit, overlay=true)
import andre_007/MovingAveragesProxy/1 as MaProxy
// ———————————————————————————————————————— Only for benchmark {
// import PineCoders/LibraryStopwatch/1 as Stopwatch // Only for debug
// [timePerBarInMs, totalTimeInMs, barsTimed, barsNotTimed] = Stopwatch.stopwatchStats()
// msElapsed = Stopwatch.stopwatch()
// ———————————————————————————————————————— }
// ———————————————————————————————————————— Only for Debug {
// import paragjyoti2012/LoggerLib/5 as Logger
// var logger=Logger.init()
// var logTable=Logger.initTable(logger, max_rows_count=15, offset=0, position='left', size='small', hide_date=false, stickyRows=0)
// ———————————————————————————————————————— }
// ———————————————————————————————————————— Constants {
// --> Rolling VWAP
var string TT_WINDOW = "By default, the time period used to calculate the RVWAP automatically adjusts with the chart's timeframe.
Check this to use a fixed-size time period instead, which you define with the following three values."
var string TT_MINBARS = "The minimum number of last values to keep in the moving window, even if these values are outside the time period.
This avoids situations where a large time gap between two bars would cause the time window to be empty."
var string GRP2 = 'Exclusive for Rolling VWAP'
// <--
// Moving Averages Types
var string AARMA = 'Adaptive Autonomous Recursive Moving Average'
var string ADEMA = '* Alpha-Decreasing Exponential Moving Average'
var string AHMA = 'Ahrens Moving Average'
var string ALMA = 'Arnaud Legoux Moving Average'
var string ALSMA = 'Adaptive Least Squares'
var string AUTOL = 'Auto-Line'
var string CMA = 'Corrective Moving average'
var string CORMA = 'Correlation Moving Average Price'
var string COVWEMA = 'Coefficient of Variation Weighted Exponential Moving Average'
var string COVWMA = 'Coefficient of Variation Weighted Moving Average'
var string DEMA = 'Double Exponential Moving Average'
var string DONCHIAN = 'Donchian Middle Channel'
var string EDMA = 'Exponentially Deviating Moving Average'
var string EDSMA = 'Ehlers Dynamic Smoothed Moving Average'
var string EFRAMA = '* Ehlrs Modified Fractal Adaptive Moving Average'
var string EHMA = 'Exponential Hull Moving Average'
var string EMA = 'Exponential Moving Average'
var string EPMA = 'End Point Moving Average'
var string ETMA = 'Exponential Triangular Moving Average'
var string EVWMA = 'Elastic Volume Weighted Moving Average'
var string FAMA = 'Following Adaptive Moving Average'
var string FIBOWMA = 'Fibonacci Weighted Moving Average'
var string FISHLSMA = 'Fisher Least Squares Moving Average'
var string FRAMA = 'Fractal Adaptive Moving Average'
var string GMA = 'Geometric Moving Average'
var string HKAMA = 'Hilbert based Kaufman\'s Adaptive Moving Average'
var string HMA = 'Hull Moving Average'
var string JURIK = 'Jurik Moving Average'
var string KAMA = 'Kaufman\'s Adaptive Moving Average'
var string LC_LSMA = '1LC-LSMA (1 line code lsma with 3 functions)'
var string LEOMA = 'Leo Moving Average'
var string LINWMA = 'Linear Weighted Moving Average'
var string LSMA = 'Least Squares Moving Average'
var string MAMA = 'MESA Adaptive Moving Average'
var string MCMA = 'McNicholl Moving Average'
var string MEDIAN = 'Median'
var string REGMA = 'Regularized Exponential Moving Average'
var string REMA = 'Range EMA'
var string REPMA = 'Repulsion Moving Average'
var string RMA = 'Relative Moving Average'
var string RSIMA = 'RSI Moving average'
var string RVWAP = '* Rolling VWAP'
var string SMA = 'Simple Moving Average'
var string SMMA = 'Smoothed Moving Average'
var string SRWMA = 'Square Root Weighted Moving Average'
var string SW_MA = 'Sine-Weighted Moving Average'
var string SWMA = '* Symmetrically Weighted Moving Average'
var string TEMA = 'Triple Exponential Moving Average'
var string THMA = 'Triple Hull Moving Average'
var string TREMA = 'Triangular Exponential Moving Average'
var string TRSMA = 'Triangular Simple Moving Average'
var string TT3 = 'Tillson T3'
var string VAMA = 'Volatility Adjusted Moving Average'
var string VIDYA = 'Variable Index Dynamic Average'
var string VWAP = '* VWAP'
var string VWMA = 'Volume-weighted Moving Average'
var string WMA = 'Weighted Moving Average'
var string WWMA = 'Welles Wilder Moving Average'
var string XEMA = 'Optimized Exponential Moving Average'
var string ZEMA = 'Zero-Lag Exponential Moving Average'
var string ZSMA = 'Zero-Lag Simple Moving Average'
// --> Tooltips
var string TOOLTIP_SAME_PARAMS = 'Check this to apply same type, source and offset for all moving averages.\n' +
'For moving averages with * the length parameter does not apply.\n' +
'These types can only be setted individually.'
var string TOOLTIP_PREDEFINED_PERIODS = '🟩 Defined by user: each period in parameters below take precedence. Otherwise, these periods don\'t take effect.\n' +
'🟩 Arithmetic Progression: set the periods in increments of n, for example, 5, 10, 15,..., where n = 5.\n' +
'🟩 Tradicional: set the periods to some important numbers: 8, 21, 50, 100, 200, 365 (one year), 730 (two years), etc.\n' +
'🟩 Fibonacci: set the periods in increments of Fibonacci: 3, 5, 8, 13, 21,...,233, etc. The limit is 2584.\n' +
'🟩 200 for All: set all the periods with 200. For this parameter to make sense, it is necessary to configure each averaging to a different type.'
var string TOOLTIP_ALMA = '◆ Offset: this is considered in the formula, not in the graphic! Offset is the Gaussian applied to the combo line and it is 0.85 by default.\nSetting offset at 1 makes it fully aligned to the current price just like the exponential moving average.\nWhile setting it to zero makes it just like a simple moving average.\nTraders may try offset combinations according to their own needs and preferences.\n\n◆ Sigma: the standard deviation applied to the combo line. It makes the combo line sharper.'
var string TOOLTIP_COLOR_AVERAGE = 'Examples:\n🟩 Moving average 1 > moving average 2 is defined by green.\n🟥 Moving average 1 < moving average 2 is defined by red.'
// --> Predefined periods of Moving Averages
var string PREDEFINED_PERIODS_1 = 'Defined by user'
var string PREDEFINED_PERIODS_2 = 'Arithmetic Progression of 5'
var string PREDEFINED_PERIODS_3 = 'Arithmetic Progression of 7'
var string PREDEFINED_PERIODS_4 = 'Arithmetic Progression of 8'
var string PREDEFINED_PERIODS_5 = 'Arithmetic Progression of 9'
var string PREDEFINED_PERIODS_6 = 'Arithmetic Progression of 10'
var string PREDEFINED_PERIODS_7 = 'Arithmetic Progression of 16'
var string PREDEFINED_PERIODS_8 = 'Arithmetic Progression of 20'
var string PREDEFINED_PERIODS_9 = 'Arithmetic Progression of 30'
var string PREDEFINED_PERIODS_10 = 'Arithmetic Progression of 32'
var string PREDEFINED_PERIODS_11 = 'Arithmetic Progression of 50'
var string PREDEFINED_PERIODS_12 = 'Arithmetic Progression of 64'
var string PREDEFINED_PERIODS_13 = 'Tradicional: 8, 21, 50, 100, 200, 365, 730, 1095, 1460, 1825, 2190'
var string PREDEFINED_PERIODS_14 = 'Fibonacci'
var string PREDEFINED_PERIODS_15 = '200 for All'
// --> Colors (Defined by User) (Default)
// Bull
var color COLOR_BULL_01 = #3af13c
var color COLOR_BULL_02 = #00e85f
var color COLOR_BULL_03 = #00de7e
var color COLOR_BULL_04 = #00d39c
var color COLOR_BULL_05 = #00c7b6
var color COLOR_BULL_06 = #00bace
var color COLOR_BULL_07 = #00ace2
var color COLOR_BULL_08 = #009ef0
var color COLOR_BULL_09 = #0090f7
var color COLOR_BULL_10 = #0080f7
var color COLOR_BULL_11 = #0079fa
var color COLOR_BULL_12 = #0072fd
var color COLOR_BULL_13 = #006aff
var color COLOR_BULL_14 = #0062ff
var color COLOR_BULL_15 = #0059ff
var color COLOR_BULL_16 = #004fff
var color COLOR_BULL_17 = #0044ff
var color COLOR_BULL_18 = #0038ff
var color COLOR_BULL_19 = #0028ff
var color COLOR_BULL_20 = #000cff
// Bear
var color COLOR_BEAR_01 = #ff0000
var color COLOR_BEAR_02 = #fc1c1a
var color COLOR_BEAR_03 = #f82c2a
var color COLOR_BEAR_04 = #f43837
var color COLOR_BEAR_05 = #ef4343
var color COLOR_BEAR_06 = #f5513b
var color COLOR_BEAR_07 = #fa5f31
var color COLOR_BEAR_08 = #fd6d26
var color COLOR_BEAR_09 = #ff7c18
var color COLOR_BEAR_10 = #ff8a00
var color COLOR_BEAR_11 = #ff9900
var color COLOR_BEAR_12 = #ffa700
var color COLOR_BEAR_13 = #ffb600
var color COLOR_BEAR_14 = #ffc400
var color COLOR_BEAR_15 = #ffd200
var color COLOR_BEAR_16 = #f6d028
var color COLOR_BEAR_17 = #eecd3b
var color COLOR_BEAR_18 = #e6cb4b
var color COLOR_BEAR_19 = #dec858
var color COLOR_BEAR_20 = #d7c564
// ———————————————————————————————————————— }
// ———————————————————————————————————————— Global Variables {
// Default parameters for all moving averages
var bool inputSameParams = true
var string inputTypeAll = 'REGMA'
var float inputSourceAll = close
var int inputOffsetAll = 0
// Length of Moving Averages
var int lenMa1 = 5
var int lenMa2 = 10
var int lenMa3 = 15
var int lenMa4 = 20
var int lenMa5 = 25
var int lenMa6 = 30
var int lenMa7 = 35
var int lenMa8 = 40
var int lenMa9 = 45
var int lenMa10 = 50
var int lenMa11 = 55
var int lenMa12 = 60
var int lenMa13 = 65
var int lenMa14 = 70
var int lenMa15 = 75
var int lenMa16 = 80
var int lenMa17 = 85
var int lenMa18 = 90
var int lenMa19 = 95
var int lenMa20 = 95
// Calculations of Moving Averages
float movingAverage1 = na
float movingAverage2 = na
float movingAverage3 = na
float movingAverage4 = na
float movingAverage5 = na
float movingAverage6 = na
float movingAverage7 = na
float movingAverage8 = na
float movingAverage9 = na
float movingAverage10 = na
float movingAverage11 = na
float movingAverage12 = na
float movingAverage13 = na
float movingAverage14 = na
float movingAverage15 = na
float movingAverage16 = na
float movingAverage17 = na
float movingAverage18 = na
float movingAverage19 = na
float movingAverage20 = na
// Bar Colors
color barColor = na
var string inputTheme = 'Defined by user'
var int inputColorFillTransparency = 90
// ———————————————————————————————————————— }
// ———————————————————————————————————————— Global inputs {
var string GROUP_ALL = '🔴🔴🔴🔴 Parameters for all Moving Averages'
inputSameParams := input.bool(title='Same parameters for all moving averages?',
defval=true, tooltip=TOOLTIP_SAME_PARAMS, inline='01', group=GROUP_ALL)
inputTypeAll := input.string(title='Type', defval=REGMA,
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='02', group=GROUP_ALL)
inputSourceAll := input.source(title='Source', defval=close, inline='03', group=GROUP_ALL)
inputOffsetAll := input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='03', group=GROUP_ALL)
var string GRP_AARMA = 'Adaptive Autonomous Recursive Moving Average'
var float gamma_aarma = input.float(3, "Gamma", group=GRP_AARMA)
var string GRP_ALSMA = 'Adaptive Least Squares Moving Average'
var float smooth = input.float(1.5, "Smooth", group=GRP_ALSMA)
var string GROUP_ALMA = 'Arnaud Legoux Moving Average (ALMA)'
inputAlmaOffset = input.float(title='Offset', defval=0.85, group=GROUP_ALMA, inline='04')
inputAlmaSigma = input.float(title='Sigma', defval=6, group=GROUP_ALMA, inline='04', tooltip=TOOLTIP_ALMA)
var string GRP_CORR = 'Correlation Moving Average'
var string GRP_CORR_TOOLTIP = 'Number multiplied after calculating correlation + standard deviation.'
var float factor = input.float(1.7, "Factor", group=GRP_CORR, tooltip=GRP_CORR_TOOLTIP)
var string GRP_EHLR = 'Ehlrs Modified Fractal Adaptive Moving Average'
var int fc = input.int(8, 'Lower Shift Limit', group=GRP_EHLR)
var int sc = input.int(8, 'Upper Shift Limit', group=GRP_EHLR)
var string GRP_EPMA = 'End Point Moving Average'
offset_epma = input.int(title="Offset", defval=4, group=GRP_EPMA)
var string GRP_JURIK = 'Jurik Moving Average'
var int jurik_phase = input.int(3, "Phase", group=GRP_JURIK)
var int jurik_power = input.int(1, "Power", group=GRP_JURIK)
var string GRP_LWMA = 'Linear Weighted Moving Average'
lwma_weight = input.int(6, title = "Weight", minval=1, step=1, group=GRP_LWMA)
var string GRP_REGMA = 'Regularized Exponential Moving Average'
var string GRP_REGMA_TOOLTIP = 'A factor that controls the \"regularization\" amount. When the Lambda value is set to zero, the Regularized Exponential Moving Average becomes the standard EMA.'
var float lambda = input.float(0.5, "Lambda", group=GRP_REGMA, tooltip=GRP_REGMA_TOOLTIP)
var string GRP_RVWAP = 'Rolling VWAP'
bool _fixedTfInput = input.bool(false, "Use a fixed time period", group = GRP_RVWAP, tooltip = TT_WINDOW, inline='1')
int _daysInput = input.int(1, "Days", minval = 0, maxval = 90, group = GRP_RVWAP, inline='2')
int _hoursInput = input.int(0, "Hours", minval = 0, maxval = 23, group = GRP_RVWAP, inline='2')
int _minsInput = input.int(0, "Minutes", minval = 0, maxval = 59, group = GRP_RVWAP, inline='2')
int _minBarsInput = input.int(10, "Bars", group = GRP_RVWAP, tooltip = TT_MINBARS, inline='3')
var string GRP_T3 = 'Tillson T3'
var float a1_t3 = input.float(0.7, 'Volume factor', group=GRP_T3)
var string GRP_VADMA = 'Volatility Adjusted Moving Average'
var string GRP_VADMA_TOOLTIP = 'Volatility loopback'
var int volatility_lookback = input.int(10, 'Loopback', minval=1, step=1, group=GRP_VADMA, tooltip=GRP_VADMA_TOOLTIP)
var string GRP_VWMA = 'Volume Weighted Moving Average'
var string GRP_VWMA_TOOLTIP = 'The most common "Volume Weighted Moving Average" is a Simple Moving Average of Price x Volume, divided by Simple Moving Average of Volume. \n' +
'Enabling this checkbox, it\'s possible to have other types and less common moving averages weighted by volume, for example, Exponencial Volume Weighted Moving Average, Alma Volume Weighted Moving Average, etc...'
applyVolumeWeighted = input.bool(title="Volume Weighted Moving Average?", defval=false, group=GRP_VWMA, tooltip=GRP_VWMA_TOOLTIP)
var string GROUP_AVERAGE_COLORS = 'Colors and theme'
inputTheme := input.string(defval='Classic', title='Theme',
options = ['Defined by user', 'Classic', 'Deep Purple', 'Sweden', 'Ocean', 'Monokai'],
tooltip='Theme for color lines', inline='05', group=GROUP_AVERAGE_COLORS)
var string color_A = 'moving average is below or above the next moving average'
var string color_B = 'price is below or above the next moving average'
var inputApplyAverageColors = input.bool(title="Change line colors?",
defval=true, inline='06', group=GROUP_AVERAGE_COLORS, tooltip=TOOLTIP_COLOR_AVERAGE)
var string avgColorLogic = input.string(defval=color_A, title='When', inline='06', group=GROUP_AVERAGE_COLORS, options=[color_A, color_B])
var bool inputFill = input.bool(title='Fill background between averages?', defval=false, inline='07', group=GROUP_AVERAGE_COLORS)
inputColorFillTransparency := input.int(defval=90 , title="Transparency for fill", minval=0, maxval=100, inline = "08", group=GROUP_AVERAGE_COLORS)
var string GROUP_BAR_COLORS = 'Bar Colors'
var inputApplyBarColorsLinesAligned = input.bool(title="Apply Bar Colors when price are above or bellow all MAs?", defval=false, inline='10', group=GROUP_BAR_COLORS)
var inputBarColorBullLinesAligned = input.color(#3af13c, 'Bullish', inline='11', group=GROUP_BAR_COLORS)
var inputBarColorBearLinesAligned = input.color(#bd0000, 'Bearish', inline='11', group=GROUP_BAR_COLORS)
// ———————————————————————————————————————— }
// ———————————————————————————————————————— Functions {
// @function applyType
// @description Utilitarian function that returns the global type of moving averges or individual types
// @param type Type of Moving Average
// @returns Type of Moving Average
applyType(type) =>
typeOut = inputSameParams ? inputTypeAll : type
typeOut
// @function applySource
// @description Utilitarian function that returns the global source of moving averges or individual sources
// @param src Source of series (close, high, low, etc.)
// @returns Source of Moving Average
applySource(src) =>
srcOut = inputSameParams ? inputSourceAll : src
srcOut
// @function applyOffset
// @description Utilitarian function that returns the global offset of moving averges or individual offsets
// @param offset Offset of Moving Average
// @returns Offset of Moving Average
applyOffset(offset) =>
offsetOut = inputSameParams ? inputOffsetAll : offset
offsetOut
// @function applyColorMovingAverage
// @description Returns a bull color if first average is greater than second average, otherwise returns a bear color.
// @param ma1 First moving average
// @param ma2 Second moving average
// @param colorBull Color used when first average is greater than second average
// @param colorBear Color used when first average is less than second average
// @param src Price source
// @returns Color
applyColorMovingAverage(series float ma1, series float ma2, color colorBull, color colorBear, series float src) =>
color colorMA = switch inputApplyAverageColors
true =>
if (avgColorLogic == color_A ? ma1 : src) >= ma2
colorBull
else
colorBear
false =>
colorBull
// @function applyBarColor
// @description Returns a bull color if price source is greater than all moving averages
// Otherwise returns a bear color.
// @param src Source of series (close, high, low, etc.)
// @returns Color
applyBarColor(float src) =>
color _barColor = na
_barColor := if inputApplyBarColorsLinesAligned
if src >= nz(movingAverage1) and
src >= nz(movingAverage2) and
src >= nz(movingAverage3) and
src >= nz(movingAverage4) and
src >= nz(movingAverage5) and
src >= nz(movingAverage6) and
src >= nz(movingAverage7) and
src >= nz(movingAverage8) and
src >= nz(movingAverage9) and
src >= nz(movingAverage10) and
src >= nz(movingAverage11) and
src >= nz(movingAverage12) and
src >= nz(movingAverage13) and
src >= nz(movingAverage14) and
src >= nz(movingAverage15) and
src >= nz(movingAverage16) and
src >= nz(movingAverage17) and
src >= nz(movingAverage18) and
src >= nz(movingAverage19) and
src >= nz(movingAverage20)
inputBarColorBullLinesAligned
else if src <= nz(movingAverage1, src) and
src <= nz(movingAverage2, src) and
src <= nz(movingAverage3, src) and
src <= nz(movingAverage4, src) and
src <= nz(movingAverage5, src) and
src <= nz(movingAverage6, src) and
src <= nz(movingAverage7, src) and
src <= nz(movingAverage8, src) and
src <= nz(movingAverage9, src) and
src <= nz(movingAverage10, src) and
src <= nz(movingAverage11, src) and
src <= nz(movingAverage12, src) and
src <= nz(movingAverage13, src) and
src <= nz(movingAverage14, src) and
src <= nz(movingAverage15, src) and
src <= nz(movingAverage16, src) and
src <= nz(movingAverage17, src) and
src <= nz(movingAverage18, src) and
src <= nz(movingAverage19, src) and
src <= nz(movingAverage20, src)
inputBarColorBearLinesAligned
// ———————————————————————————————————————— }
// ———————————————————————————————————————— Inputs {
string GROUP_AVG = '🔴🔴🔴🔴🔴 Moving Averages'
var string inputPredefinedPeriods = input.string(PREDEFINED_PERIODS_1,
'Predefined Periods',
options=[
PREDEFINED_PERIODS_1,
PREDEFINED_PERIODS_2,
PREDEFINED_PERIODS_3,
PREDEFINED_PERIODS_4,
PREDEFINED_PERIODS_5,
PREDEFINED_PERIODS_6,
PREDEFINED_PERIODS_7,
PREDEFINED_PERIODS_8,
PREDEFINED_PERIODS_9,
PREDEFINED_PERIODS_10,
PREDEFINED_PERIODS_11,
PREDEFINED_PERIODS_12,
PREDEFINED_PERIODS_13,
PREDEFINED_PERIODS_14,
PREDEFINED_PERIODS_15],
inline='09', group=GROUP_AVG, tooltip=TOOLTIP_PREDEFINED_PERIODS)
// ————— Average 1
bool inputShowAvg1 = input.bool(title='Moving Average 1', defval=true, inline='12', group=GROUP_AVG)
color inputColorBull1 = input.color(COLOR_BULL_01, '', inline='12', group=GROUP_AVG)
color inputColorBear1 = input.color(COLOR_BEAR_01, '', inline='12', group=GROUP_AVG)
string inputTypeMa1 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='13', group=GROUP_AVG)
int inputLengthMa1 = input.int(5, minval=1, title='Length', inline='13', group=GROUP_AVG)
float inputSourceMa1 = input.source(close, title='Source', inline='14', group=GROUP_AVG)
int inputOffsetMa1 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='14', group=GROUP_AVG)
// ————— Average 2
bool inputShowAvg2 = input.bool(title='Moving Average 2', defval=true, inline='15', group=GROUP_AVG)
color inputColorBull2 = input.color(COLOR_BULL_02, '', inline='15', group=GROUP_AVG)
color inputColorBear2 = input.color(COLOR_BEAR_02, '', inline='15', group=GROUP_AVG)
string inputTypeMa2 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='16', group=GROUP_AVG)
int inputLengthMa2 = input.int(10, minval=1, title='Length', inline='16', group=GROUP_AVG)
float inputSourceMa2 = input.source(close, title='Source', inline='17', group=GROUP_AVG)
int inputOffsetMa2 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='17', group=GROUP_AVG)
// ————— Average 3
bool inputShowAvg3 = input.bool(title='Moving Average 3', defval=true, inline='18', group=GROUP_AVG)
color inputColorBull3 = input.color(COLOR_BULL_03, '', inline='18', group=GROUP_AVG)
color inputColorBear3 = input.color(COLOR_BEAR_03, '', inline='18', group=GROUP_AVG)
string inputTypeMa3 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='19', group=GROUP_AVG)
int inputLengthMa3 = input.int(15, minval=1, title='Length', inline='19', group=GROUP_AVG)
float inputSourceMa3 = input.source(close, title='Source', inline='20', group=GROUP_AVG)
int inputOffsetMa3 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='20', group=GROUP_AVG)
// ————— Average 4
bool inputShowAvg4 = input.bool(title='Moving Average 4', defval=true, inline='21', group=GROUP_AVG)
color inputColorBull4 = input.color(COLOR_BULL_04, '', inline='21', group=GROUP_AVG)
color inputColorBear4 = input.color(COLOR_BEAR_04, '', inline='21', group=GROUP_AVG)
string inputTypeMa4 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='22', group=GROUP_AVG)
int inputLengthMa4 = input.int(20, minval=1, title='Length', inline='22', group=GROUP_AVG)
float inputSourceMa4 = input.source(close, title='Source', inline='23', group=GROUP_AVG)
int inputOffsetMa4 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='23', group=GROUP_AVG)
// ————— Average 5
bool inputShowAvg5 = input.bool(title='Moving Average 5', defval=true, inline='24', group=GROUP_AVG)
color inputColorBull5 = input.color(COLOR_BULL_05, '', inline='24', group=GROUP_AVG)
color inputColorBear5 = input.color(COLOR_BEAR_05, '', inline='24', group=GROUP_AVG)
string inputTypeMa5 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='25', group=GROUP_AVG)
int inputLengthMa5 = input.int(25, minval=1, title='Length', inline='25', group=GROUP_AVG)
float inputSourceMa5 = input.source(close, title='Source', inline='26', group=GROUP_AVG)
int inputOffsetMa5 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='26', group=GROUP_AVG)
// ————— Average 6
bool inputShowAvg6 = input.bool(title='Moving Average 6', defval=true, inline='27', group=GROUP_AVG)
color inputColorBull6 = input.color(COLOR_BULL_06, '', inline='27', group=GROUP_AVG)
color inputColorBear6 = input.color(COLOR_BEAR_06, '', inline='27', group=GROUP_AVG)
string inputTypeMa6 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='28', group=GROUP_AVG)
int inputLengthMa6 = input.int(30, minval=1, title='Length', inline='28', group=GROUP_AVG)
float inputSourceMa6 = input.source(close, title='Source', inline='29', group=GROUP_AVG)
int inputOffsetMa6 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='29', group=GROUP_AVG)
// ————— Average 7
bool inputShowAvg7 = input.bool(title='Moving Average 7', defval=true, inline='30', group=GROUP_AVG)
color inputColorBull7 = input.color(COLOR_BULL_07, '', inline='30', group=GROUP_AVG)
color inputColorBear7 = input.color(COLOR_BEAR_07, '', inline='30', group=GROUP_AVG)
string inputTypeMa7 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='31', group=GROUP_AVG)
int inputLengthMa7 = input.int(35, minval=1, title='Length', inline='31', group=GROUP_AVG)
float inputSourceMa7 = input.source(close, title='Source', inline='32', group=GROUP_AVG)
int inputOffsetMa7 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='32', group=GROUP_AVG)
// ————— Average 8
bool inputShowAvg8 = input.bool(title='Moving Average 8', defval=true, inline='33', group=GROUP_AVG)
color inputColorBull8 = input.color(COLOR_BULL_08, '', inline='33', group=GROUP_AVG)
color inputColorBear8 = input.color(COLOR_BEAR_08, '', inline='33', group=GROUP_AVG)
string inputTypeMa8 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='34', group=GROUP_AVG)
int inputLengthMa8 = input.int(40, minval=1, title='Length', inline='34', group=GROUP_AVG)
float inputSourceMa8 = input.source(close, title='Source', inline='35', group=GROUP_AVG)
int inputOffsetMa8 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='35', group=GROUP_AVG)
// ————— Average 9
bool inputShowAvg9 = input.bool(title='Moving Average 9', defval=true, inline='36', group=GROUP_AVG)
color inputColorBull9 = input.color(COLOR_BULL_09, '', inline='36', group=GROUP_AVG)
color inputColorBear9 = input.color(COLOR_BEAR_09, '', inline='36', group=GROUP_AVG)
string inputTypeMa9 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='37', group=GROUP_AVG)
int inputLengthMa9 = input.int(45, minval=1, title='Length', inline='37', group=GROUP_AVG)
float inputSourceMa9 = input.source(close, title='Source', inline='38', group=GROUP_AVG)
int inputOffsetMa9 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='38', group=GROUP_AVG)
// ————— Average 10
bool inputShowAvg10 = input.bool(title='Moving Average 10', defval=true, inline='39', group=GROUP_AVG)
color inputColorBull10 = input.color(COLOR_BULL_10, '', inline='39', group=GROUP_AVG)
color inputColorBear10 = input.color(COLOR_BEAR_10, '', inline='39', group=GROUP_AVG)
string inputTypeMa10 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='40', group=GROUP_AVG)
int inputLengthMa10 = input.int(50, minval=1, title='Length', inline='40', group=GROUP_AVG)
float inputSourceMa10 = input.source(close, title='Source', inline='41', group=GROUP_AVG)
int inputOffsetMa10 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='41', group=GROUP_AVG)
// ————— Average 11
bool inputShowAvg11 = input.bool(title='Moving Average 11', defval=true, inline='42', group=GROUP_AVG)
color inputColorBull11 = input.color(COLOR_BULL_11, '', inline='42', group=GROUP_AVG)
color inputColorBear11 = input.color(COLOR_BEAR_11, '', inline='42', group=GROUP_AVG)
string inputTypeMa11 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='43', group=GROUP_AVG)
int inputLengthMa11 = input.int(55, minval=1, title='Length', inline='43', group=GROUP_AVG)
float inputSourceMa11 = input.source(close, title='Source', inline='44', group=GROUP_AVG)
int inputOffsetMa11 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='44', group=GROUP_AVG)
// ————— Average 12
bool inputShowAvg12 = input.bool(title='Moving Average 12', defval=true, inline='45', group=GROUP_AVG)
color inputColorBull12 = input.color(COLOR_BULL_12, '', inline='45', group=GROUP_AVG)
color inputColorBear12 = input.color(COLOR_BEAR_12, '', inline='45', group=GROUP_AVG)
string inputTypeMa12 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='46', group=GROUP_AVG)
int inputLengthMa12 = input.int(60, minval=1, title='Length', inline='46', group=GROUP_AVG)
float inputSourceMa12 = input.source(close, title='Source', inline='47', group=GROUP_AVG)
int inputOffsetMa12 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='47', group=GROUP_AVG)
// ————— Average 13
bool inputShowAvg13 = input.bool(title='Moving Average 13', defval=true, inline='48', group=GROUP_AVG)
color inputColorBull13 = input.color(COLOR_BULL_13, '', inline='48', group=GROUP_AVG)
color inputColorBear13 = input.color(COLOR_BEAR_13, '', inline='48', group=GROUP_AVG)
string inputTypeMa13 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='49', group=GROUP_AVG)
int inputLengthMa13 = input.int(65, minval=1, title='Length', inline='49', group=GROUP_AVG)
float inputSourceMa13 = input.source(close, title='Source', inline='50', group=GROUP_AVG)
int inputOffsetMa13 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='50', group=GROUP_AVG)
// ————— Average 14
bool inputShowAvg14 = input.bool(title='Moving Average 14', defval=true, inline='51', group=GROUP_AVG)
color inputColorBull14 = input.color(COLOR_BULL_14, '', inline='51', group=GROUP_AVG)
color inputColorBear14 = input.color(COLOR_BEAR_14, '', inline='51', group=GROUP_AVG)
string inputTypeMa14 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='52', group=GROUP_AVG)
int inputLengthMa14 = input.int(70, minval=1, title='Length', inline='52', group=GROUP_AVG)
float inputSourceMa14 = input.source(close, title='Source', inline='53', group=GROUP_AVG)
int inputOffsetMa14 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='53', group=GROUP_AVG)
// ————— Average 15
bool inputShowAvg15 = input.bool(title='Moving Average 15', defval=true, inline='54', group=GROUP_AVG)
color inputColorBull15 = input.color(COLOR_BULL_15, '', inline='54', group=GROUP_AVG)
color inputColorBear15 = input.color(COLOR_BEAR_15, '', inline='54', group=GROUP_AVG)
string inputTypeMa15 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='55', group=GROUP_AVG)
int inputLengthMa15 = input.int(75, minval=1, title='Length', inline='55', group=GROUP_AVG)
float inputSourceMa15 = input.source(close, title='Source', inline='56', group=GROUP_AVG)
int inputOffsetMa15 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='56', group=GROUP_AVG)
// ————— Average 16
bool inputShowAvg16 = input.bool(title='Moving Average 16', defval=true, inline='57', group=GROUP_AVG)
color inputColorBull16 = input.color(COLOR_BULL_16, '', inline='57', group=GROUP_AVG)
color inputColorBear16 = input.color(COLOR_BEAR_16, '', inline='57', group=GROUP_AVG)
string inputTypeMa16 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='58', group=GROUP_AVG)
int inputLengthMa16 = input.int(80, minval=1, title='Length', inline='58', group=GROUP_AVG)
float inputSourceMa16 = input.source(close, title='Source', inline='59', group=GROUP_AVG)
int inputOffsetMa16 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='59', group=GROUP_AVG)
// ————— Average 17
bool inputShowAvg17 = input.bool(title='Moving Average 17', defval=true, inline='60', group=GROUP_AVG)
color inputColorBull17 = input.color(COLOR_BULL_17, '', inline='60', group=GROUP_AVG)
color inputColorBear17 = input.color(COLOR_BEAR_17, '', inline='60', group=GROUP_AVG)
string inputTypeMa17 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='61', group=GROUP_AVG)
int inputLengthMa17 = input.int(85, minval=1, title='Length', inline='61', group=GROUP_AVG)
float inputSourceMa17 = input.source(close, title='Source', inline='62', group=GROUP_AVG)
int inputOffsetMa17 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='62', group=GROUP_AVG)
// ————— Average 18
bool inputShowAvg18 = input.bool(title='Moving Average 18', defval=true, inline='63', group=GROUP_AVG)
color inputColorBull18 = input.color(COLOR_BULL_18, '', inline='63', group=GROUP_AVG)
color inputColorBear18 = input.color(COLOR_BEAR_18, '', inline='63', group=GROUP_AVG)
string inputTypeMa18 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='64', group=GROUP_AVG)
int inputLengthMa18 = input.int(90, minval=1, title='Length', inline='64', group=GROUP_AVG)
float inputSourceMa18 = input.source(close, title='Source', inline='65', group=GROUP_AVG)
int inputOffsetMa18 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='65', group=GROUP_AVG)
// ————— Average 19
bool inputShowAvg19 = input.bool(title='Moving Average 19', defval=true, inline='66', group=GROUP_AVG)
color inputColorBull19 = input.color(COLOR_BULL_19, '', inline='66', group=GROUP_AVG)
color inputColorBear19 = input.color(COLOR_BEAR_19, '', inline='66', group=GROUP_AVG)
string inputTypeMa19 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='67', group=GROUP_AVG)
int inputLengthMa19 = input.int(95, minval=1, title='Length', inline='67', group=GROUP_AVG)
float inputSourceMa19 = input.source(close, title='Source', inline='68', group=GROUP_AVG)
int inputOffsetMa19 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='68', group=GROUP_AVG)
// ————— Average 20
bool inputShowAvg20 = input.bool(title='Moving Average 20', defval=true, inline='69', group=GROUP_AVG)
color inputColorBull20 = input.color(COLOR_BULL_20, '', inline='69', group=GROUP_AVG)
color inputColorBear20 = input.color(COLOR_BEAR_20, '', inline='69', group=GROUP_AVG)
string inputTypeMa20 = input.string(SMA, 'Type',
options=[AARMA,ALSMA,AHMA,ADEMA,ALMA,AUTOL,COVWEMA,COVWMA,CMA,CORMA,DEMA,DONCHIAN,EFRAMA,EDSMA,EVWMA,EPMA,EDMA,EHMA,EMA,ETMA,FIBOWMA,FISHLSMA,FAMA,FRAMA,GMA,HKAMA,HMA,JURIK,KAMA,LC_LSMA,LEOMA,LSMA,LINWMA,MEDIAN,MAMA,MCMA,XEMA,REMA,REGMA,RMA,REPMA,RVWAP,RSIMA,SMA,SW_MA,SRWMA,SMMA,SWMA,TT3,TREMA,TRSMA,TEMA,THMA,VIDYA,VAMA,VWAP,WMA,WWMA,ZEMA,ZSMA],
inline='70', group=GROUP_AVG)
int inputLengthMa20 = input.int(100, minval=1, title='Length', inline='70', group=GROUP_AVG)
float inputSourceMa20 = input.source(close, title='Source', inline='71', group=GROUP_AVG)
int inputOffsetMa20 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='71', group=GROUP_AVG)
// ———————————————————————————————————————— }
// ———————————————————————————————————————— Calculations {
// @function calculateMovingAverage
// @description Abstract function that invokes the calculation of average according to type
// @param type Type of Moving Average
// @param src Source of series (close, high, low, etc.)
// @param len Period of loopback to calculate the average
// @returns series of moving average
calculateMovingAverage(simple string type, float src, simple int len) =>
// ———————————————————— Only for Debug {
// Logger.log("Type: " + type, logger, logTable, "info")
// ———————————————————— }
MaProxy.getMovingAverage(
type=type, src=src, len=len,
lsmaOffset=0,
inputAlmaOffset=inputAlmaOffset, inputAlmaSigma=inputAlmaSigma,
FC=fc, SC=sc,
a1_t3=a1_t3,
fixedTfInput=_fixedTfInput, daysInput=_daysInput, hoursInput=_hoursInput, minsInput=_minsInput, minBarsInput=_minBarsInput,
lambda=lambda,
factor=factor,
offset_epma=offset_epma,
volumeWeighted=applyVolumeWeighted,
gamma_aarma=gamma_aarma,
smooth=smooth,
linweight=lwma_weight,
volatility_lookback=volatility_lookback,
jurik_phase=jurik_phase,
jurik_power=jurik_power)
switch inputPredefinedPeriods
'Defined by user' =>
lenMa1 := inputLengthMa1
lenMa2 := inputLengthMa2
lenMa3 := inputLengthMa3
lenMa4 := inputLengthMa4
lenMa5 := inputLengthMa5
lenMa6 := inputLengthMa6
lenMa7 := inputLengthMa7
lenMa8 := inputLengthMa8
lenMa9 := inputLengthMa9
lenMa10 := inputLengthMa10
lenMa11 := inputLengthMa11
lenMa12 := inputLengthMa12
lenMa13 := inputLengthMa13
lenMa14 := inputLengthMa14
lenMa15 := inputLengthMa15
lenMa16 := inputLengthMa16
lenMa17 := inputLengthMa17
lenMa18 := inputLengthMa18
lenMa19 := inputLengthMa19
lenMa20 := inputLengthMa20
'Arithmetic Progression of 5' =>
lenMa1 := 5
lenMa2 := 10
lenMa3 := 15
lenMa4 := 20
lenMa5 := 25
lenMa6 := 30
lenMa7 := 35
lenMa8 := 40
lenMa9 := 45
lenMa10 := 50
lenMa11 := 55
lenMa12 := 60
lenMa13 := 65
lenMa14 := 70
lenMa15 := 75
lenMa16 := 80
lenMa17 := 85
lenMa18 := 90
lenMa19 := 95
lenMa20 := 100
'Arithmetic Progression of 7' =>
lenMa1 := 7
lenMa2 := 14
lenMa3 := 21
lenMa4 := 28
lenMa5 := 35
lenMa6 := 42
lenMa7 := 49
lenMa8 := 56
lenMa9 := 63
lenMa10 := 70
lenMa11 := 77
lenMa12 := 84
lenMa13 := 91
lenMa14 := 98
lenMa15 := 105
lenMa16 := 112
lenMa17 := 119
lenMa18 := 126
lenMa19 := 133
lenMa20 := 140
'Arithmetic Progression of 8' =>
lenMa1 := 8
lenMa2 := 16
lenMa3 := 24
lenMa4 := 32
lenMa5 := 40
lenMa6 := 48
lenMa7 := 56
lenMa8 := 64
lenMa9 := 72
lenMa10 := 80
lenMa11 := 88
lenMa12 := 96
lenMa13 := 104
lenMa14 := 112
lenMa15 := 120
lenMa16 := 128
lenMa17 := 136
lenMa18 := 144
lenMa19 := 152
lenMa20 := 160
'Arithmetic Progression of 9' =>
lenMa1 := 9
lenMa2 := 18
lenMa3 := 27
lenMa4 := 36
lenMa5 := 45
lenMa6 := 54
lenMa7 := 63
lenMa8 := 72
lenMa9 := 81
lenMa10 := 90
lenMa11 := 99
lenMa12 := 108
lenMa13 := 117
lenMa14 := 126
lenMa15 := 135
lenMa16 := 144
lenMa17 := 153
lenMa18 := 162
lenMa19 := 171
lenMa20 := 180
'Arithmetic Progression of 10' =>
lenMa1 := 10
lenMa2 := 20
lenMa3 := 30
lenMa4 := 40
lenMa5 := 50
lenMa6 := 60
lenMa7 := 70
lenMa8 := 80
lenMa9 := 90
lenMa10 := 100
lenMa11 := 110
lenMa12 := 120
lenMa13 := 130
lenMa14 := 140
lenMa15 := 150
lenMa16 := 160
lenMa17 := 170
lenMa18 := 180
lenMa19 := 190
lenMa20 := 200
'Arithmetic Progression of 16' =>
lenMa1 := 16
lenMa2 := 32
lenMa3 := 48
lenMa4 := 64
lenMa5 := 80
lenMa6 := 96
lenMa7 := 112
lenMa8 := 128
lenMa9 := 144
lenMa10 := 160
lenMa11 := 176
lenMa12 := 192
lenMa13 := 208
lenMa14 := 224
lenMa15 := 240
lenMa16 := 256
lenMa17 := 272
lenMa18 := 288
lenMa19 := 304
lenMa20 := 320
'Arithmetic Progression of 20' =>
lenMa1 := 20
lenMa2 := 40
lenMa3 := 60
lenMa4 := 80
lenMa5 := 100
lenMa6 := 120
lenMa7 := 140
lenMa8 := 160
lenMa9 := 180
lenMa10 := 200
lenMa11 := 220
lenMa12 := 240
lenMa13 := 260
lenMa14 := 280
lenMa15 := 300
lenMa16 := 320
lenMa17 := 340
lenMa18 := 360
lenMa19 := 380
lenMa20 := 400
'Arithmetic Progression of 30' =>
lenMa1 := 30
lenMa2 := 60
lenMa3 := 90
lenMa4 := 120
lenMa5 := 150
lenMa6 := 180
lenMa7 := 210
lenMa8 := 240
lenMa9 := 270
lenMa10 := 300
lenMa11 := 330
lenMa12 := 360
lenMa13 := 390
lenMa14 := 420
lenMa15 := 450
lenMa16 := 480
lenMa17 := 510
lenMa18 := 540
lenMa19 := 570
lenMa20 := 600
'Arithmetic Progression of 32' =>
lenMa1 := 32
lenMa2 := 64
lenMa3 := 96
lenMa4 := 128
lenMa5 := 160
lenMa6 := 192
lenMa7 := 224
lenMa8 := 256
lenMa9 := 288
lenMa10 := 320
lenMa11 := 352
lenMa12 := 384
lenMa13 := 416
lenMa14 := 448
lenMa15 := 480
lenMa16 := 512
lenMa17 := 544
lenMa18 := 576
lenMa19 := 608
lenMa20 := 640
'Arithmetic Progression of 50' =>
lenMa1 := 50
lenMa2 := 100
lenMa3 := 150
lenMa4 := 200
lenMa5 := 250
lenMa6 := 300
lenMa7 := 350
lenMa8 := 400
lenMa9 := 450
lenMa10 := 500
lenMa11 := 550
lenMa12 := 600
lenMa13 := 650
lenMa14 := 700
lenMa15 := 750
lenMa16 := 800
lenMa17 := 850
lenMa18 := 900
lenMa19 := 950
lenMa20 := 1000
'Arithmetic Progression of 64' =>
lenMa1 := 64
lenMa2 := 128
lenMa3 := 192
lenMa4 := 256
lenMa5 := 320
lenMa6 := 384
lenMa7 := 448
lenMa8 := 512
lenMa9 := 576
lenMa10 := 640
lenMa11 := 704
lenMa12 := 768
lenMa13 := 832
lenMa14 := 896
lenMa15 := 960
lenMa16 := 1024
lenMa17 := 1088
lenMa18 := 1152
lenMa19 := 1216
lenMa20 := 1280
'Tradicional: 8, 21, 50, 100, 200, 365, 730, 1095, 1460, 1825, 2190' =>
lenMa1 := 8
lenMa2 := 21
lenMa3 := 50
lenMa4 := 100
lenMa5 := 200
lenMa6 := 365
lenMa7 := 730
lenMa8 := 1095
lenMa9 := 1460
lenMa10 := 1825
lenMa11 := 2190
lenMa12 := 1
lenMa13 := 1
lenMa14 := 1
lenMa15 := 1
lenMa16 := 1
lenMa17 := 1
lenMa18 := 1
lenMa19 := 1
lenMa20 := 1
inputShowAvg12 := false
inputShowAvg13 := false
inputShowAvg14 := false
inputShowAvg15 := false
inputShowAvg16 := false
inputShowAvg17 := false
inputShowAvg18 := false
inputShowAvg19 := false
inputShowAvg20 := false
'Fibonacci' =>