Paint Bars Based on the Stochastic D?

JWrsb

New member
Hi. First of all, just wanted to say I love this community. Everyone is so helpful.

SO here's my question. I have a study that paints the bars based on the RSI. I find it useful.

But I was wondering if someone could help me with the TOS Stochastic Full Indicator - so that it paints the bars based on the FullD value with values for 0 - 100 - with a different definable color for 0, 10, 20 , 30, ... all the way to 100.

Here's the code for the TOS Stochastic Full indicator. Thanks for any help!

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#

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 slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - 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, DPeriod);

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;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "On FullK":
    UpSignal = if upK then OverSold else Double.NaN;
    DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
    UpSignal = if upD then OverSold else Double.NaN;
    DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
    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");

FullK.SetDefaultColor(GetColor(5));
FullD.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);
 

BenTen

Administrative
Staff
VIP
Something like: if FullD is >= 10 then color.green, if FullD >= 20 then color.blue?

You need to give us the color template and values for each color so we can help.
 

JWrsb

New member
Thanks BenTen!

Something like this:

Code:
AssignPriceColor(if FullD >= 0 then CreateColor (128,0,106)
else if FullD >= 10 then CreateColor (204,0,68)
else if FullD >= 20  then CreateColor (255,0,0)
else if FullD >= 30 then CreateColor (255,102,25)
else if FullD >= 40 then CreateColor (255,170,0)
else if FullD >= 50 then CreateColor (170,255,0)
else if FullD >= 60 then CreateColor (43,255,0)
else if FullD >= 70 then CreateColor (0,255,170)
else if FullD >= 80 then CreateColor (0,213,255)
else if FullD >= 90 then CreateColor (221,204,255)
else CreateColor (255,255,25) );

I don't know how to incorporate this into the script to make it paint the bars.
 

JWrsb

New member
OK - I figured it out!!
I needed to reverse the order of them so they were listed highest to lowest, otherwise they were all being painted according to the first condition: if FullD >= 0 then CreateColor (128,0,106). Duh.

Thanks for helping me think!
 

drkellog

New member
VIP
JWrsb,

I went ahead and edited the code because I wanted to see what it looks like. Looks pretty cool. Here is the code....

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#

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 slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - 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, DPeriod);

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;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "On FullK":
    UpSignal = if upK then OverSold else Double.NaN;
    DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
    UpSignal = if upD then OverSold else Double.NaN;
    DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
    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");

FullK.SetDefaultColor(GetColor(5));
FullD.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);

AssignPriceColor(if FullD <= 0 then CreateColor (128,0,106)
else if FullD >= 90 then CreateColor (221,204,255)
else if FullD >= 80 then CreateColor (0,213,255)
else if FullD >= 70 then CreateColor (0,255,170)
else if FullD >= 60 then CreateColor (43,255,0)
else if FullD >= 50 then CreateColor (170,255,0)
else if FullD >= 40 then CreateColor (255,170,0)
else if FullD >= 30 then CreateColor (255,102,25)
else if FullD >= 20  then CreateColor (255,0,0)
else if FullD >= 10 then CreateColor (204,0,68)
else CreateColor (255,255,25) );

and here is the download link for thinkorswim... http://tos.mx/Y7UEcFj
 
Last edited by a moderator:

JWrsb

New member
Thanks everyone. I think this will be useful spotting divergences in the price action and the stochastic indicator.

Here's the code. Try it out and let me know what you think. :)

Code:
# Cust_Stochastic_Full_ColorBars v1.1
# Coded using the StochasticFull code from TOS.
# Added the Color Bars to make spotting divergence in price action and Stochastic indicator easier to spot.
# Wallace Stochastic Full Color Bars
# Version 1.1


declare lower;

input KPeriod = 7;
input DPeriod = 2;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input priceH = high;
input priceL = low;
input priceC = close;
input over_bought = 80;
input over_sold = 20;
input centerline = 50;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

input l1 = 6;
input l2 = 12;
input l3 = 20;
input l4 = 28;
input l5 = 35;
input m1 = 46;
input m2 = 54;
input h1 = 65;
input h2 = 72;
input h3 = 80;
input h4 = 90;
input h5 = 94;

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - 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, DPeriod);

plot OverBought = over_bought;
plot OverSold = over_sold;
plot CenterL = centerline;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "On FullK":
    UpSignal = if upK then OverSold else Double.NaN;
    DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
    UpSignal = if upD then OverSold else Double.NaN;
    DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
    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");

FullK.SetDefaultColor(GetColor(5));
FullD.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);

AssignPriceColor(
if FullD >= h5 then CreateColor (255,245,255)
else if FullD >= h4 then CreateColor (255,190,248)
else if FullD >= h3 then CreateColor (0,213,255)
else if FullD >= h2 then CreateColor (0,255,170)
else if FullD >= h1 then CreateColor (43,255,0)
else if FullD >= m2 then CreateColor (170,255,0)
else if FullD >= m1 then CreateColor (255,255,115)
else if FullD >= l5 then CreateColor (255,170,0)
else if FullD >= l4 then CreateColor (255,102,25)
else if FullD >= l3 then CreateColor (255,55,0)
else if FullD >= l2 then CreateColor (200,0,15)
else if FullD >= l1 then CreateColor (177,17,68)
else if FullD >= 0 then CreateColor (128,0,106)
else CreateColor (255,255,25) );
 

cswu1211

Member
VIP
I brought the above two studies (post #6 by JWrsb and post #5 by drkellog) together. It seems quite different. I browse thru two threads, but didn't quite get a good grasp of what are the differences between them. where can I identify the parameter section in the threads? maybe a great chance for me to learn the script writing.

Could you help?!

 

JWrsb

New member
@cswu1211 The main difference, as I recall, is the ability to set the low, mid, and high levels yourself. I've found it useful when trading different timeframes to be able to set the levels differently. Also you'll notice that the K and D periods and the slowing factors have different default values.
 

cswu1211

Member
VIP
@cswu1211 The main difference, as I recall, is the ability to set the low, mid, and high levels yourself. I've found it useful when trading different timeframes to be able to set the levels differently. Also you'll notice that the K and D periods and the slowing factors have different default values.
tks, greatly appreciated. could you show me WHICH section of the script has these info for further modifications
 

Similar threads

Top