Just messing with a new RSI strategy. Using 3 RSI levels with a cross over to indicate going long or short. Just seeing if anyone can help me clean up the code a little better and plot the vertical lines when the parameter is truly met versus when the RSI levels are in transition. I'm fairly new to scripting and only know the basics.
Code:
###Triple RSI ###
declare lower;
input length = 8;
input length2 = 14;
input length3 = 21;
input over_Bought = 70;
input over_Sold = 30;
input over_Bought2 = 80;
input over_Sold2 = 20;
input over_Bought3 = 90;
input over_Sold3 = 10;
input midlineX = 50;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
###RSI ONE###
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 TWO###
def NetChgAvg2 = MovingAverage(averageType, price - price[1], length2);
def TotChgAvg2 = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;
plot RSI2 = 50 * (ChgRatio2 + 1);
plot OverSold2 = over_Sold2;
plot OverBought2 = over_Bought2;
###RSI THREE###
def NetChgAvg3 = MovingAverage(averageType, price - price[1], length3);
def TotChgAvg3 = MovingAverage(averageType, AbsValue(price - price[1]), length3);
def ChgRatio3 = if TotChgAvg3 != 0 then NetChgAvg3 / TotChgAvg3 else 0;
plot RSI3 = 50 * (ChgRatio3 + 1);
plot OverSold3 = over_Sold3;
plot OverBought3 = over_Bought3;
###MIDLINE###
plot Midline = midlineX;
###Vertical Lines###
def M1 = RSI crosses above RSI2 and RSI3;
def M2 = M1+ M1[1];
AddVerticalLine(M2[0] > M2[1], "Go BULLISH!", Color.green, Curve.SHORT_DASH);
def M3 = RSI crosses below RSI2 and RSI3;
def M4 = M3+ M3[1];
AddVerticalLine(M4[0] > M4[1], "Go SHORT", Color.red, Curve.SHORT_DASH);
Last edited by a moderator: