Here's some code I came up with that shows the RSI signal on the MACD, plus plots MACD with two different length Bollinger Bands, plus adds some labels. Hope it's useful to you. The long Bollinger Bands can help you keep oriented with regards to price scalping and help find bottoms in particular. As always, use it with other indicators and the various key lines and trendlines.
Code:
# JS_MACD_RSI_Signals_DoubleBollingerBands
#
declare lower;
input fastLength = 34;
input slowLength = 55;
input smoothLength = 13;
input averageType = AverageType.EXPONENTIAL;
input longLength = 50;
input bbLength = 13;
input STDEV_Multiplier = 1;
plot MacdValue = MACD(fastLength, slowLength, smoothLength, averageType).Value;
plot MacdAvg = MACD(fastLength, slowLength, smoothLength, averageType).Avg;
plot ZeroLine = 0;
plot LongAverage = MovingAverage(averageType, MacdValue, longLength);
LongAverage.DefineColor("Up", GetColor(6)); #6 is green
LongAverage.DefineColor("Down", GetColor(0)); #0 is magenta
LongAverage.AssignValueColor(if LongAverage > LongAverage[1] then LongAverage.Color("Up") else LongAverage.Color("Down"));
LongAverage.SetStyle(Curve.Long_Dash);
#Bollinger Bands
def SDBB = StDev(MacdAvg, bbLength);
plot UpperBollinger = MacdAvg + STDEV_Multiplier * SDBB;
UpperBollinger.SetDefaultColor(Color.ORANGE);
plot LowerBollinger = MacdAvg - STDEV_Multiplier * SDBB;
LowerBollinger.SetDefaultColor(Color.ORANGE);
def bullMacd = MacdValue > UpperBollinger and MacdValue > LongAverage;
def bearMacd = MacdValue < LowerBollinger and MacdValue < LongAverage;
#Long BollingerBands
def longBBLength = longLength;
input longSD_Multiplier = 2;
def longSDBB = StDev(LongAverage, longBBLength);
plot LongUpperBB = LongAverage + longSD_Multiplier * longSDBB;
LongUpperBB.SetDefaultColor(Color.PLUM);
plot LongLowerBB = LongAverage - longSD_Multiplier * longSDBB;
LongLowerBB.SetDefaultColor(Color.PLUM);
AddLabel(yes, if bullMacd then "BullMACD" else if bearMacd then "BearMACD" else "Changing", if bullMacd then Color.LIGHT_GREEN else if bearMacd then Color.LIGHT_RED else Color.ORANGE);
# RSI signals show move below UpperThreshhold or move above LowerThreshhold
input RSIlength = 14;
#input threshold = 50;
input UpperThreshold = 70;
input LowerThreshold = 30;
input RSIaverageType = AverageType.WILDERS;
def CrossAboveSignal = RSI(length = RSIlength, averageType = RSIaverageType).RSI >= UpperThreshold;
def CrossBelowSignal = RSI(length = RSIlength, averageType = RSIaverageType).RSI <= LowerThreshold;
MacdValue.AssignValueColor(if CrossAboveSignal then Color.RED else if CrossBelowSignal then Color.RED else Color.WHITE);
MacdAvg.SetDefaultColor(GetColor(1)); #1 is cyan
ZeroLine.SetDefaultColor(GetColor(0));
Last edited: