Due to limitation on number of screens, I use one chart that I often switch from Max W chart, 1Y 1D chart, 180D 4h chart, to 1D 5m chart to create support and resistant.
I use 4 moving average(MA)s, which I played around into 1 study.
They are the 13 EMA, 20 EMA, 50 SMA, and 200 SMA.
For awhile, it was working fine. However, overtime I've found myself putting too many support and resistant lines that the MA lines were getting harder to read.
So, I tried using SetHiding to hide the 13 & 20 EMAs and only show the 50 & 200 SMAs when I'm switching to Max W & 1Y 1D charts and vice versa on hiding the 50 & 200 SMAs and showing 13 & 20 EMAs when switching to 180D 4h & 1D 5m chart.
I don't know what I'm doing, but if anyone can take a stab at it, rearrange, or give me a constructive criticism on how to fix the code, it would be very much appreciated. Thanks in advance.
Here's the code:
I use 4 moving average(MA)s, which I played around into 1 study.
They are the 13 EMA, 20 EMA, 50 SMA, and 200 SMA.
For awhile, it was working fine. However, overtime I've found myself putting too many support and resistant lines that the MA lines were getting harder to read.
So, I tried using SetHiding to hide the 13 & 20 EMAs and only show the 50 & 200 SMAs when I'm switching to Max W & 1Y 1D charts and vice versa on hiding the 50 & 200 SMAs and showing 13 & 20 EMAs when switching to 180D 4h & 1D 5m chart.
I don't know what I'm doing, but if anyone can take a stab at it, rearrange, or give me a constructive criticism on how to fix the code, it would be very much appreciated. Thanks in advance.
Here's the code:
Code:
#= MOVING AVERAGES =========================================================#
# INPUTS FOR MOVING AVERAGE #
input EMA1 = 13;
input EMA2 = 20;
input SMA1 = 50;
input SMA2 = 200;
input Displace = 0;
input AverageType1 = {"SIMPLE", default "EXPONENTIAL", "WEIGHTED", "WILDERS", "HULL"};
input AverageType2 = {default "SIMPLE", "EXPONENTIAL", "WEIGHTED", "WILDERS", "HULL"};
# PLOTS FOR MOVING AVERAGE #
plot FirstMA = MovingAverage(AverageType1, close[-Displace], EMA1);
plot SecondMA = MovingAverage(AverageType1, close[-Displace], EMA2);
plot ThirdMA = MovingAverage(AverageType2, close[-Displace], SMA1);
plot FourthMA = MovingAverage(AverageType2, close[-Displace], SMA2);
# SET HIDING FOR MOVING AVERAGE #
FirstMA.SetHiding(GetAggregationPeriod() >= AggregationPeriod.MIN);
SecondMA.SetHiding(GetAggregationPeriod() >= AggregationPeriod.MIN);
ThirdMA.SetHiding(GetAggregationPeriod() <= AggregationPeriod.DAY);
SecondMA.SetHiding(GetAggregationPeriod() <= AggregationPeriod.DAY);
# DEFINE GLOBAL COLOR FOR MOVING AVERAGE #
DefineGlobalColor("MA1", (CreateColor(153, 204, 255)));
DefineGlobalColor("MA2", (CreateColor(0, 128, 255)));
DefineGlobalColor("MA3", (CreateColor(204, 153, 255)));
DefineGlobalColor("MA4", (CreateColor(127, 0, 255)));
# SET DEFAULT COLOR FOR MOVING AVERAGE #
FirstMA.SetDefaultColor (GlobalColor("MA1"));
SecondMA.SetDefaultColor (GlobalColor("MA2"));
ThirdMA.SetDefaultColor (GlobalColor("MA3"));
FourthMA.SetDefaultColor (GlobalColor("MA4"));
# SET LINE WEIGHT FOR MOVING AVERAGE #
FirstMA.SetLineWeight(1);
SecondMA.SetLineWeight(1);
ThirdMA.SetLineWeight(1);
FourthMA.SetLineWeight(1);
#= MOVING AVERAGE =========================================================#