I found this Free indicator link from the video below.
It works off MACD.
It auto draws the divergence line on the chart both up top and bottom so two parts
Can someone change this into a Stochastic version with the K and D so it draws the lines on both upper and lower but using the D Stochastic it looks for to create the lines it draws. The MACD misses a lot that the D Stochastic would find.
Here is the TOS link to it
http://tos.mx/e4lWbJJ
Here is the video link showing it is free and it has the TOS link in the video text area at the bottom.
It works off MACD.
It auto draws the divergence line on the chart both up top and bottom so two parts
Can someone change this into a Stochastic version with the K and D so it draws the lines on both upper and lower but using the D Stochastic it looks for to create the lines it draws. The MACD misses a lot that the D Stochastic would find.
Ruby:
# Mechanical MACD Divergence (lower chart)
# with both standard & volume-weighted MACD
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input MACD_Type = {default "Standard", "Volume Weighted"};
input averageType = AverageType.EXPONENTIAL;
def fastAvg;
def slowAvg;
switch (MACD_Type) {
case "Standard":
fastAvg = MovingAverage(averageType, close, fastLength);
slowAvg = MovingAverage(averageType, close, slowLength);
case "Volume Weighted":
fastAvg = sum(volume * close, fastLength) / sum(volume, fastLength);
slowAvg = Sum(volume * close, slowLength) / Sum(volume, slowLength);
}
plot Value = fastAvg - slowAvg;
plot Avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
def V = Diff < 0 and Diff < Diff[1] and Diff < Diff[-1];
def firstV = if Diff > 0 then 0 else if V then 1 else firstV[1];
def LD = if Diff crosses below 0 then Diff else if Diff < LD[1] then Diff else LD[1];
def vBar = if Diff == LD then BarNumber() else vBar[1];
def pvBar = if Diff crosses above 0 then vBar[1] else pvBar[1];
def bullV = (V and firstV[1] == 0 and Diff > GetValue(Diff, BarNumber() - pvBar)) and (low < GetValue(low, BarNumber() - pvBar));
def A = Diff > 0 and Diff > Diff[1] and Diff > Diff[-1];
def firstA = if Diff < 0 then 0 else if A then 1 else firstA[1];
def HD = if Diff crosses above 0 then Diff else if Diff > HD[1] then Diff else HD[1];
def aBar = if Diff == HD then BarNumber() else aBar[1];
def paBar = if Diff crosses below 0 then aBar[1] else paBar[1];
def bearA = (A and firstA[1] == 0 and Diff < GetValue(Diff, BarNumber() - paBar)) and (high > GetValue(high, BarNumber() - paBar));
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
# calculate bull div line
def cnV = fold i = 1 to lastBar with b = Double.NaN while IsNaN(b) do if GetValue(bullV, -i) == 1 then i else Double.NaN;
def startBullDiv = BarNumber() == GetValue(pvBar, -cnV);
def isBullDiv = if startBullDiv then 1 else if bullV[1] then 0 else isBullDiv[1];
def mBull = if startBullDiv then (GetValue(Diff, -cnV) - Diff) / cnV else mBull[1];
def line1 = if startBullDiv then Diff + (LowestAll(value) * 0.05) else line1[1] + mBull;
plot bullDivLine = if isBullDiv then line1 else Double.NaN;
bullDivLine.SetDefaultColor(Color.YELLOW);
bullDivLine.SetLineWeight(2);
# calculate bear div line
def cnA = fold j = 1 to lastBar with c = Double.NaN while IsNaN(c) do if GetValue(bearA, -j) == 1 then j else Double.NaN;
def startBearDiv = BarNumber() == GetValue(paBar, -cnA);
def isBearDiv = if startBearDiv then 1 else if bearA[1] then 0 else isBearDiv[1];
def mBear = if startBearDiv then (GetValue(Diff, -cnA) - Diff) / cnA else mBear[1];
def line2 = if startBearDiv then Diff + (HighestAll(value) * 0.05) else line2[1] + mBear;
plot bearDivLine = if isBearDiv then line2 else Double.NaN;
bearDivLine.SetDefaultColor(Color.DARK_ORANGE);
bearDivLine.SetLineWeight(2);
Here is the TOS link to it
http://tos.mx/e4lWbJJ
Here is the video link showing it is free and it has the TOS link in the video text area at the bottom.
Last edited by a moderator: