Chaiken Money Flow (CMF), RSI and MACD as a combined trading signal.
Ruby:
# Chaikin Money Flow, RSI and MACD Combined Signal Mobius 08.22.2021
declare lower;
input longLengthCMF = 10;
input shortLengthCMF = 3;
input lengthRSI = 14;
input fastLengthMACD = 12;
input slowLengthMACD = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;
input averageTypeRSI = AverageType.WILDERS;
script S
{
input c = close;
def Min = -100;
def Max = 100;
def hh = highestAll(c);
def ll = lowestAll(c);
plot Range = (((Max - Min) * (c - ll)) / (hh - ll)) + Min;
}
def c = close;
def h = high;
def l = low;
def v = volume;
def NetChgAvg = MovingAverage(averageTypeRSI, c - c[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(c - c[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def CLV = if h != l then ((c - l) - (h - c)) / (h - l) else 1;
def AccDist = (TotalSum(v * CLV));
plot Value = S(MovingAverage(averageTypeMACD, close, fastLengthMACD) -
MovingAverage(averageTypeMACD, close, slowLengthMACD));
plot Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
plot RSI = S(50 * (ChgRatio + 1));
plot COSC = s(ExpAverage(accDist, shortLengthCMF) - ExpAverage(accDist, longLengthCMF));
plot zero = if isNaN(c) then double.nan else 0;
Value.AssignValueColor(if Value > Avg then color.green else color.red);
Avg.AssignValueColor(if Value > Avg then color.green else color.red);
RSI.AssignValueColor(if RSI > 0 then color.green else color.red);
COSC.AssignValueColor(if COSC > 0 then color.green else color.red);
zero.SetDefaultColor(Color.Light_Gray);
def up = Value > Avg and RSI > 0 and COSC > 0;
def dn = Value < Avg and RSI < 0 and COSC < 0;
addCloud(Value, Avg, color.green, color.red);
addCloud(if up then 100 else double.nan, -100, color.green);
addCloud(if dn then 100 else double.nan, -100, color.red);
Last edited: