Stochastic Scalper for ThinkorSwim

RickK

Active member
Hey All,

Not sure if anyone has ever put this up, but I know that it has been around for quite some time. I found it a long time ago on FunWithThinkscript.
It's called Stochastic Scalper and I don't know who has taken credit for designing it....boy would I like to know and ask some questions. I've been hot and cold on it for a long time....lately warming back up since I took some time to tweak the settings.

I've included an image, the code (which I liberally modified the "instructions"[if you want to call it that....but don't]), and links to a workspace and a link to the thinkscript itself. Would love to see some dialog on this to see what kind of results, if any, others are getting. Currently I'm trading mostly /NQ on 1m/5m timeframes.

Also, if there is anyone that can convert this code to Tradingview pinescript, that would be awesome! I trade with Tradovate mostly now and chart using Tradingview because I got tired of TOS locking up, bogging down and just plain stopping for minutes at a time..... and because Tradovate's charting is sort of crap.

Enjoy!

q56RBgs.jpg


Here's the link to the workspace of the image I've shown above: https://tos.mx/O7oxLBP

Here's the link to the thinkscript indicator itself: https://tos.mx/UwPpmjI

Note: the code below has a huge "hint" section that seems to be displaying as one line on usethinkscript. Copy and paste it into notepad to read it or just read it once you download the indicator. In it, I have discussed mods that I've made to the script itself and also parameters that I've changed in my testing. :)

Code:
#Stochastic Scalper

#hint: Stochastic Scalper - unattributed - I think it was originally designed for forex trading on MT4  Modifications to hints(info) done by @RickKennedy, member usethinkscript.com................ INFO: This is designed to give short aggregation Signals 1 to 5 min.  When used on a single chart, scalp when both lines agree (green  lines long, red lines short). Best situation is when both lines agree on  the 1m chart and both lines agree on the 5m chart ...all 4 lines agreeing. (Lately I've been testing it on a 600 tick/1800 tick chart combo with fast but interesting results.) Using the two chart method is usually a very high probability  trade.  ................ The white line is pure price scaled to the Stochastic range. ................The straight line is a Linear Regression of the Total Chart aggregation showing the charts trend (red=downward, yellow=upward).  Note:  I have turned off the linear regression lines as I didn't feel that they really added anything, for me. Likewise, I have turned off its chart labels that said "CHART TREND UP", "CHART TREND DOWN". Also I changed the labels from "BUY" to "BULLISH" and "SELL" to "BEARISH" and "SQUEEZE" to "SQZ".................. Yellow Triangles at the top of indicator show volume in the 30 percentile for that Volume Period or above. ................ Blue Dots at the bottom of the indicator show when price is in a squeeze, such as with the TTM_Squeeze indicator. ................ When a light blue square appears on the white price line, this  indicates divergence between price and the stochastic lines. A reversal could be coming. Labels are used for trading signals.  ................Added at the end of the script is a new bit of code that will  display a heat map line at the top of the indicator (green  when both stochastic lines are green, red when both stochastic  lines are red, and white when the lines are not the same). ................ Lastly, there is a section of code (that I have turned off) which  allows the indicator to assign colors to the candles on the chart.  I couldn't figure out the use, so I commented it out................. Finally, there is a bit of complimentary code (a separate indicator) that will display the results of Stochastic Scalper on your watchlist.  Thus, if a TSLA is Green/Bullish/Buy on the indicator, it will display  a Green block on the watchlist. This works for 1m and 5m.  Nice feature..........Oh, I forgot to mention. You might want to play with the settings.  Currently I am using it with a 10,6,60 setting on the short term chart and 6,6,60 on the longer term chart. Advice: look for the lines to correlate on the longer term chart, then look for the lines to coincide on the short term chart. Good luck!


declare lower;

input period = 21;
input periodEMA = 13;
input VolumePeriod = 60;

def o;
def h;
def l;
def c;
def v;
def r;
def p1;
def s;
def p3;
plot K;
plot D;
#plot A;
def Min;
def Max;
def vS;
def vK;
plot vP;
plot PLine;
def mean;
def sd;
def atr;
plot squeeze;
plot Div;
o = (open[1] + close[1]) / 2;
h = Max(high, close[1]);
l = Min(low, close[1]);
c = (o + h + l + close) / 4;
v = volume;
script ScalingPlot {
    input c = close;
    input Min = 0;
    input Max = 100;
    def hh = Highest(c, 63);
    def ll = Lowest(c, 63);
    plot Range = (((Max - Min) * (c - ll)) /  (hh - ll)) + Min;
}
r  = Highest(h, period) - Lowest(l, period);
p1 = (c - Lowest(l, period)) / r;
K  = ExpAverage(p1, periodEMA);
s  = Highest(K, period) - Lowest(K, period);
p3 = (K - Lowest(K, period)) / s;
D  = ExpAverage(p3, periodEMA);
Min = LowestAll(K);
Max = HighestAll(K);
PLine   = scalingPlot(c = c, Min = Min, Max = Max);
#A   = InertiaAll(b);
vS = Highest(v, VolumePeriod) - Lowest(v, VolumePeriod);
vK = (v - Lowest(v, VolumePeriod)) / vS;
vP = if vK > .7 then 1 else Double.NaN;
vP.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
mean = Average(c, 20);
sd = StDev(c, 20);
atr = Average(TrueRange(c, h, l), 20);
squeeze = if (mean + (2 * sd)) < (mean + (1.5 * atr)) then 0 else Double.NaN;
squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
K.AssignValueColor(if K > K[1] then Color.LIME else Color.DARK_ORANGE);
K.SetLineWeight (2);
D.AssignValueColor(if D > D[1] then Color.GREEN else Color.MAGENTA);
#A.AssignValueColor(if A > A[1] then Color.yellow else Color.Red);
PLine.SetDefaultColor(Color.WHITE);
vP.SetDefaultColor(Color.YELLOW);
squeeze.SetDefaultColor(CreateColor(15, 150, 250));
squeeze.SetLineWeight(4);
#AddLabel(1, if A > A[1]
#           then "Chart Trend Up"
#            else "Chart Trend Down",
#           if A > A[1]
#            then Color.Green
#            else Color.Red);
AddLabel(K < K[1] and D < D[1], "BEARISH", Color.RED);
AddLabel(K > K[1] and D > D[1], "BULLISH", Color.GREEN);
AddLabel(!IsNaN(vP), "VOL!!", Color.YELLOW);
AddLabel(!IsNaN(squeeze), "SQZ", CreateColor(15, 150, 250));
plot OB = if IsNaN(close) then Double.NaN else .8;
OB.SetDefaultColor(Color.WHITE);
plot OS = if IsNaN(close) then Double.NaN else .2;
OS.SetDefaultColor(Color.WHITE);
# Scan Plots
plot Long = if K > K[1] and
               D > D[1] and
               D[1] < D[2]
            then 1
            else 0;
Long.Hide();
plot Short = if K < K[1] and
                D < D[1] and
                D[1] > D[2]
             then 1
             else 0;
Short.Hide();

#The following 5 lines of code will color the candles on the
#chart for some reason.....can't figure out why
#AssignPriceColor(if Long
#                then Color.Yellow
#                else if Short
#                then Color.Plum
#                else Color.Current);


# Price and Stochastic Divergence
Div = if Correlation(D, PLine, 3) >= -.99 then Double.NaN else PLine;
Div.SetPaintingStrategy(PaintingStrategy.SQUARES);
Div.SetDefaultColor(Color.CYAN);
Div.SetLineWeight(4);

#code to add clouds for overbought and oversold zones
AddCloud(-.02, .2, Color.LIGHT_GRAY, Color.GREEN);
AddCloud(.8, 1.02, Color.DARK_GRAY, Color.LIGHT_RED);

# End original Code for  Stochastic Scalper


# copy and paste the following to the very end of the
# original Stochastic Scalper script ( http://tos.mx/R91bLn )
# this will add squares to the top of the scalper plot
# the squares will be green when both K and D are higher
# the squares will be red when both K and D are lower
# the squares will be gray when K and D are mixed

plot Neut = if IsNaN(close) then Double.NaN else (Max(HighestAll(K), HighestAll(D))) * 1.1;
Neut.SetPaintingStrategy(PaintingStrategy.SQUARES);
Neut.AssignValueColor(if K > K[1] and D > D[1] then Color.GREEN else if K < K[1] and D < D[1] then Color.RED else Color.LIGHT_GRAY);
Neut.SetLineWeight(4);
 
Last edited:
@barbaros (and @BenTen and @surferdude to complete my original post),..... That is definitely a lot of lines, fo sho!

I'm copying below the hint section that I've elaborated on (from the original). Basically, for me, I ignore the colored dots , squares, triangles and linear regression line (not shown) and labels. For now, I really only watch the green/red lines and the white line ...... on both charts. The white line is price, scaled to the stochastic range. So, let's say price is down in the oversold range (on 1m chart) and maybe creeping up and I'm looking for longs. I'll look to the 5m chart first, to see if both green/red lines are green together. If so, then I'll look to the 1m chart and wait for an entry.....which is when both green/red lines are also green together. From the image I posted, using the examples and this strategy, it shows a resulting 12+ point short trade (red drawing) on /NQ and then a 15+ long trade (blue drawing).

Super busy looking indicator, but that's really about it in simplicity. Detailed explanation of all of the features is below.

#hint: Stochastic Scalper - unattributed - I think it was originally designed for forex trading on MT4. Modifications to hints(info) done by @RickKennedy, member usethinkscript.com................ INFO: This is designed to give short aggregation Signals 1 to 5 min. When used on a single chart, scalp when both lines agree (green lines long, red lines short). Best situation is when both lines agree on the 1m chart and both lines agree on the 5m chart ...all 4 lines agreeing. (Lately I've been testing it on a 600 tick/1800 tick chart combo with fast but interesting results.) Using the two chart method is usually a very high probability trade. ................ The white line is pure price scaled to the Stochastic range. ................The straight line is a Linear Regression of the Total Chart aggregation showing the charts trend (red=downward, yellow=upward). Note: I have turned off the linear regression lines as I didn't feel that they really added anything, for me. Likewise, I have turned off its chart labels that said "CHART TREND UP", "CHART TREND DOWN". Also I changed the labels from "BUY" to "BULLISH" and "SELL" to "BEARISH" and "SQUEEZE" to "SQZ".................. Yellow Triangles at the top of indicator show volume in the 30 percentile for that Volume Period or above. ................ Blue Dots at the bottom of the indicator show when price is in a squeeze, such as with the TTM_Squeeze indicator. ................ When a light blue square appears on the white price line, this indicates divergence between price and the stochastic lines. A reversal could be coming. Labels are used for trading signals. ................Added at the end of the script is a new bit of code that will display a heat map line at the top of the indicator (green when both stochastic lines are green, red when both stochastic lines are red, and white when the lines are not the same). ................ Lastly, there is a section of code (that I have turned off) which allows the indicator to assign colors to the candles on the chart. I couldn't figure out the use, so I commented it out................. Finally, there is a bit of complimentary code (a separate indicator) that will display the results of Stochastic Scalper on your watchlist. Thus, if a TSLA is Green/Bullish/Buy on the indicator, it will display a Green block on the watchlist. This works for 1m and 5m. Nice feature..........Oh, I forgot to mention. You might want to play with the settings. Currently I am using it with a 10,6,60 setting on the short term chart and 6,6,60 on the longer term chart. Advice: look for the lines to correlate on the longer term chart, then look for the lines to coincide on the short term chart. Good luck!
 
Last edited:
@RickKennedy Thank you for the summarized thoughts.

I noticed that you have the charts set up as ticks and not 1m/5m. Is that intentional? It seems to work better with tick charts.

Here are some quick notes:
I disabled the VWAP upper and lower band.
I can't find where the pivot points indicator plots are. They don't seem to show. So, if not used, we can remove those as well.
There are a bunch of EMAs in the main chart. Some are useful, but lagging. But, they can be used for support resistance.
Stdev channels will move as price moves. Good if you are trading mean reversion.

And, here is an interesting trade highlight for /ES on Friday.
Both the 600t and 1800t price is in the overbought.
Both red/green line turns red, but price side chops for a while.
If you wait for 25-30mins, price eventually traces back down to stdev and 600t price goes into oversold.
It's a long time to hold for a scalper, but it works. Stochastic would have exited earlier.

UDRDbG4.png


There are other examples with better performance, but this one was interesting to me.
 
The thing is, I don't understand how the 'price' line, the '%K' line and the '%D' line are calculated with this indicator, which is why I would have no way of understanding how to approach it in Tradingview pinescript. It is calculated very differently from regular Stochastic.

I've put up another image that has most of the indicator stripped away (eliminate all of the busyness).... so you can just see the %K, %D and the white price line. The trigger for a long trade is shown with the vertical cyan line at about 10:20am CST. As you can see from the standard Stochastic Full (below ....using scalper settings 5,3,3), the Stochastic Full throws off a nice divergence on the 1m chart.....but those can't always be trusted by any means. The Stochastic Scalper throws off no such divergence and, in fact, I don't even look for divergences using it.

Thoughts?

x76MvKe.jpg


Thanks @barbaros .... it looks like we were posting at the same time. Yes, I should have stripped away everything from the price chart. Could lead to confusion. Even tho you'll see the pivot points listed as an indicator on the list, I set it to not display. As for the 600tick/1800tick chart, I was just testing some theories. .... probably too fast anyway.... unless used in mid morning. In the post that I made just above this, I reverted back to 1m/5m.

And yes, this indicator will leave some $$$ on the table. I'm only interested in it for scalping a portion between the turns. ....and as for exits, that's another set of considerations. One can stay in the trade while the 'fast' line on the 5m chart stays green (best return/riskiest), or bail when when the 'fast' line on the 1m chart turns red (small return/very low risk).
 
Last edited by a moderator:
@RickKennedy You may be on to something with the tick charts. I like the micro trends shown. However, I don't know if the bars will move too quick for 600t.

I'll watch this on the side tomorrow to see the indicators paint live.
 
Hello @RickKennedy Thank you for posting this indicator. I just came across it today. Can you please share your experience with it? Does it repaint? Thanks!
 
Sorry @hhjani , I don't seem to get email notifications (sometimes) when someone replies to a post here....even though I have that setting on.

To be honest, I knew about this indicator a long time ago and tried to make it work....but couldnt. Recently I revisited it and, in the hopes that it would garner some interest and testing here, it could be used effectively. But I'm back and forth with it and it doesn't seem to have gained much interest here. Unfortunately I can't claim much in terms of results.

I don't believe it repaints.
 
Hi,

Does anyone have a watchlist column for this stochastic scalper indicator? Much appreciated. Thanks.
 

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
297 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