The following code will plot Stochastic Full Diff divergence lines on the price bars. However, I would like to be able to see the divergence lines on the Stochastic Full Diff indicator in the sub graph. Yes, I understand that some of the Stochastic Full Diff code needs to have the # removed in order for it to plot sub graph, and the FullK and FullD def statements need to be changed to plot statements. However, the real issue is someplace in the divergence portion of the code, for when the above changes are made the divergence lines will plot at where the price level would be instead of on the FullK line.
def zeroline1 =45;
def zeroline2 =55;
def over_bought = 80;
def over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
def priceH = high;
def priceL = low;
def priceC = close;
input slowing_period = 2;
def smoothingType = 1;
def KLength = 50;
def displace = 0;
def Trnd = Average(close[-displace], KLength);
def c1 = priceC – Lowest(priceL, KPeriod);
def c2 = Highest(priceH, KPeriod) – Lowest(priceL, KPeriod);
def FastK = c1 / c2 * 100;
def FullK;
def FullD;
if smoothingType == 1 then { FullK = Average(FastK, slowing_period);
FullD = Average(FullK, DPeriod);
} else { FullK = ExpAverage(FastK, slowing_period);
FullD = ExpAverage(FullK, DPeriod);
}
#plot OverBought = over_bought;
#plot OverSold = over_sold;
def “Zero_Line1” =45;
def “Zero_Line2” =55;
#plot OverBought = over_bought;
#OverBought.SetDefaultColor (Color.Black);
#OverBought.SetLineWeight(2);
#OverBOught.HideTitle();
#plot OverSold = over_sold;
#OverSold.SetDefaultColor (Color.Black);
#OverSold.SetLineWeight(2);
#OverSold.HideTitle();
#”Zero_Line1″.HideTitle();
#”Zero_Line1″.SetDefaultColor(Color.Gray);
#”Zero_Line1″.SetStyle(Curve.LONG_DASH);
#”Zero_Line2″.SetDefaultColor(Color.Gray);
#”Zero_Line2″.SetStyle(Curve.LONG_DASH);
#”Zero_Line2″.HideTitle();
#FullD.AssignValueColor(if FullD > FullD[1] then Color.Blue else (if FullD == FullD[1] then Color.blue else Color.dark_orange));
#FullD.DefineColor(“Up”, Color.Blue);
#FullD.DefineColor(“Down”, Color.Dark_Orange);
#FullD.AssignValueColor(if FullD > FullD[1] then FullD.color(“Up”) else FullD.color(“Down”));
#FullD.SetStyle(Curve.SHORT_DASH);
#FullD.SetLineWeight(1);
#FullK.DefineColor(“Up”, Color.Blue);
#FullK.DefineColor(“Down”, Color.Dark_Orange);
#FullK.AssignValueColor(if FullK > FullK[1] then FullK.color(“Up”) else FullK.color(“Down”));
#FullK.AssignValueColor(if FullK > FullK[1] then color.blue else color.dark_orange);
#FullK.SetLineWeight(3);
#AddCloud(FullK, FullD);
input TrendLine = {EMA, SMA, default LRL, WMA, Hull};
input AlertOn = yes;
def price = close + low + high /4;
def Midline = 50;
def o = open;
def h = high;
def l = low;
def c = close;
def lowestLow = if FullK > “Zero_Line1” then 5 else if FullK < “Zero_Line1” and 5 < lowestLow[1] then 5 else lowestLow[1]; def lowestFullK = if FullK > MidLine then FullK else if FullK < MidLine and FullK < lowestFullK[1] then FullK else lowestFullK[1];
def divergentLow = if FullK < “Zero_Line1” and 5 <= lowestLow[1] and FullK > lowestFullK[1] then “Zero_Line1” else Double.NaN;
def highestHigh = if FullK < “Zero_Line2” then h else if FullK > “Zero_Line2” and h > highestHigh[1] then h else highestHigh[1];
def highestFullK = if FullK < MidLine then FullK else if FullK > MidLine and FullK > highestFullK[1] then FullK else highestFullK[1];
def divergentHigh = if FullK > “Zero_Line2” and h >= highestHigh and FullK < highestFullK then “Zero_Line2” else if FullK < “Zero_Line2” and c < o then Double.NaN else divergentHigh[1]; def swingHigh = if divergentHigh and price > price[12] then 1 else 0;;
def swingLow = if DivergentLow and price < Price[12] then -1 else 0;
Plot sh = if swinghigh then high else double.nan;
sh.setlineweight(2);
sh.setdefaultcolor(color.Blue);
Plot sl = if swinglow then low else double.nan;
sl.setlineweight(2);
sl.setdefaultcolor(color.Blue);
Like this:
Like Loading...
I have removed the code from your post. I need to make sure the code is free of copyright and that you have permission from the author to post it in this forum. Please provide a link showing where you acquired the code so I can research this further.
I actually found a CCI code on a forum at the following website (https://researchtrade.com/forum/read.php?7,2258,6273), and then personally modified it to fit Stochastics Full Diff.
You can also find a version of the CCI code that I found at https://www.quesearch.com/msgsdisp.php?parm=tosthinkscript-fwd-cci-divergence