please not that crosses will just plot exact moment when it crosses and nothing after, so i will make the following two assumptions that instead of
crosses above, you meant crosses above or is above.
crosses below, you meant crosses below or is below
but if im wrong on my assumption then you can just take that section of the code out.
i also made the assumption you wanted no label if it was neither buy or sell.
Code:
declare lower;
input show_label = yes;
input price1 = close;
input length1 = 12;
input displace1 = 0;
def AvgExp1 = ExpAverage(price1[-displace1], length1);
input price2 = close;
input length2 = 20;
input displace2 = 0;
def AvgExp2 = ExpAverage(price2[-displace2], length2);
def emacross_below = if AvgExp1 crosses below avgexp2 or AvgExp1 < avgexp2 then 1 else 0;
def emacross_above = if AvgExp1 crosses above avgexp2 or AvgExp1 >avgexp2 then 1 else 0;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def Diff = Value - Avg;
def ZeroLine = 0;
def UpSignal = if Diff crosses above ZeroLine or Diff > ZeroLine then 1 else 0;
def DownSignal = if Diff crosses below ZeroLine or Diff < ZeroLine then 1 else 0;
def sell = if emacross_below and DownSignal then 1 else 0 ;
def buy = if emacross_above and upsignal then 1 else 0;
AddLabel(sell, (if show_label==1 then "Sell" else ""), Color.red);
AddLabel(buy, (if show_label==1 then "Buy" else ""), Color.GREEN);