# Inside Day and NR4 Indicator for ThinkorSwim with Strategy

#### BenTen

Staff
VIP
An inside day occurs when the stock trades within the range of the previous day high and low. Combining with Narrow Range 4 or known as NR4 will provide a high probability of trading the breakout or breakdown of the inside day bar.

Identify Inside Day:
• When the bar is within the high and low of its previous day.

Identify NR4:
• Made up of 4 bars
• Most recent candlestick will have a range that is smaller than the 3 previous bars.
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".

So instead of just looking for inside day candlestick, we're now looking for an inside day with a range that is smaller than the 3 previous bars.

### thinkScript Code

Rich (BB 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);``````

### Inside Day + NR4 Scanner

Rich (BB 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;``````

Now that you have the indicator and scanner on your ThinkorSwim, here is the guide on how to trade this particular inside day candlestick that includes the NR4 rules.

### Inside Day and Narrow Range 4 Strategy

After you add the indicator, it will plot arrows pointing at any inside days. Here is an example.

The above screenshot is \$BABA 6m 1D timeframe with 2 inside days.

The strategy for trading this is fairly simple. You plot the high and low of the Inside Day bar. Something like this:

You can initiate a long position if the candlestick breaks above the high of the Inside Day bar or short the stock if the candlestick breaks below the low of the Inside Day bar.

• For long, stop loss would be the low of the Inside Day bar.
• For short, stop loss would be the high of the Inside Day bar.

That is how I would personally trade Inside Day + NR4.

A few more examples:

Credits:

Last edited:

#### Chenthy73

##### New member
You would use it mainly on the daily chart? Thanks

Last edited:

#### BenTen

Staff
VIP
@Chenthy73 Daily and Hourly would be my go to for this indicator.

Last edited:

#### Steve2286

##### New member
2019 Donor
Ben - I've never run a scan before - where does the code get pasted ?

tks

Last edited:

#### BenTen

Staff
VIP
@Steve2286 Go to the Scan page, add new Study filter, remove the existing one and then paste the code into the thinkScript section.

Last edited:

2019 Donor
Thanks Ben

Last edited:

#### Antares66

##### New member
Hello, i tried to write an intraday scanner. The scanner works but the results are not correct.
At first i`m looking for a strong move within the last 5 days, then for an inside day.
What did i wrong?

def change=(close-close[5])/close[5]*100;
def Inside= if (high<High[1] and low >low[1]) then 1 else 0;
def bs= if change > 20 and inside>0 then 1 else 0;

#### tomsk

##### Well-known member
VIP
@Antares66 I looked through your scan code, looks like you're looking for a 20% move in the past 5 days. This is probably overly optimistic though not impossible especially if the underlying stock had some news propelling it to highs.

If you meant a 2% move in 5 days you'll get results. As a matter of fact I just ran the code on the scanner and found 7 results on a scan of the S&P 500 (daily). Bottom line, your code looks find, just check if you really meant a 20% move.

#### TOSLearner

##### New member
How do you get high/low price line on InsideDay bar? As you shown above in image, like \$74.92 and \$76.3.

#### BenTen

Staff
VIP
@TOSLearner You can do that using the drawing toolkit in ThinkorSwim.

#### divinci01

##### New member
Is there a script for a scan that picks up on stocks when they touch high/low of previous day? Or possibly a watchlist column with red /green to indicate price touching previous day high/low?

#### Roddog101

##### New member
Does anyone have anything that would be similar to a N4 or N7 that would be used on 3, 5 and 10 min intrday charts?
Looking for something that can help me identify those really narrow bars.
New to TOS so there maybe something off shelf I havent found yet?? If there was a volume indicator/alert for following bars would be nice also.

Thanks

#### Roddog101

##### New member
Think I screwed up the last post. Can this be used for lower timeframes? 5 min & 10 min?

#### BenTen

Staff
VIP
@Roddog101 Just add it to your chart and you will see. I don't see any reason why it wouldn't work on the lower timeframe, unless you're looking for something really specific.

#### rwfarrell

##### New member
Can anyone convert this PineScript inside bar code to ThinkScript? I already have a ThinkScript code on ToS for an inside bar. The thing about this below code is the candle border for green and red is easier to see if its a buy or sell candle. I tried to attach a picture but the pic attachment is asking for URL link. Thank you!

//@version=3
study(title = "Inside Bar", overlay = true)
barcolor((high <= high[1] and low >= low[1] and close >= open) ? gray : na)
barcolor((high <= high[1] and low >= low[1] and open >= close) ? black : na)

I am seeing a lot posts for IB, I have been manually attempting this script myself with no success. The main thing I like about this script is the border of the candle color is green or red but the fill color is white. This represents the IB and sticks out like a sore thumb. If anyone can translate this I would greatly appreciate it? Of if anyone has a script on how to change the fill color of a candle I can continue working it. Once I have it to my liking I will gladly share for everyone else who trades Inside Bars. Thanks again guys!!

Last edited:

#### jhatch

##### New member
Hi all

I was wondering if it would be possible if someone knows of a indicator that numbers the candles as follows:

1 = inside candle (also highlighted yellow)
2 = a normal candle that has exceeded the previous candles open/close - can either be bullish or bearish
3 = an outside candle

I recently came across a trader by the name of Rob Smith who has a strategy using simple inside candle patterns etc and I noticed on his charts he has an indicator of this type. I tried to insert a screenshot to this post but it didn't work, however it is pretty simple so I think my description should suffice.

Here is a link to the type of indicator Im talking about.

Thanks

#### Pensar

##### Active member
VIP
@jhatch

Code:
``````plot one = if low >= low[1]
and high <= high[1]
then 1 else double.nan;
one.setdefaultcolor(color.white);
one.setpaintingstrategy(paintingstrategy.values_below);

plot two = if high > high[1]
and low >= low[1]
or high <= high[1]
and low < low[1]
then 2 else double.nan;
two.setdefaultcolor(color.white);
two.setpaintingstrategy(paintingstrategy.values_below);

plot three = if high > high[1]
and low < low[1]
then 3 else double.nan;
three.setdefaultcolor(color.white);
three.setpaintingstrategy(paintingstrategy.values_below);

assignpricecolor(if one then color.yellow else color.current);``````

#### jhatch

##### New member
@jhatch God bless you sir. Thank you very much.

#### Vimal Mittal

##### Member
Thanks. It works great. What is the significance of outside candle? sorry I am new here. Thanks. However, can you make script indicator or scan for NR7 same way?

#### Rosalyn

##### New member
Thanks. It works great. What is the significance of outside candle? sorry I am new here. Thanks. However, can you make script indicator or scan for NR7 same way?
This is a bar whose high is above the high of the previous bar, while its low is beneath the low of the previous bar. It basically engulfs the previous bar. Volatility increases and it can lead to an outside reversal. It can also act as a continuation pattern in a bullish or bearish trend, if reversal fails.