#
# SM_MovingAverageLabels
#
# version 1.2
#
declare on_volume;
#Default moving average values:
#SIMP 3 Close.DAY
#SIMP 8 Close.DAY
#SIMP 20 Close.DAY
#SIMP 50 Close.DAY
#SIMP 200 Close.DAY
input aP = AggregationPeriod.DAY;
input MA_1_length = 3; #simple
input MA_2_length = 8; #simple
input MA_3_length = 20; #simple
input MA_4_length = 50; #simple
input MA_5_length = 200; #simple
def MA_1_closeType = close(period = aP);
def MA_2_closeType = close(period = aP);
def MA_3_closeType = close(period = aP);
def MA_4_closeType = close(period = aP);
def MA_5_closeType = close(period = aP);
def MA_1_avg = round(Average(MA_1_closeType, MA_1_length),2);
def MA_2_avg = round(Average(MA_2_closeType, MA_2_length),2);
def MA_3_avg = round(Average(MA_3_closeType, MA_3_length),2);
def MA_4_avg = round(Average(MA_4_closeType, MA_4_length),2);
def MA_5_avg = round(Average(MA_5_closeType, MA_5_length),2);
def currentPrice = close;
AddLabel(1, "SMA" + " ", Color.YELLOW);
def MA_1_above = if currentPrice > MA_1_avg then 1 else 0;
def MA_1_below = if currentPrice <= MA_1_avg then 1 else 0;
AddLabel(MA_1_above, MA_1_length + ": " + MA_1_avg + " ", Color.GREEN);
AddLabel(MA_1_below, MA_1_length + ": " + MA_1_avg + " ", Color.RED);
def MA_2_above = if currentPrice > MA_2_avg then 1 else 0;
def MA_2_below = if currentPrice <= MA_2_avg then 1 else 0;
AddLabel(MA_2_above, MA_2_length + ": " + MA_2_avg + " ", Color.GREEN);
AddLabel(MA_2_below, MA_2_length + ": " + MA_2_avg + " ", Color.RED);
def MA_3_above = if currentPrice > MA_3_avg then 1 else 0;
def MA_3_below = if currentPrice <= MA_3_avg then 1 else 0;
AddLabel(MA_3_above, MA_3_length + ": " + MA_3_avg + " ", Color.GREEN);
AddLabel(MA_3_below, MA_3_length + ": " + MA_3_avg + " ", Color.RED);
def MA_4_above = if currentPrice > MA_4_avg then 1 else 0;
def MA_4_below = if currentPrice <= MA_4_avg then 1 else 0;
AddLabel(MA_4_above, MA_4_length + ": " + MA_4_avg + " ", Color.GREEN);
AddLabel(MA_4_below, MA_4_length + ": " + MA_4_avg + " ", Color.RED);
def MA_5_above = if currentPrice > MA_5_avg then 1 else 0;
def MA_5_below = if currentPrice <= MA_5_avg then 1 else 0;
AddLabel(MA_4_above, MA_5_length + ": " + MA_5_avg + " ", Color.GREEN);
AddLabel(MA_4_below, MA_5_length + ": " + MA_5_avg + " ", Color.RED);
#EXPO 3 Close
#EXPO 8 Close
#EXPO 20 Close
#EXPO 50 Close
#EXPO 200 Close
input EMA_1_length = 3; #exponential
input EMA_2_length = 8; #exponential
input EMA_3_length = 20; #exponential
input EMA_4_length = 50; #exponential
input EMA_5_length = 200; #exponential
def EMA_1_closeType = close;
def EMA_2_closeType = close;
def EMA_3_closeType = close;
def EMA_4_closeType = close;
def EMA_5_closeType = close;
def EMA_1_avg = round(ExpAverage(EMA_1_closeType, EMA_1_length),2);
def EMA_2_avg = round(ExpAverage(EMA_2_closeType, EMA_2_length),2);
def EMA_3_avg = round(ExpAverage(EMA_3_closeType, EMA_3_length),2);
def EMA_4_avg = round(ExpAverage(EMA_4_closeType, EMA_4_length),2);
def EMA_5_avg = round(ExpAverage(EMA_5_closeType, EMA_5_length),2);
AddLabel(1, "EMA" + " ", Color.YELLOW);
def EMA_1_above = if currentPrice > EMA_1_avg then 1 else 0;
def EMA_1_below = if currentPrice <= EMA_1_avg then 1 else 0;
AddLabel(EMA_1_above, EMA_1_length + ": " + EMA_1_avg + " ", Color.GREEN);
AddLabel(EMA_1_below, EMA_1_length + ": " + EMA_1_avg + " ", Color.RED);
def EMA_2_above = if currentPrice > EMA_2_avg then 1 else 0;
def EMA_2_below = if currentPrice <= EMA_2_avg then 1 else 0;
AddLabel(EMA_2_above, EMA_2_length + ": " + EMA_2_avg + " ", Color.GREEN);
AddLabel(EMA_2_below, EMA_2_length + ": " + EMA_2_avg + " ", Color.RED);
def EMA_3_above = if currentPrice > EMA_3_avg then 1 else 0;
def EMA_3_below = if currentPrice <= EMA_3_avg then 1 else 0;
AddLabel(EMA_3_above, EMA_3_length + ": " + EMA_3_avg + " ", Color.GREEN);
AddLabel(EMA_3_below, EMA_3_length + ": " + EMA_3_avg + " ", Color.RED);
def EMA_4_above = if currentPrice > EMA_4_avg then 1 else 0;
def EMA_4_below = if currentPrice <= EMA_4_avg then 1 else 0;
AddLabel(EMA_4_above, EMA_4_length + ": " + EMA_4_avg + " ", Color.GREEN);
AddLabel(EMA_4_below, EMA_4_length + ": " + EMA_4_avg + " ", Color.RED);
def EMA_5_above = if currentPrice > EMA_5_avg then 1 else 0;
def EMA_5_below = if currentPrice <= EMA_5_avg then 1 else 0;
AddLabel(EMA_4_above, EMA_5_length + ": " + EMA_5_avg + " ", Color.GREEN);
AddLabel(EMA_4_below, EMA_5_length + ": " + EMA_5_avg + " ", Color.RED);