NR4 Inside Bar for ThinkorSwim

install Inside Day indicator and NR4 for ThinkorSwim with strategy, and it appears in red and does not work, you can inform me that there may be an error.

Code:
def lowVol = (VolatilityStdDev(6) / VolatilityStdDev(100)) < 0.5;
def insideDay = high < high[1] and low > low[1];
def range = high - low;
def NR4 = range < Lowest(range[1], 3);
plot signal = lowVol and insideDay and NR4;
plot signal2 = lowVol and insideDay and NR4;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal.SetDefaultColor(Color.MAGENTA);
signal.SetLineWeight(1);
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal2.SetDefaultColor(Color.MAGENTA);
signal2.SetLineWeight(1);


Code:
def lowVol = (VolatilityStdDev(6) / VolatilityStdDev(100)) < 0.5;
def insideDay = high < high[1] and low > low[1];
def range = high - low;
def NR4 = range < Lowest(range[1], 3);
def s = lowVol and insideDay and NR4;
plot signal = s within 1 bars;
 
@BenTen, I was looking at this indicator and it is not loading the arrows for these stocks. I'm sure they are in inside as of 10/23/2020. Do you know why the arrows are not working for these?

$AMWL $APT $AYX $CRWD $DOCU $FVRR $LMPX $LSF $MELI $TMHC $TTCF $WKHS
 
@lowtrade Probably because of the NR4 condition:

Below is the indicator that applies the rules on how to identify Inside Day and NR4. This way you can easily figure out when we have an Inside Day with "narrow-range-4-bars".

If you just want to identify inside bar, then use the code below:

Code:
# Inside Bar
# Mobius
# 8.7.2017

def inside = high < high[1] and low > low[1];
plot inside_bar = inside;
inside_bar.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
inside_bar.SetDefaultColor(Color.MAGENTA);
inside_bar.SetLineWeight(1);
 
I've been looking to see if I can find the following script for a scan that I've been doing manually at end of day. Looking to scan for stocks with inside days as shown by their DTR (1 day range) no more than 80% of their ATR (I use Wilder 8 day for mine. For example yesterday's PTON, where the DTR was 4.0 and the 8 day was 7.4 so the ratio was .54. I take these ratios that are less than 70% and put them into a watchlist (or cross reference with other watchlist parameters) and look for breakouts. Ideally I'd like to be able to change the days for each condition (7 vs 8, 2 vs 1). Would also like to be able to adjust the ration, ie less than 70% 50% etc. I do this scan at the end of each day. Does anyone have anything like this or want to provide me with one? I've $$$ for scripts before some I'm open to that too (when I can find them on any boards). I go thru 65 stocks each day or so and it takes a hell of a long time. So....
 
I've been looking to see if I can find the following script for a scan that I've been doing manually at end of day. Looking to scan for stocks with inside days as shown by their DTR (1 day range) no more than 80% of their ATR (I use Wilder 8 day for mine. For example yesterday's PTON, where the DTR was 4.0 and the 8 day was 7.4 so the ratio was .54. I take these ratios that are less than 70% and put them into a watchlist (or cross reference with other watchlist parameters) and look for breakouts. Ideally I'd like to be able to change the days for each condition (7 vs 8, 2 vs 1). Would also like to be able to adjust the ration, ie less than 70% 50% etc. I do this scan at the end of each day. Does anyone have anything like this or want to provide me with one? I've $$$ for scripts before some I'm open to that too (when I can find them on any boards). I go thru 65 stocks each day or so and it takes a hell of a long time. So....
I look at 1000 charts a day,.... takes me 30 minutes,...find something simpler. Don't pay for scripts...... What is your set up? Can you tell a kid what your set up is and have him understand it?
 
Thanks for this. The set up is "on average, stock XYZ trades within a range of 10 points if you take the high and low of the stock. But today, stock XYZ only trade 7 points. So I'm looking for this stock to expand back to it's average range." I see this is a study. Do you have a version of this as a scan? I probably can find some how to's on converting studies into scans. Regardless, thanks much.
 
I figured it out.

Code:
def value1 = .65*ATR("length" =8);
def value2 = ATR("length" =1);
plot signal = value1 > value2;

Proud to say this is my first TOS script :cool:
 
This is my first serious code in ThinkScript. Wanted to plot an indicator suggested by a pro trader I follow to see how well it actually works. It looks for periods of low volatility as measured by consecutive inside bars against a baseline. Used a bubble so I could see where it occurs in a plot. Turned out to be way easier than it seemed at first:

Code:
input MinCompressionLength = 4;
input BubbleAbove = yes;
input TurnOffPlot = no;

def InsideBars =
    if InsideBars[1] == 0 then
        if high <= high[1] and low >= low[1] then 1
        else 0
    else
        if high <= GetValue(high, InsideBars[1] + 1, 0) and
            low >= GetValue(low, InsideBars[1] + 1, 0)
            then InsideBars[1] + 1
        else 0;

AddChartBubble(!TurnOffPlot and InsideBars >= MinCompressionLength and !InsideBars[-1], high,
    InsideBars + " inside", Color.GRAY, BubbleAbove);
 
Anyone able to help me here? I'm a java programmer & thinkscript really does not make any sense to me & I'm gonna take a wild guess and say this isn't the hardest thing to do considering thinkorswim will let you scan for upto inside months.

Thank's in advance usethinkscript people :)
I can relate. I'm a long time computer programmer and it didn't make sense to me either. Its a paradigm shift. Think of it this way--TS scans from left to right across the chart and needs you to tell it what to do at each bar it sees. If you think about it that way it may help you figure it out.
 
Hi Guys,

Could someone help me on how to scan inside bar candlestick which is the 2nd candle is less than half the size of the 1st bar?
could you please tell me what to write a script that the 2nd is only half the size
thanks!
 
I can relate. I'm a long time computer programmer and it didn't make sense to me either. Its a paradigm shift. Think of it this way--TS scans from left to right across the chart and needs you to tell it what to do at each bar it sees. If you think about it that way it may help you figure it out.
Yes. There are excellent tutorials in the ThinkOrSwim Learning Center that can get you started. If you're experienced, you'll be over the initial hurdle in a short period of time.

https://tlc.thinkorswim.com/center/reference/thinkScript/tutorials

If you already did the tutorials, you can use the references to look up commands.
https://tlc.thinkorswim.com/center/reference

After you know what you're doing, a google search for "topic site:usethinkscript.com" or "topic thinkscript" usually works to get you where you're going. (I prefer to look for things at usethinkscript.com before searching the larger Internet.)

(That said, don't take trading advice from farm equipment.)
 
Hello,

I'm trying to assign a price color for inside bar on the RSI candle indicator but the candle color won't change. I am I doing something wrong?

Code:
declare lower;

def RSI = RSI();

def o = (RSI + RSI[1]) / 2;

def h = Max(RSI, RSI[1]);

def l = Min(RSI, RSI[1]);

def c = RSI;

AddChart(high = h, low = l, open = o, close = c, type = ChartType.CANDLE, Color.upTICK, color.red, color.white);

Plot OverSold = if isNan(close[1]) then double.nan else 70;
plot OverBought = if isNan(close[1]) then double.nan else 30;

def inside = h < h[1] and l > l[1];
AssignPriceColor(if inside
                then color.cyan
                else color.current);
 
Hello,

I'm trying to assign a price color for inside bar on the RSI candle indicator but the candle color won't change. I am I doing something wrong?

declare lower;

def RSI = RSI();

def o = (RSI + RSI[1]) / 2;

def h = Max(RSI, RSI[1]);

def l = Min(RSI, RSI[1]);

def c = RSI;

AddChart(high = h, low = l, open = o, close = c, type = ChartType.CANDLE, Color.upTICK, color.red, color.white);

Plot OverSold = if isNan(close[1]) then double.nan else 70;
plot OverBought = if isNan(close[1]) then double.nan else 30;

def inside = h < h[1] and l > l[1];
AssignPriceColor(if inside
then color.cyan
else color.current);
AddChart is a deprecated function and is buggy. It does not handle colours well at all. There is, somewhere here, an explanation of a long workaround involving plotting two AddChart functions with different colours depending on (in your case whether it is an inside bar or not) some condition...

Hope that helps,
-mashume


EDIT:
the code for the addCharts would look like this:
Code:
def inside = h < h[1] and l > l[1];

def nan = double.nan;

AddChart(
high   = if !inside then h else nan, 
low    = if !inside then l else nan, 
open   = if !inside then o else nan, 
close  = if !inside then c else nan, 
type = ChartType.CANDLE, Color.black);

AddChart(
high   = if inside then h else nan, 
low    = if inside then l else nan, 
open   = if inside then o else nan, 
close  = if inside then c else nan, 
type = ChartType.CANDLE, Color.red);

but you'll never see an inside candle with your code because you've defined h and l to be the MAX(rsi, rsi[1]) and since you're comparing the value this bar with the value last bar that is the max of this and last, it can't be less than that. It seems. Unless I just need another cup of coffee. Which seems likely.
 
Last edited:
AddChart is a deprecated function and is buggy. It does not handle colours well at all. There is, somewhere here, an explanation of a long workaround involving plotting two AddChart functions with different colours depending on (in your case whether it is an inside bar or not) some condition...

Hope that helps,
-mashume


EDIT:
the code for the addCharts would look like this:
Code:
def inside = h < h[1] and l > l[1];

def nan = double.nan;

AddChart(
high   = if !inside then h else nan,
low    = if !inside then l else nan,
open   = if !inside then o else nan,
close  = if !inside then c else nan,
type = ChartType.CANDLE, Color.black);

AddChart(
high   = if inside then h else nan,
low    = if inside then l else nan,
open   = if inside then o else nan,
close  = if inside then c else nan,
type = ChartType.CANDLE, Color.red);

but you'll never see an inside candle with your code because you've defined h and l to be the MAX(rsi, rsi[1]) and since you're comparing the value this bar with the value last bar that is the max of this and last, it can't be less than that. It seems. Unless I just need another cup of coffee. Which seems likely.

Thanks. Problem still exist.
 
Below script searches for inside bar and I have it scanning on my custom watchlist. when it finds an inside bar, it shows a 1 on the column, otherwise it displays a 0. I want it to change color when the script is true and showing 1 to be yellow.

Code:
# Generation time: 2020-09-26T16:01:42.946Z

def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
plot PatternPlot =
    ((Sum(IsUp, 1)[2] >= 0)) and
    ((Sum(IsUp, 1)[1] >= 0)) and
    ((Sum(IsUp, 1)[0] >= 0)) and
    Lowest(low[2], 1) < Lowest(low[1], 1) and
    Highest(high[2], 1) > Highest(high[1], 1) and
    Highest(high[1], 1) > Highest(high[0], 1) and
    Lowest(low[1], 1) < Lowest(low[0], 1);

PatternPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
PatternPlot.SetDefaultColor(GetColor(0));
 

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