MTF Stochastic "Stoplight" Upper Study

Dixon72

New member
VIP
Hey everyone, new to the site. I've enjoyed sifting through the collection of indicators on this site and it's inspired me to try some scripting of my own. Disclaimer: I **** and am still learning. I've tried piecing together some code (some borrowed, some not) to make an MTF Stochastic stoplight-like upper indicator. It'll end up as a collection of red/green squares at the top of the chart that will tell you what the current status of the StochasticFull is (%K > %D = green and vice verse) for multiple charts -- 1D, 4hr, 1hr, 30 min, whatever you want. I've been successful getting one timeframe's stoplight to appear on it's own chart, but can't figure out how to have all timeframes report on a single chart (30min, 15min, 5min, 1 min all on the 1min chart). The code for I've been working on to get multiple timeframes reporting on a single chart is below, but it has an error with the "script SymbolStochastic {" line. I'm sure it's something silly due to me not knowing what I'm doing, but would appreciate it if someone could show me the error of my ways. Thanks!

Code:
declare upper;
input period = AggregationPeriod.DAY;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input aP = AggregationPeriod.DAY;
input averageType = AverageType.SIMPLE;
DefineGlobalColor("CrossDown", Color.GREEN);
DefineGlobalColor("CrossUp", Color.RED);
script SymbolStochastic {
def CrossUp = FullK >= FullD;
def CrossDown = 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;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
def currentPeriod = GetAggregationPeriod();
if period >= currentPeriod {
s1 = SymbolStochastic(aP = period);
} else {
s1 = Double.NaN;
}
AddLabel(!IsNaN(s1), if period == AggregationPeriod.MONTH then "M" else
if period == AggregationPeriod.WEEK then "W" else
if period == AggregationPeriod.FOUR_DAYS then "4D" else
if period == AggregationPeriod.THREE_DAYS then "3D" else
if period == AggregationPeriod.TWO_DAYS then "2D" else
if period == AggregationPeriod.DAY then "D" else
if period == AggregationPeriod.FOUR_HOURS then "4H" else
if period == AggregationPeriod.TWO_HOURS then "2H" else
if period == AggregationPeriod.HOUR then "60m" else
if period == AggregationPeriod.THIRTY_MIN then "30m" else
if period == AggregationPeriod.TWENTY_MIN then "20m" else
if period == AggregationPeriod.FIFTEEN_MIN then "15m" else
if period == AggregationPeriod.TEN_MIN then "10m" else
if period == AggregationPeriod.FIVE_MIN then "5m" else
if period == AggregationPeriod.FOUR_MIN then "4m" else
if period == AggregationPeriod.THREE_MIN then "3m" else
if period == AggregationPeriod.TWO_MIN then "2m" else
if period == AggregationPeriod.MIN then "1m"
else "", if s1 > 0 then GlobalColor("CrossUp") else GlobalColor("CrossDown"));
 
@Dixon72 Nice start from the looks of things. Please go through the Universe of Thinkscript, located in the Tutorial section. You'll find examples there.
Please fill out you signature line so we know where your comin' from. :)

"Something simple like you not knowing what you're doing." :LOL::ROFLMAO: It looks to me like you've got a very good grip on things for a beginner.

Take a look at this indicator below, open it up and go thru the code. It will give you an idea of what might be needed. (Or not!)
StopLightIndicators_Lar719
 
@Dixon72 line 15 comes back with an invalid statement error

@Dixon72 Yep, you are quite right, I took a quick look through the code, seems like there is a missing brace for the script() function, the use of the script function appears to be incomplete. Another example is that FullK and FullD are used before those variables were defined.

It seems you are planning to implement some sort of Stochastic MTF study. I recently posted a full solution for how to construct a DMI MTF study on another thread for another requester, you might want to look into that and then retrofit into your study

https://usethinkscript.com/threads/...s-mtf-labels-for-thinkorswim.1129/#post-10082
 
Last edited:
@Dixon72 Here is a MTF Stochastic. Maybe it will help in constructing your study. Just need to repeat your code for all your time frames. Then add labels.

Code:
# // ==========================
#
declare lower;

input length = 14;
input over_bought = 80;
input over_sold = 20;
input smoothK = 3;
input smoothD = 3;
#input priceH = high;
#input priceL = low;
#input priceC = close;
input showBreakoutSignals = {default "Yes", "No"};

def k = SimpleMovingAvg(100*(close-lowest(low,length))/(highest(high,length)-lowest(low,length)), smoothK);
def d = SimpleMovingAvg(k, smoothD);

plot outK = k;
plot outD = d;

plot OverBought = over_bought;
plot OverSold = over_sold;

#need to add cloud with these
#def upK = outK crosses above OverSold;
#def downK = outK crosses below OverBought;
def crossUp = (outK[1] < outD[1] and outK[1] < OverSold[1]) and (outK > outD);
def crossDn = (outK[1] > outD[1] and outK[1] > OverBought[1]) and (outK < outD);

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "Yes":
    UpSignal = if crossUp then OverSold else Double.NaN;
    DownSignal = if crossDn then OverBought else Double.NaN;}

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

input aggregationPeriod = AggregationPeriod.DAY;
input KPeriod = 3;
input DPeriod = 3;
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);
 
Hey everyone, new to the site. I've enjoyed sifting through the collection of indicators on this site and it's inspired me to try some scripting of my own. Disclaimer: I **** and am still learning. I've tried piecing together some code (some borrowed, some not) to make an MTF Stochastic stoplight-like upper indicator. It'll end up as a collection of red/green squares at the top of the chart that will tell you what the current status of the StochasticFull is (%K > %D = green and vice verse) for multiple charts -- 1D, 4hr, 1hr, 30 min, whatever you want. I've been successful getting one timeframe's stoplight to appear on it's own chart, but can't figure out how to have all timeframes report on a single chart (30min, 15min, 5min, 1 min all on the 1min chart). The code for I've been working on to get multiple timeframes reporting on a single chart is below, but it has an error with the "script SymbolStochastic {" line. I'm sure it's something silly due to me not knowing what I'm doing, but would appreciate it if someone could show me the error of my ways. Thanks!

Code:
declare upper;
input period = AggregationPeriod.DAY;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input aP = AggregationPeriod.DAY;
input averageType = AverageType.SIMPLE;
DefineGlobalColor("CrossDown", Color.GREEN);
DefineGlobalColor("CrossUp", Color.RED);
script SymbolStochastic {
def CrossUp = FullK >= FullD;
def CrossDown = 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;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
def currentPeriod = GetAggregationPeriod();
if period >= currentPeriod {
s1 = SymbolStochastic(aP = period);
} else {
s1 = Double.NaN;
}
AddLabel(!IsNaN(s1), if period == AggregationPeriod.MONTH then "M" else
if period == AggregationPeriod.WEEK then "W" else
if period == AggregationPeriod.FOUR_DAYS then "4D" else
if period == AggregationPeriod.THREE_DAYS then "3D" else
if period == AggregationPeriod.TWO_DAYS then "2D" else
if period == AggregationPeriod.DAY then "D" else
if period == AggregationPeriod.FOUR_HOURS then "4H" else
if period == AggregationPeriod.TWO_HOURS then "2H" else
if period == AggregationPeriod.HOUR then "60m" else
if period == AggregationPeriod.THIRTY_MIN then "30m" else
if period == AggregationPeriod.TWENTY_MIN then "20m" else
if period == AggregationPeriod.FIFTEEN_MIN then "15m" else
if period == AggregationPeriod.TEN_MIN then "10m" else
if period == AggregationPeriod.FIVE_MIN then "5m" else
if period == AggregationPeriod.FOUR_MIN then "4m" else
if period == AggregationPeriod.THREE_MIN then "3m" else
if period == AggregationPeriod.TWO_MIN then "2m" else
if period == AggregationPeriod.MIN then "1m"
else "", if s1 > 0 then GlobalColor("CrossUp") else GlobalColor("CrossDown"));
I believe you are onto something extremely powerful here. I had been using all kinds of indicators and all have failed with the exception of the MTF of RSI. However, that too has drawbacks since RSI is somewhat of a lagging indicator and ToS painting those curves as straight lines simply isn't helpful. So I ended up using Fast Stochs, Full Stochs and Stoch Momentum indicators. Other popular indicators (MACD, RSI, SZO, etc...) are also on the screen but I rarely used them unless for confirmation. Seems that the Stochs are plenty. And I have been able to read the market behavior just by looking at the Stochs.

I'm no good with writing scripts ("code" challenged, that is) but I can see that you are basing your stoplights on the cross-over/cross-under. I don't see that as necessary, or they cross at the same time. As long as the current bar is higher (or lower) than the previous, especially when ALL timeframes are "sync up", the market simply went into overdrive. The more timeframes sync up, the stronger the market moves. The lower Stochs indicators are still needed for visual confirmation though.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
405 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top