I updated your question title so that is clearly states the context of your question. Please review the title I chose and in the future make sure you are very specific, yet brief, in your question titles.
It is a shame you did not include you code. If you are trying to learn this stuff then make sure to provide your code, even if it’s not functional. I will take the time to explain the items you missed and help you understand how to do it right. But since you did not provide your code I only have the solution.
I have copied the major portions of the built-in study so that it plots on a lower subgraph just like the original The two statements at the very bottom create your alerts.
declare lower;
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
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;
RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
OverSold.SetDefaultColor(GetColor(8)); OverBought.SetDefaultColor(GetColor(8));
Alert(RSI > over_Bought and RSI[1] < over_Bought, "RSI Overbought", Alert.BAR, Sound.RING);
Alert(RSI < over_Sold and RSI[1] > over_Sold, "RSI Oversold", Alert.BAR, Sound.RING);