# Need % percentage change in Stochastic

##### Member
I need guidance on how to add code to this Slow Stochastic that essentially measures the distance between the Kperiod & Dperiod lines. I want to see the distance measured in percentage terms. Can someone please help?

UPDATE: I figured it out myself: plot percentChg = ((SlowK / SlowD)-1) * 100;

Last edited:

#### Johnny Cash

##### Member
VIP
I need guidance on how to add code to this Slow Stochastic that essentially measures the distance between the Kperiod & Dperiod lines. I want to see the distance measured in percentage terms. Can someone please help?

UPDATE: I figured it out myself: plot percentChg = ((SlowK / SlowD)-1) * 100;

could you share your script with that line in.
i am getting a error code
Thanks

##### Member
It will only show a value not a line. This is still a work in progress where I am working to improve the calculation, but it does work as show below....

Code:
``````declare lower;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On SlowK", "On SlowD", "On SlowK & SlowD"};

plot SlowK = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageType).FullK;
plot SlowD = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageType).FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;

def upK = SlowK crosses above OverSold;
def upD = SlowD crosses above OverSold;
def downK = SlowK crosses below OverBought;
def downD = SlowD crosses below OverBought;

plot percentChg = ((SlowK / SlowD)-1) * 100;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
UpSignal = Double.NaN;
DownSignal = Double.NaN;
case "On SlowK":
UpSignal = if upK then OverSold else Double.NaN;
DownSignal = if downK then OverBought else Double.NaN;
case "On SlowD":
UpSignal = if upD then OverSold else Double.NaN;
DownSignal = if downD then OverBought else Double.NaN;
case "On SlowK & SlowD":
UpSignal = if upK or upD then OverSold else Double.NaN;
DownSignal = if downK or downD then OverBought else Double.NaN;
}

UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");

SlowK.setDefaultColor(GetColor(5));
SlowD.setDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);``````