Nudge n Shove indicator For ThinkOrSwim

TTs_MikeC

New member

*UPDATED*

Hello everybody, I wanted to share my first official indicator with the community incase it could be of use to anyone. Especially because there was no WAY this was getting done without giving that search bar a workout. My apologies if this is just another copy of something else on here, I did not see anything like it which is what inspired me to write it. I'm not much of a coder so this may be fairly primitive to the more experienced. I have not even begun to learn how to properly back test yet so I do not have any proof to show yet, but using it today kept me green. ALSO BEFORE ANYBODY ASKS I do NOT have a watchlist/scanner/alert system as that is all still beyond the scope of my knowledge at this time. Now on to the indicator:

Lower study developed to help scalp/day-trade in sideways or shorter range market. Plot line follows current price trend while histogram bars measure relative volume. Red Shaded areas on zero line indicate current time frame squeeze. Plot Points are a "nudge" on trend with above price line nudging down (bearish) and below nudging upwards (bullish). Arrows indicate a stronger push and potential trend change. Has tendency to provide early notice. Recommended for use with confirming TA.

Price trend line is based on built in Fisher Transform with stochastic formula. 2nd stochastic type formula is processed through a similar "filter" and used as reference changes in trend. Volume bars below zero line are below volume avg (relative volume ratio below 1) and switch to above zero line if they meet/cross avg. Strong shifts quickly followed by opposing "nudges" or "shoves" are often false signals or a sign of volatility/chop. False signals may also be seen or missed during excessive chop or large gaps in price.


Code:
## Nudge n Shove Indicator
#By: TTsMikeC 10/2021
#hint: Lower study developed to help scalp/day-trade in sideways or shorter range market.  Plot line follows current price trend while histogram bars measure relative volume.  Red Shaded areas on zero line indicate current time frame squeeze. Plot Points are a "nudge" on trend with above price line nudging down (bearish) and below nudging upwards (bullish).  Arrows indicate a stronger push and potential trend change.  Has tendency to provide early notice.  Recommended for use with confirming TA.
#
# Price trend line is based on built in Fisher Transform with
#    stochastic formula.  2nd stochastic type formula is processed
#    through a similar "filter" and used as reference for changes
#    in trend.  Volume bars below zero line are below volume avg
#    (relative volume ratio below 1) and switch to above zero line
#    if they meet/cross avg.
#
# Strong shifts quickly followed by opposing "nudges" or "shoves"
#    are often false signals or a sign of volatility/chop.  False
#    signals may also be seen or missed during excessive chop or
#    large gaps in price.
#
# Updates:
# 11/2/2021 v1.2
#    - reworked conditions for Nudges and Shoves for for fewer false
#    signals, as well as added a condition based on price action
#    - Fixed relative volume bars not plotting correctly

declare lower;

#hint volume_length: Length of SMA in calculating Relative Volume.  Relative volume bars are negative(Gray) when below average and positive(Green) when at or above average.
#hint price_length: Used in the calculation of price trend.  Based on Fisher Transform.  Settings too low show increased noise <b>Recommended setting: 10</b>
#hint Fast_ref: Stochastic based calculation used in referencing "Nudge" and "Shove" signals.  Lower settings will result in more false signals. <b>Recommended setting: 24</b>
#hint Arrow_Height: Distance away from Price Trend line
input volume_length = 21;
input price = hl2;
input price_length = 10;
input Fast_ref = 24;
input Arrow_Height = 2.0;
input Hide_Squeeze_Off = yes;

## Fisher Transform - Price trend
def maxHigh = Highest(price, price_length);
def minLow = Lowest(price, price_length);
def range = maxHigh - minLow;
def value = if IsNaN(price)
    then Double.NaN
    else if IsNaN(range)
        then value[1]
        else if range == 0
            then 0
            else 0.66 * ((price - minLow) / range - 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
#  .3 is down from .5 original formula to shrink plot
def fish = 0.3 * (Log((1 + truncValue) / (1 - truncValue)) + fish[1]);

def FTOneBarBack = fish[1];
plot Price_Trend = fish;
Price_Trend.SetDefaultColor(color.MAGENTA);
Price_Trend.setLineWeight(1);

#### Stochastic ####

def FastKH = Highest(price, Fast_ref);
def FastKL = Lowest(price, Fast_ref);

## Calculate Stochastic and normalize
def fastkFix = ((price - FastKL) / (FastKH - FastKL));
def fastNorm = (2 * fastkFix) - 1;
def fastCap = if fastNorm > 0.99 then 0.999 else if fastNorm < -0.99 then -0.999 else fastNorm;

### Resulting stoch line, the .3 is to shrink the oscilator to size
def fastFinal = .3 * (Log((1 + fastCap) / (1 - fastCap)) + fastFinal[1]);
### Change def to plot for trouble shooting ####
def FastK = fastFinal;

### Nudge alerts ###
def upcross = if FastK crosses above Price_Trend and
((FastK - FastK[1]) > .3) and
(Price_Trend - Price_Trend[1]) > .3 or
((FastK - FastK[1]) > 1) and Price_Trend >= -1.3 then 1 else 0  or
 if (Price_Trend - Price_Trend[1]) > .1  and Price_Trend > 0.2 and (Price_Trend[1] - Price_Trend[2]) > .2 and
Price_Trend < .4 then 1 else 0 or
if (close[1] < open[1]) and (open < close) and ((high[1] - low[1]) / (high - low) *100 < 75) then 1 else 0;

def downcross = if FastK crosses below Price_Trend and
((FastK[1] - FastK) > .3) and
(Price_Trend[1] - Price_Trend) > .5 or
((FastK[1] - FastK) > 1) and Price_Trend <= 1.3 then 1 else 0  or
if (Price_Trend[1] - Price_Trend) > .2  and Price_Trend < -0.3 and (Price_Trend[2] - Price_Trend[1]) > .2 and
 Price_Trend >-.4 then 1 else 0 or
if (close[1] > open[1]) and (open > close) and ((high[1] - low[1]) / (high - low) *100 < 75) then 1 else 0;

plot Bull_Nudge = if upcross then Price_Trend - .8 else double.NaN;
Bull_Nudge.setPaintingStrategy(paintingStrategy.POINTS);
Bull_Nudge.setDefaultColor(color.Cyan);
Bull_Nudge.setLineWeight(3);

plot Bear_Nudge = if downcross then Price_Trend + .8 else double.NaN;
Bear_Nudge.setPaintingStrategy(paintingStrategy.POINTS);
Bear_Nudge.setDefaultColor(color.yellow);
Bear_Nudge.setLineWeight(3);

### Shove plots for stronger trend change ###
## Commented out add lines to test arrows
def upshove = if upcross and Price_Trend < 0 and Price_Trend crosses above FToneBarBack and (Price_Trend > ((Price_Trend[1]+ Price_Trend[2]) / 2 ))then 1 else 0 or if upcross is true within 1 bars and Price_Trend - Price_Trend[1] > .1 and Price_Trend[1] > Price_Trend[2] then 1 else 0;
;
plot Bull_Shove = if upshove then Price_Trend - Arrow_Height else double.NaN;
Bull_Shove.setPaintingStrategy(paintingStrategy.ARROW_UP);
Bull_Shove.setlineWeight(2);
Bull_Shove.setDefaultColor(color.upTICK);
#AddverticalLine(upshove, "", color.UPTICK, Curve.SHORT_DASH);

def downshove = if downcross and Price_Trend > 0 and Price_Trend crosses below FToneBarBack and (Price_Trend < ((Price_Trend[1]+ Price_Trend[2]) / 2 )) then 1 else 0;

plot Bear_Shove = if downshove then Price_Trend + Arrow_Height else double.NaN;
Bear_Shove.setPaintingStrategy(paintingStrategy.ARROW_DOWN);
Bear_Shove.setlineWeight(2);
Bear_Shove.setDefaultColor(color.DOWNTICK);
#AddverticalLine(downshove, "", color.DOWNTICK, Curve.SHORT_DASH);


#### Relative Volume Histogram ####
def Relvol =  absValue(volume / Average(volume, volume_length));
plot Rvol = if Relvol < 1 then (Relvol *-1) else Relvol ;
rvol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
rvol.SetLineWeight(4);
rvol.DefineColor("Pos and Up", Color.GREEN);
rvol.DefineColor("Pos and Down", Color.DARK_GREEN);
rvol.DefineColor("Less but More", Color.Dark_GRAY);
rvol.DefineColor("Less and Less", Color.GRAY);
rvol.AssignValueColor(if rvol >= 0 then if rvol > rvol[1] then rvol.Color("Pos and Up") else rvol.Color("Pos and Down") else if rvol < rvol[1] then rvol.Color("Less and Less") else rvol.Color("Less but More"));

#### Squeeze indicator #####
def c = close;
def squeeze_length = 20;
def sqz = average(c, squeeze_length);
def sdv = stDev(c, squeeze_length);
def bbref = sqz +(2 * sdv) ;
def kelref = sqz + (1.5 * Average(TrueRange(high, close, low),  squeeze_length));
def squeeze = bbref < kelref;
plot Squeeze_Line = 0;
Squeeze_Line.setPaintingStrategy(paintingStrategy.LINE);
Squeeze_Line.defineColor("Squeeze off", color.DARK_GRAY);
Squeeze_Line.defineColor("Squeeze on",(createColor(204,000,000)));
Squeeze_Line.AssignValueColor(if squeeze then Squeeze_Line.color("Squeeze on") else Squeeze_Line.color("Squeeze off"));
Squeeze_Line.setLineWeight(2);
def sqz_up_range = 1.5;
def sqz_down_range = -1.5;
addcloud(if squeeze then sqz_up_range else double.NaN, sqz_down_range, (createColor(235,000,000)), (createColor(204,000,000)));
addcloud(if !Hide_Squeeze_Off then sqz_up_range else double.NaN, sqz_down_range, color.GRAY, color.GRAY);
#End


Most updated link: http://tos.mx/pK7qz9V




Feedback is appreciated! Thank you

Update 10/31/2021
Re-worked all the formulas for the plots and this should be much better. This is the current code with updated share link. Reminder: Due to the nature of it being stochastic based, times of higher volatility and larger price swings may give false signals and this indicator should not be taken as "buy"/"sell" signals. Added input for arrow plot adjustments as well.

Update 11/2/2021
Sorry for not having a better working setup before sharing!!
  • Bug fixes from last update. Cleaned up code a bit and adjusted formulas again for more accurate plots and less noise.
  • Fixed relative volume bars not plotting correctly.
 
Last edited:

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

intentional? NOPE! lol I didn't notice but I was using in on a 1m 3m and 5m chart only so far.. Thanks I'll try to look into that!
it seems that most of the code is reliant on displacement. It is continuously checking current values against past values. This indicator will always lag 2 bars behind- regardless of what chart you are using. daily or minutes.

Please correct me if I am wrong.
image.png
 
it seems that most of the code is reliant on displacement. It is continuously checking current values against past values. This indicator will always lag 2 bars behind- regardless of what chart you are using. daily or minutes.

Please correct me if I am wrong.
image.png
You are correct, I was thinking I was using previous data to show a difference in current data but I found a thread last night that suggested the [-1] is the cause of the delay.. It was this post from @MerryDay that made me realize: https://usethinkscript.com/threads/ttm_scalperalert-source-code-for-thinkorswim.914/post-48120 .
I am currently trying to rework each formula. Takes me a bit of clunking around in the dark as I am not very experienced with coding but hoping to have better formulas by the end of the weekend. Already I fixed the late plot but the accuracy is gone, and now I know it's because the current code waits for confirmation to plot.. Should've known it was too good to be true lol.

def upcross = if FastK crosses above Price_Trend and
((FastK[-1] - FastK) > .2) and
(Price_Trend <= (Price_Trend[1]+.5)) or
((FastK - FastK[1]) > 1.5) then 1 else 0;

def downcross = if FastK crosses below Price_Trend and
((FastK[-1] - FastK) < .2) and
(Price_Trend >= (Price_Trend[1] -.5)) or
((FastK[1] - FastK) > 1.5) then 1 else 0;
I was using this part to show a minimum change in readings because without this it just plots points with every shift so my focus is on re-vamping this part of the code as well as the part you highlighted.

If somebody has a better way of doing this they would be a hero, else I'll be working on it until I figure something out.
 
You are correct, I was thinking I was using previous data to show a difference in current data but I found a thread last night that suggested the [-1] is the cause of the delay.. It was this post from @MerryDay that made me realize: https://usethinkscript.com/threads/ttm_scalperalert-source-code-for-thinkorswim.914/post-48120 .
I am currently trying to rework each formula. Takes me a bit of clunking around in the dark as I am not very experienced with coding but hoping to have better formulas by the end of the weekend. Already I fixed the late plot but the accuracy is gone, and now I know it's because the current code waits for confirmation to plot.. Should've known it was too good to be true lol.


I was using this part to show a minimum change in readings because without this it just plots points with every shift so my focus is on re-vamping this part of the code as well as the part you highlighted.

If somebody has a better way of doing this they would be a hero, else I'll be working on it until I figure something out.
I have been trying to work on it too- but not all is lost. Since it doesn't matter the time frame and rather just 2 bars within that time frame there may still be hope. Is there a way to decrease the sensitivity that way It is giving less signals? the delay wouldn't matter as much then. I am not familiar with either the PRICE LENGTH or FAST REF - what is best to play around with in order to get the indicator to produce less signals but not ruin the function of the code?
 
I have been trying to work on it too- but not all is lost. Since it doesn't matter the time frame and rather just 2 bars within that time frame there may still be hope. Is there a way to decrease the sensitivity that way It is giving less signals? the delay wouldn't matter as much then. I am not familiar with either the PRICE LENGTH or FAST REF - what is best to play around with in order to get the indicator to produce less signals but not ruin the function of the code?
the areas I quoted in the last reply are the 2 formulas responsible for the arrows and points plotting. "price length" is the purple line plotted based on the built in Fisher Transform study, and "fast k" section is a regular stochastic indicator with similar "filter" to normalize/bring it down from a 0-100 reading to a similar range as the price line.

If you switch out "def" for "plot" on line 62 you will see the stochastic or "fast" line that is being referenced for "upcross/downcross". So to break it down upcross/downcross are the conditions for plotting the points, and upshove/downshove are the conditions for the arrows which also reference the upcross/downcross. I think we need to come up with new sets of conditions because everything with a [-1] is wrong and responsible for the delayed plots and all the math around them was based on playing with numbers until the results looked right.
 
What a curious and fascinating indicator. Used this today with good results, will continue to work with settings but will integrate it into my trading strategy. Nice work, thanks.
 
What a curious and fascinating indicator. Used this today with good results, will continue to work with settings but will integrate it into my trading strategy. Nice work, thanks.
That's great to hear! I hope you got the updated code and not the very 1st one posted with the late plots. Incase it helps: adjustments on the "fast ref" are what will shift the plots. It's much more responsive to changes in price than a regular stochastic which is why the default setting is so high.
 
That's great to hear! I hope you got the updated code and not the very 1st one posted with the late plots. Incase it helps: adjustments on the "fast ref" are what will shift the plots. It's much more responsive to changes in price than a regular stochastic which is why the default setting is so high.
what would i need to change to make it more suitable for i since im a swing trader
 
what would i need to change to make it more suitable for i since im a swing trader
I personally am not holding for very long lately so I have not spent too much time testing this on higher time frames.. However what I can suggest is to lower the "fast ref" setting to make the plots more "sensitive" or if your timeframe is higher than daily you can lower "price length" to allow the purple line to follow price more closely until you find a setting that matches your strategy. The higher default settings are meant more for intraday to cut some of the noise, but may be too slow for larger timeframes. A "price length" lower than 5 may just be chaos.

Lowering the "Price length" will allow the purple plot to follow price closer which will change the other plots, and lowering "fast ref" will make the "nudge and shove" plots more sensitive. I hope this helps.
 
so does it matter whether the dot prints above or below the line, or simply whether the dot is yellow or blue?
 
so does it matter whether the dot prints above or below the line, or simply whether the dot is yellow or blue?
the colors are just an attempt to make it easier to see, the dots below the line are stochastic shifts upwards, and the above the line are shifts downwards.. like a small push to make it easier to see changes in price action
 
What a curious and fascinating indicator. Used this today with good results, will continue to work with settings but will integrate it into my trading strategy. Nice work, thanks.
I agree , I am not an arrow fan so I will just use the price trend line and squeeze line to keep on right side of mkt. and see how that works out with my other indicator . I like to keep my chart as clean as possible .
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
445 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