Hello,

I have came across this post,

https://usethinkscript.com/threads/...ivergence-as-picture-below.17589/#post-136165 , and since I have no clue how to code, I had chat switch it to Stochastic Full, you will see the code below with some weird things I did myself. Now what the problem is...After the cycle above Overbought(OB) or below Oversold (OS) the code does not move to the next high or low, I would like if that bottom line had moved to the blue area, I want to see it plot from the highs or lows of %K, (black area) it seems to be plotting off %D, this is the Russell (RUT) and on AAPL see how far it is away from %K highs, if you will adjust this it would be great.

P.S

MoeBettaBlues

I know you are looking at this code like what in the world is this, but we make work, how we know how and chat only get so far...smile !

declare lower;

input over_bought = 70;

input over_sold = 30;

input K_Period = 5;

input D_Period = 3;

input priceH = high;

input priceL = low;

input priceC = close;

input slowing_period = 2;

input averageType = AverageType.SIMPLE;

input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def lowest_k = Lowest(priceL, K_Period);

def c1 = priceC - lowest_k;

def c2 = Highest(priceH, K_Period) - lowest_k;

def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

plot FullK = MovingAverage(averageType, FastK, slowing_period);

plot FullD = MovingAverage(averageType, FullK, D_Period);

plot OverBought = over_bought;

plot OverSold = over_sold;

def upK = FullK crosses above OverSold;

def upD = FullD crosses above OverSold;

def downK = FullK crosses below OverBought;

def downD = FullD crosses below OverBought;

FullK.SetDefaultColor(Color.WHITE);

FullD.SetDefaultColor(Color.RED);

FullD.SetLineWeight(2);

OverBought.SetDefaultColor(GetColor(1));

OverSold.SetDefaultColor(GetColor(1));

# Arrows when %K crosses above %D and is above the OVERSOLD line

plot ArrowUp = if FullK crosses FullD and FullK then FullD else Double.NaN;

ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

ArrowUp.SetDefaultColor(Color.UPTICK);

ArrowUp.SetLineWeight(2);

plot ZeroLine = 50;

#__________________#______________________________#_________________________

def c = close;

def h = high;

def l = low;

def highest_high = Highest(h, k_period);

def lowest_low = Lowest(l, k_period);

def fast_k = if highest_high != lowest_low then (c - lowest_low) / (highest_high - lowest_low) * 100 else 0;

def slow_k = ExpAverage(fast_k, slowing_period);

def slow_d = ExpAverage(slow_k, d_period);

def bar = BarNumber();

def Currh = if slow_k > OverBought then fold i = 1 to Floor(k_period / 2) with p = 1 while p do slow_k > getValue(slow_k, -i) else 0;

def CurrPivotH = if (bar > k_period and slow_k == highest(slow_k, Floor(k_period/2)) and Currh) then slow_k else double.NaN;

def Currl = if slow_k < OverSold then fold j = 1 to Floor(k_period / 2) with q = 1 while q do slow_k < getValue(slow_k, -j) else 0;

def CurrPivotL = if (bar > k_period and slow_k == lowest(slow_k, Floor(k_period/2)) and Currl) then slow_k else double.NaN;

def CurrPHBar = if !isNaN(CurrPivotH) then bar else CurrPHBar[1];

def CurrPLBar = if !isNaN(CurrPivotL) then bar else CurrPLBar[1];

def PHpoint = if !isNaN(CurrPivotH) then CurrPivotH else PHpoint[1];

def priorPHBar = if PHpoint != PHpoint[1] then CurrPHBar[1] else priorPHBar[1];

def PLpoint = if !isNaN(CurrPivotL) then CurrPivotL else PLpoint[1];

def priorPLBar = if PLpoint != PLpoint[1] then CurrPLBar[1] else priorPLBar[1];

def HighPivots = bar >= highestAll(priorPHBar);

def LowPivots = bar >= highestAll(priorPLBar);

def pivotHigh = if HighPivots then CurrPivotH else double.NaN;

plot PlotHline = pivotHigh;

PlotHline.enableApproximation();

PlotHline.SetDefaultColor(GetColor(7));

PlotHline.SetStyle(Curve.Short_DASH);

plot pivotLow = if LowPivots then CurrPivotL else double.NaN;

pivotLow.enableApproximation();

pivotLow.SetDefaultColor(GetColor(7));

pivotLow.SetStyle(Curve.Short_DASH);

plot PivotDot = if !isNaN(pivotHigh) then pivotHigh else if !isNaN(pivotLow) then pivotLow else double.NaN;

pivotDot.SetDefaultColor(GetColor(7));

pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);

pivotDot.SetLineWeight(3);

# End Code Stochastic Full with Divergence