Add arrows to chart with MACD and RSI indicator?

Rojo Grande

Hello all. I'm trying to cut and paste together a code that will show an up arrow on the bar where the MACD value, average are above 0, and the RSI is above 50. Also a down arrow for the opposite. One problem (of many) I have is that I would like the MACD to be exponential, and the RSI to be Wilders. Here is what I have put together, but does not work:

input fastLength = 3;
input slowLength = 6;
input MACDLength = 20;
input averageType = AverageType.EXPONENTIAL;

plot Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
plot ZeroLine = 0;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
#input averageType = AverageType.Exponential;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
plot MidLine = 50;

plot BUYSignal = (Value > 0) and (Avg > 0) and (RSI crosses above 50);
plot SELLSignal = (Value < 0) and (Avg < 0) and (RSI crosses below 50);



ANY help appreciated, thank you.


Well-known member
#input averageTypersi = AverageType.Wilders;
def NetChgAvg = MovingAverage(averageTypersi, price - price[1], length);
def TotChgAvg = MovingAverage(averageTypersi, AbsValue(price - price[1]), length);

That is the easy part.

RSI plots 0 to 100 and MACD above and below the zero line. So you need to solve that first. Try working out the plots as a lower study first.

That is all. Good luck.

Similar threads