latinbori123456
Member
I created this indicator to allow 4 different moving averages across many common timeframes to be put on one chart. I use this on a 5 min chart to have labels to help me see how far the current price is intra day to the 5/21/50/200 EMA on the daily and weekly chart.
Hope people can use this
Hope people can use this
Code:
#declare lower;
input aggregationPeriod1 = {Five_Min, Fifteen_Min, default One_Hour, Four_Hour, Daily, Weekly, Monthly};
input length1 = 200;
input averageType1 = {default EMA, SMA, HMA};
input aggregationPeriod2 = {Five_Min, Fifteen_Min, One_Hour, Four_Hour, default Daily, Weekly, Monthly};
input length2 = 200;
input averageType2 = {default EMA, SMA, HMA};
input aggregationPeriod3 = {Five_Min, Fifteen_Min, One_Hour, Four_Hour, Daily, default Weekly, Monthly};
input length3 = 200;
input averageType3 = {default EMA, SMA, HMA};
input aggregationPeriod4 = {Five_Min, Fifteen_Min, One_Hour, Four_Hour, Daily, Weekly, default Monthly};
input length4 = 200;
input averageType4 = {default EMA, SMA, HMA};
input ShowLabel1 = yes;
input ShowLabel2 = yes;
input ShowLabel3 = yes;
input ShowLabel4 = yes;
input ShowLabel5 = yes;
input VwapType = {default DAY, WEEK, MONTH};
def VWAPRef = reference VWAP("time frame" = VwapType)."VWAP";
def VWAPRef1a = if !IsNaN(VWAPRef) then VWAPRef else VWAPRef1a[1];
def VWAP1 = VWAPRef1a;
def VWAPpct1 = (close / VWAPRef1a) - 1;
plot VWAPdist1 = VWAPpct1;
def AvgType1;
switch (averageType1){
case EMA:
AvgType1 = AverageType.EXPONENTIAL;
case SMA:
AvgType1 = AverageType.SIMPLE;
case HMA:
AvgType1 = AverageType.HULL;
}
def AvgType2;
switch (averageType2){
case EMA:
AvgType2 = AverageType.EXPONENTIAL;
case SMA:
AvgType2 = AverageType.SIMPLE;
case HMA:
AvgType2 = AverageType.HULL;
}
def AvgType3;
switch (averageType3){
case EMA:
AvgType3 = AverageType.EXPONENTIAL;
case SMA:
AvgType3 = AverageType.SIMPLE;
case HMA:
AvgType3 = AverageType.HULL;
}
def AvgType4;
switch (averageType4){
case EMA:
AvgType4 = AverageType.EXPONENTIAL;
case SMA:
AvgType4 = AverageType.SIMPLE;
case HMA:
AvgType4 = AverageType.HULL;
}
###MA1 Data###
def AggPer1;
switch (aggregationPeriod1){
case Five_Min:
AggPer1 = AggregationPeriod.FIVE_MIN;
case Fifteen_Min:
AggPer1 = AggregationPeriod.FIFTEEN_MIN;
case One_Hour:
AggPer1 = AggregationPeriod.HOUR;
case Four_Hour:
AggPer1 = AggregationPeriod.FOUR_HOURS;
case Daily:
AggPer1 = AggregationPeriod.DAY;
case Weekly:
AggPer1 = AggregationPeriod.WEEK;
case Monthly:
AggPer1 = AggregationPeriod.MONTH;
}
def pricetype1 = close( period = AggPer1);
def avg1 = MovingAverage(AvgType1, pricetype1, length1);
def avg1a = if !IsNaN(avg1) then avg1 else avg1a[1];
def MA1 = avg1a;
def pct1 = (close / avg1a) - 1;
plot dist1 = pct1;
###MA2 Data###
def AggPer2;
switch (aggregationPeriod2){
case Five_Min:
AggPer2 = AggregationPeriod.FIVE_MIN;
case Fifteen_Min:
AggPer2 = AggregationPeriod.FIFTEEN_MIN;
case One_Hour:
AggPer2 = AggregationPeriod.HOUR;
case Four_Hour:
AggPer2 = AggregationPeriod.FOUR_HOURS;
case Daily:
AggPer2 = AggregationPeriod.DAY;
case Weekly:
AggPer2 = AggregationPeriod.WEEK;
case Monthly:
AggPer2 = AggregationPeriod.MONTH;
}
def pricetype2 = close( period = AggPer2);
def avg2 = MovingAverage(AvgType2, pricetype2, length2);
def avg2a = if !IsNaN(avg2) then avg2 else avg2a[1];
def MA2 = avg2a;
def pct2 = (close / avg2a) - 1;
plot dist2 = pct2;
###MA3 Data###
def AggPer3;
switch (aggregationPeriod3){
case Five_Min:
AggPer3 = AggregationPeriod.FIVE_MIN;
case Fifteen_Min:
AggPer3 = AggregationPeriod.FIFTEEN_MIN;
case One_Hour:
AggPer3 = AggregationPeriod.HOUR;
case Four_Hour:
AggPer3 = AggregationPeriod.FOUR_HOURS;
case Daily:
AggPer3 = AggregationPeriod.DAY;
case Weekly:
AggPer3 = AggregationPeriod.WEEK;
case Monthly:
AggPer3 = AggregationPeriod.MONTH;
}
def pricetype3 = close( period = AggPer3);
def avg3 = MovingAverage(AvgType3, pricetype3, length3);
def avg3a = if !IsNaN(avg3) then avg3 else avg3a[1];
def MA3 = avg3a;
def pct3 = (close / avg3a) - 1;
plot dist3 = pct3;
###MA4 Data###
def AggPer4;
switch (aggregationPeriod4){
case Five_Min:
AggPer4 = AggregationPeriod.FIVE_MIN;
case Fifteen_Min:
AggPer4 = AggregationPeriod.FIFTEEN_MIN;
case One_Hour:
AggPer4 = AggregationPeriod.HOUR;
case Four_Hour:
AggPer4 = AggregationPeriod.FOUR_HOURS;
case Daily:
AggPer4 = AggregationPeriod.DAY;
case Weekly:
AggPer4 = AggregationPeriod.WEEK;
case Monthly:
AggPer4 = AggregationPeriod.MONTH;
}
def pricetype4 = close( period = AggPer4);
def avg4 = MovingAverage(AvgType4, pricetype4, length4);
def avg4a = if !IsNaN(avg4) then avg4 else avg4a[1];
def MA4 = avg4a;
def pct4 = (close / avg4a) - 1;
plot dist4 = pct4;
###Labels###
AddLabel(ShowLabel1, length1 + " " + (if AggPer1 == AggregationPeriod.FIVE_MIN then "5 Min" else if AggPer1 == AggregationPeriod.FIFTEEN_MIN then "15 Min" else if AggPer1 == AggregationPeriod.HOUR then "1 Hour" else if AggPer1 == AggregationPeriod.FOUR_HOURS then "4 Hour" else if AggPer1 == AggregationPeriod.DAY then "Day" else if AggPer1 == AggregationPeriod.WEEK then "Week" else if AggPer1 == AggregationPeriod.MONTH then "Month" else "") + " " + (if AvgType1 == 1 then "EMA" else if AvgType1 == 0 then "SMA" else if avgType1 == 4 then "HMA" else "") + " " + MA1 + " pct: " + AsPercent(dist1) , if pct1 > 0 then Color.GREEN else Color.RED);
;
AddLabel(ShowLabel2, length2 + " " + (if AggPer2 == AggregationPeriod.FIVE_MIN then "5 Min" else if AggPer2 == AggregationPeriod.FIFTEEN_MIN then "15 Min" else if AggPer2 == AggregationPeriod.HOUR then "1 Hour" else if AggPer2 == AggregationPeriod.FOUR_HOURS then "4 Hour" else if AggPer2 == AggregationPeriod.DAY then "Day" else if AggPer2 == AggregationPeriod.WEEK then "Week" else if AggPer2 == AggregationPeriod.MONTH then "Month" else "") + " " + (if AvgType2 == 1 then "EMA" else if AvgType2 == 0 then "SMA" else if avgType2 == 4 then "HMA" else "") + " " + MA2 + " pct: " + AsPercent(dist2) , if pct2 > 0 then Color.GREEN else Color.RED);
;
AddLabel(ShowLabel3, length3 + " " + (if AggPer3 == AggregationPeriod.FIVE_MIN then "5 Min" else if AggPer3 == AggregationPeriod.FIFTEEN_MIN then "15 Min" else if AggPer3 == AggregationPeriod.HOUR then "1 Hour" else if AggPer3 == AggregationPeriod.FOUR_HOURS then "4 Hour" else if AggPer3 == AggregationPeriod.DAY then "Day" else if AggPer3 == AggregationPeriod.WEEK then "Week" else if AggPer3 == AggregationPeriod.MONTH then "Month" else "") + " " + (if AvgType3 == 1 then "EMA" else if AvgType3 == 0 then "SMA" else if avgType3 == 4 then "HMA" else "") + " " + MA3 + " pct: " + AsPercent(dist3) , if pct3 > 0 then Color.GREEN else Color.RED);
;
AddLabel(ShowLabel4, length4 + " " + (if AggPer4 == AggregationPeriod.FIVE_MIN then "5 Min" else if AggPer4 == AggregationPeriod.FIFTEEN_MIN then "15 Min" else if AggPer4 == AggregationPeriod.HOUR then "1 Hour" else if AggPer4 == AggregationPeriod.FOUR_HOURS then "4 Hour" else if AggPer4 == AggregationPeriod.DAY then "Day" else if AggPer4 == AggregationPeriod.WEEK then "Week" else if AggPer4 == AggregationPeriod.MONTH then "Month" else "") + " " + (if AvgType4 == 1 then "EMA" else if AvgType4 == 0 then "SMA" else if avgType4 == 4 then "HMA" else "") + " " + MA4 + " pct: " + AsPercent(dist4) , if pct4 > 0 then Color.GREEN else Color.RED);
;
AddLabel(ShowLabel5, (if VwapType == VwapType.DAY then "Daily" else if VwapType == VwapType.WEEK then "Weekly" else if VwapType == VwapType.MONTH then "Monthly" else "") + " VWAP " + VWAP1 + " pct: " + AsPercent(VWAPdist1) , if VWAPpct1 > 0 then Color.GREEN else Color.RED);
;