# MTF Stochastic Oscillator for ThinkorSwim

#### Johnny Cash

##### Member
Could anyone tell me how to plot the Stochastic Oscillator on multiple timeframes? Both daily and weekly slow stochastic on the same chart.

#### BenTen

Staff member
Staff
VIP
If you're looking for a multi timeframe option for the Stochastic Oscillator, try this code:

Code:
``````# Stochastic Full MTF
# blt
# 7.15.2016

# 07.15.2016 blt v0, initial release
# 07.15.2016 blt v1, added on/off input for bubbles

# Here is a Stochastic Full_MTF indicator coded with a similar look
# as the RSI_Laguerre_Time_MTF uses. On the 1min chart image of DAL,
# I have the Stochastic set to a fast seting of 10,3,1, using higher
# agg period of 2min for the Stochastic.
#
# I used TOS Stochastic Full because with it you can do all three
# flavors (full 10,10,3; fast 10,3,1; slow 10,10,1) just changing
# the inputs
#
# This is an enhanced version with inputs to show bubbles or not.
# If you want to see it in expansion to the right, then you need to
# increase your right expansion to approx 35. The bubbles were
# already moveable at the inputs m and z

declare lower;

input usehigheraggperiod = {default "Current", "Higher"};

# Current uses the current chart agg. So if you are on a 1min chart
# the indicator is based on 1min. If you select higher, then whatever
# agg you enter at the input will be what is used for the RSI. So
# if you are on a 1min chart and higher is set to 2min, then a 2min
# RSI and the entries and targets are 2min based.

input agg                = AggregationPeriod.TWO_MIN;
input atrlength          = 14;
input atrfactor          = 3;

# Variables:
def o;
def h;
def l;
def c;
def error = usehigheraggperiod == usehigheraggperiod."Higher" and GetAggregationPeriod() > agg;
switch (usehigheraggperiod) {
case Current:
o = (open + close) / 2;
h = Max(high, close);
l = Min(low, close);
c = (o + h + l + close) / 4;
case Higher:
if error {
o = Double.NaN;
h = Double.NaN;
l = Double.NaN;
c = Double.NaN;
} else {
o = (open(period = agg)     + close(period = agg)) / 2;
h = Max(high(period = agg)  , close(period = agg));
l = Min(low(period = agg)   , close(period = agg));
c = ((open(period = agg)    + close(period = agg)) / 2
+ Max(high(period = agg), close(period = agg))
+ Min(low(period = agg) , close(period = agg))
+ close(period = agg)) / 4;
}
}
AddLabel(error, "Chart Aggregation Period is greater than RSI aggregation period. Need to Change input to a higher agg than current chart aggregation or choose 'Current' at input usehigheraggperiod", Color.WHITE);

#TOS StochasticFull
#used TOS StochasticFull because with it you can do all 3 (full 10,10,3; fast 10,3,1; slow 10,10,1) with it by just changing the inputs for kperiod
input over_bought = 80;
input over_sold   = 20;
input KPeriod = 10;
input DPeriod = 10;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
def priceH = h;
def priceL = l;
def priceC = c;

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 =  if isnan(close) then double.nan else MovingAverage(averageType, FastK, slowing_period);
plot FullD =  if isnan(close) then double.nan else MovingAverage(averageType, FullK, DPeriod);

plot OverBought = if isnan(close) then double.nan else over_bought;
plot OverSold   = if isnan(close) then double.nan else over_sold;

FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));

def ob = over_bought;
def os = over_sold;
def stou = if FullK crosses above ob or
FullK crosses above os
then 1
else if stou == 1 and !(FullK crosses below ob) and FullK > os
then 1
else 0;
FullK.AssignValueColor(if stou
then Color.GREEN
else Color.RED);

then FullK
else Double.NaN,
OverBought,
Color.GREEN, Color.GREEN);
then OverSold
else Double.NaN,
FullK,
Color.RED, Color.RED);

plot mid   = if isnan(close) then double.nan else 50;
plot lineh = if isnan(close) then double.nan else 110;
plot linel = if isnan(close) then double.nan else -10;
lineh.setdefaultColor(color.gray);
linel.setdefaultColor(color.gray);
lineh.hidebubble();
linel.hidebubble();

AddLabel(yes, "STO (" + agg / 60000 + "min): " + Round(FullK, 0),
if FullK > 0
then if FullK > FullK
then Color.DARK_GREEN
else Color.GREEN
else if FullK < FullK
then Color.DARK_RED
else  Color.RED);

def atr    = Average(TrueRange(h, c, l), atrlength);
def entry  = if FullK crosses above OverSold or stou == 0 and FullK crosses above OverBought
then close
else if FullK crosses below OverBought or stou and FullK crosses below OverSold
then close
else entry;
def ebar   = if FullK crosses above OverSold or stou == 0 and FullK crosses above OverBought
then BarNumber()
else if FullK crosses below OverBought or stou and FullK crosses below OverSold
then BarNumber()
else Double.NaN;
def target = if FullK crosses above OverSold or stou == 0 and FullK crosses above OverBought
then Round((close + (atrfactor * atr)) / TickSize(), 0) * TickSize()
else if FullK crosses below OverBought or stou and FullK crosses below OverSold
then Round((close - (atrfactor * atr)) / TickSize(), 0) * TickSize()
else target;
def u_d    = if FullK crosses above OverSold or stou == 0 and FullK crosses above OverBought
then 1
else if FullK crosses below OverBought or stou and FullK crosses below OverSold
then -1
else u_d;
def goalu  = if u_d > 0  and  high >= target
then 1
else if goalu == 1 and u_d > 0
then 1
else 0;
def goald  = if u_d < 0 and  low <= target
then 1
else if goald == 1 and u_d < 0
then 1
else 0;

AddLabel(1,  if error then " "
else  "T:"+(if u_d > 0 then "Up " else "Dn") + " " + AsText(target) +
(if u_d < 0
then if  goald == 0
then " Need " + AsText(Round((target - close), 2))
else " Met "
else "") +
(if u_d > 0
then if goalu == 0
then " Need " + AsText(Round((target - close), 2))
else " Met "
else ""),
if u_d < 0 and !goald or u_d > 0 and !goalu
then Color.WHITE
else Color.GREEN);
input showentrybubble = yes;
input m = 2;
def  m1 = m + 1;
if FullK crosses above OverSold or stou and FullK crosses below OverSold
then OverSold
else OverBought,
"Entry: " + AsText(Round(entry, 2)),
if u_d > 0
then Color.GREEN
else Color.RED,
if u_d > 0
then no
else yes);
input showtargetbubble = yes;
if Between(FullK[m1], OverSold, OverBought)
then FullK[m1]
else if u_d[m1] > 0
then 80
else 20,
if error[m1]
then " "
else "T:"+(if u_d[m1] > 0 then "Up " else "Dn ") + " " + AsText(target[m1]) +
(if u_d[m1] < 0 and !goald[m1]
then "\nDiff     " + AsText(Round((target[m1] - close[m1]), 2))
else if u_d[m1] > 0 and !goalu[m1]
then "\nDiff     " + AsText(Round((target[m1] - close[m1]), 2))
else " Met "),
if u_d[m1] < 0 and !goald[m1] or u_d[m1] > 0 and !goalu[m1]
then Color.WHITE
else Color.GREEN,
if Between(FullK[m1], OverSold, OverBought)
then if u_d[m1] < 0
then no
else yes
else if u_d[m1] < 0
then no
else yes);
#StochasticFull Bubble
input showstochasticbubble = yes;
input  z = 30;#Hint z: = number of spaces to move the StochasticFull bubbles sideways
def   z1 = z + 1;
mid[z1],
"S",
if stou[z1]
then Color.GREEN
else Color.RED);``````

• diazlaz and markos

#### HighBredCloud

##### Well-known member
@BenTen Does the time aggregation actually work? I tried to switch it around from a 5 min to 15 min but the Stochastic never changed...it stayed the same...hence I can't really figure out the MTF part in it...

#### horserider

##### Well-known member
VIP
@HighBredCloud The study BenTen showed will display the chart time frame or a higher time frame, not both at the same time. Try the ones in post 4.

• HighBredCloud and BenTen

#### Johnny Cash

##### Member
Here's a code for a multi time frame stochastic. This will allow you to plot a stochastic for any time frame that is greater than the one that your chart is currently on. For example, it can be helpful to know what the hourly stochastic looks like if you're trading on a 5 min chart. Hope it is helpful to someone out there.

Code:
``````declare lower;

input over_bought = 80;
input over_sold = 20;
input aggregationPeriod = AggregationPeriod.DAY;
input KPeriod = 10;
input DPeriod = 10;
input slowing_period = 3;

plot FullK = Average((close(period = aggregationPeriod) - Lowest(low(period = aggregationperiod), KPeriod)) / (Highest(high(period = aggregationperiod), KPeriod) - Lowest(low(period = aggregationperiod), KPeriod)) * 100, slowing_period);
plot FullD = Average(Average((close(period = aggregationPeriod) - Lowest(low(period = aggregationperiod), KPeriod)) / (Highest(high(period = aggregationperiod), KPeriod) - Lowest(low(period = aggregationperiod), KPeriod)) * 100, slowing_period), DPeriod);

plot OverBought = over_bought;
plot OverSold = over_sold;``````

• BenTen

#### Ninja Bull

##### Member
Hey Ben, I came across this Slow Stochastic MTF that seems simple but powerful and all in one single study.
. Is this something that you can help us with?

• tonyvu, asharmax and Johnny Cash

#### Johnny Cash

##### Member
Post # 8 is a higher time frame stochastic.

#### Anita

##### New member
2019 Donor
@Johnny Cash It's exactly what I was looking for; Thank you!

• Johnny Cash

#### AnAirdrop

##### New member
I'm trying to create a weekly stochastic indicator that I can use on my daily chart, but the plot points don't seem to get smoothed like they do on the tradingview version of the indicator. Any thoughts how I could fix that? Here is the code I'm currently using.

Code:
``````declare lower;

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

def dailywk;
if GetAggregationPeriod() < AggregationPeriod.WEEK {
dailywk = AggregationPeriod.WEEK;
} else {
dailywk = AggregationPeriod.DAY;
}

#def plwk = movingaverage(averagetype.simple,priceL,5);
#def phwk = movingaverage(averagetype.simple,priceH,5) ;
#def pcwk = movingaverage(averagetype.simple,priceC,5) ;

plot SlowK = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).FullK
;

plot SlowD = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).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 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);``````

This is how it displays on thinkorswim:
https://ibb.co/XjjsxXF

This is how it displays on tradingview:
https://ibb.co/PjTyVfR

Any thoughts how I can get those plots smoothed out?

#### SleepyZ

##### Well-known member
VIP
I'm trying to create a weekly stochastic indicator that I can use on my daily chart, but the plot points don't seem to get smoothed like they do on the tradingview version of the indicator. Any thoughts how I could fix that? Here is the code I'm currently using.

Code:
``````#Example Smooth Plot HigherAgg on LowerAgg
#Usethinkscript request AnAirDrop
#Sleepyz

input show_original_plot = yes;
input show_smooth_plot   = yes;

declare lower;

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

def dailywk;
if GetAggregationPeriod() < AggregationPeriod.WEEK {
dailywk = AggregationPeriod.WEEK;
} else {
dailywk = AggregationPeriod.DAY;
}

#def plwk = movingaverage(averagetype.simple,priceL,5);
#def phwk = movingaverage(averagetype.simple,priceH,5) ;
#def pcwk = movingaverage(averagetype.simple,priceC,5) ;

plot SlowK = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).FullK
;
slowk.sethiding(show_original_plot == no);

plot SlowD = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).FullD
;
slowd.sethiding(show_original_plot == no);

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 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);

#Smoothed Plots
def minutes = aggp/60000;
def bar = BarNumber();
def x = if bar == 1 or bar % ((Ceil(minutes) ) / (GetAggregationPeriod() / 60000)) == 0
then slowk
else x;

def xx = (if x!=x then xx + 1 else xx);
def xxx = if  xx!= xx then x else Double.NaN;
plot xsmooth =if !show_smooth_plot then double.nan else  if isnan(close[-1]) then slowk else xxx;
xsmooth.EnableApproximation();

def x1 = if bar == 1 or bar % ((Ceil(minutes) ) / (GetAggregationPeriod() / 60000)) == 0
then slowd
else x1;

def xx1 = (if x1!=x1 then xx1 + 1 else xx);
def xxx1 = if  xx1!= xx1 then x1 else Double.NaN;
plot x1smooth = if !show_smooth_plot then double.nan else if isnan(close[-1]) then slowd else xxx1;
x1smooth.EnableApproximation();

Any thoughts how I can get those plots smooth``````
ed out?

See if the following adaption of TOS approximates what you see on TradingView. This is meant to connect the first bars of the Higher Agg Indicator to smooth the Original TOS plot of the Higher Agg.
Code:
``````#Example Smooth Plot HigherAgg on LowerAgg
#Usethinkscript request AnAirDrop
#Sleepyz

input show_original_plot = yes;
input show_smooth_plot   = yes;

declare lower;

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

def dailywk;
if GetAggregationPeriod() < AggregationPeriod.WEEK {
dailywk = AggregationPeriod.WEEK;
} else {
dailywk = AggregationPeriod.DAY;
}

#def plwk = movingaverage(averagetype.simple,priceL,5);
#def phwk = movingaverage(averagetype.simple,priceH,5) ;
#def pcwk = movingaverage(averagetype.simple,priceC,5) ;

plot SlowK = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).FullK
;
slowk.sethiding(show_original_plot == no);

plot SlowD = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).FullD
;
slowd.sethiding(show_original_plot == no);

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 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);

#Smoothed Plots
def minutes = aggp/60000;
def bar = BarNumber();
def x = if bar == 1 or bar % ((Ceil(minutes) ) / (GetAggregationPeriod() / 60000)) == 0
then slowk
else x;

def xx = (if x!=x then xx + 1 else xx);
def xxx = if  xx!= xx then x else Double.NaN;
plot xsmooth =if !show_smooth_plot then double.nan else  if isnan(close[-1]) then slowk else xxx;
xsmooth.EnableApproximation();

def x1 = if bar == 1 or bar % ((Ceil(minutes) ) / (GetAggregationPeriod() / 60000)) == 0
then slowd
else x1;

def xx1 = (if x1!=x1 then xx1 + 1 else xx);
def xxx1 = if  xx1!= xx1 then x1 else Double.NaN;
plot x1smooth = if !show_smooth_plot then double.nan else if isnan(close[-1]) then slowd else xxx1;
x1smooth.EnableApproximation();`````` Last edited:
• tonyvu

#### Johnny Cash

##### Member
Wow, that is awesome work, been looking for that for a long time.
Question: is it possible to get rid of the zig zag line( the original plot) when i set to "no" the all thing disappears.

• SleepyZ

#### SleepyZ

##### Well-known member
VIP
Wow, that is awesome work, been looking for that for a long time.
Question: is it possible to get rid of the zig zag line( the original plot) when i set to "no" the all thing disappears.

Oops. thank you for the heads up. I fixed the code above in #13. I forgot that I needed those plot statements. Following is the corrected code:
Code:
``````#Example Smooth Plot HigherAgg on LowerAgg
#Usethinkscript request AnAirDrop
#Sleepyz

input show_original_plot = yes;
input show_smooth_plot   = yes;

declare lower;

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

def dailywk;
if GetAggregationPeriod() < AggregationPeriod.WEEK {
dailywk = AggregationPeriod.WEEK;
} else {
dailywk = AggregationPeriod.DAY;
}

#def plwk = movingaverage(averagetype.simple,priceL,5);
#def phwk = movingaverage(averagetype.simple,priceH,5) ;
#def pcwk = movingaverage(averagetype.simple,priceC,5) ;

plot SlowK = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).FullK
;
slowk.sethiding(show_original_plot == no);

plot SlowD = reference StochasticFull(
over_bought = over_bought,
over_sold = over_sold,
KPeriod = KPeriod,
DPeriod = DPeriod,
priceH = high(period = dailywk),
priceL = low(period = dailywk),
priceC = close(period = dailywk),
slowing_period = 3).FullD
;
slowd.sethiding(show_original_plot == no);

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 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);

#Smoothed Plots
def minutes = aggp/60000;
def bar = BarNumber();
def x = if bar == 1 or bar % ((Ceil(minutes) ) / (GetAggregationPeriod() / 60000)) == 0
then slowk
else x;

def xx = (if x!=x then xx + 1 else xx);
def xxx = if  xx!= xx then x else Double.NaN;
plot xsmooth =if !show_smooth_plot then double.nan else  if isnan(close[-1]) then slowk else xxx;
xsmooth.EnableApproximation();

def x1 = if bar == 1 or bar % ((Ceil(minutes) ) / (GetAggregationPeriod() / 60000)) == 0
then slowd
else x1;

def xx1 = (if x1!=x1 then xx1 + 1 else xx);
def xxx1 = if  xx1!= xx1 then x1 else Double.NaN;
plot x1smooth = if !show_smooth_plot then double.nan else if isnan(close[-1]) then slowd else xxx1;
x1smooth.EnableApproximation();``````
Thank you for the kind remark.

Last edited:

#### rajdixon

##### New member
VIP
I am looking for help to create a label that pulls data from a higher aggregation period. For example, I want to look at the daily chart and have a label that tells me if the StochasticSlow, SlowK is greater than the StochasticSlow, SlowK from the candle before on the weekly chart. I wrote the following code below but it only tells me the information from the current aggregation period that I am looking at and not the weekly. Any help would be greatly appreciated.
input firstAggregation = AggregationPeriod.WEEK;

def StochasticSlowUp;

if GetAggregationPeriod() <= firstAggregation
{

StochasticSlowUp = StochasticSlow("average type" = "EXPONENTIAL")."SlowK" is greater than StochasticSlow("average type" = "EXPONENTIAL")."SlowK" from 1 bars ago;

}
else {

StochasticSlowUp = 0;

}

#### SleepyZ

##### Well-known member
VIP
I am looking for help to create a label that pulls data from a higher aggregation period. For example, I want to look at the daily chart and have a label that tells me if the StochasticSlow, SlowK is greater than the StochasticSlow, SlowK from the candle before on the weekly chart. I wrote the following code below but it only tells me the information from the current aggregation period that I am looking at and not the weekly. Any help would be greatly appreciated.
input firstAggregation = AggregationPeriod.WEEK;

def StochasticSlowUp;

if GetAggregationPeriod() <= firstAggregation
{

StochasticSlowUp = StochasticSlow("average type" = "EXPONENTIAL")."SlowK" is greater than StochasticSlow("average type" = "EXPONENTIAL")."SlowK" from 1 bars ago;

}
else {

StochasticSlowUp = 0;

}

Since the stochastic indicators use prices of high, low, close, you cannot reference the indicator easily to make it multi-timeframe usable. The following uses the script function to do that. The picture shows the label with the stochasticslow data with the corresponding chart below showing the same data for the weekly chart. Ruby:
``````input firstAggregation = AggregationPeriod.WEEK;

Script stochslow {
input agg = aggregationPeriod.WEEK;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
def priceH = high(period=agg);
def priceL = low(period=agg);
def priceC = close(period=agg);
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 StochasticSlowUp;

if GetAggregationPeriod() <= firstAggregation
{

StochasticSlowUp = stochslow().SlowK from 1 bars ago;

}
else {

StochasticSlowUp = 0;

} ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?