The code below (1) calculates the moving average slope, and then (2) should give the price difference between the moving average and the current stock price DEPENDING UPON THE SLOPE - but the "if" part is wrong - can anyone see the error?
Code:
#slope
def EMA30 = MovAvgExponential(close,30);
def slopeavg = Average(close,3);
def height = slopeavg - slopeavg[3];
def slope = Atan(height/3)*180/Double.Pi;
#conditions
def Condition1 = (slope < 0 and close > EMA30);
def Conditiion2 = (slope > 0 and close < EMA30);
#watchlist column result
plot X = if Condition1 then close - EMA30:
plot X = if Condition2 then EMA30 - close;