I found an indicator on Hahn's site but when i find inside days from my scans, it's not showing an entry for all of them like it should. I use wicks, so what im trying to do is:
If it had an inside day yesterday, i would like to draw a SOLID line at the top of the candle and bottom of that candle, long and short entries. I wouls also like to draw a DASHED line for the target, which would be the high/low of the bar prior to the inside day
Code:
input offset = 1;
#def count = 2;
def range = high – low;
#def priorrange = high[1] – low[1];
def priorrange = range[1];
def nibsize = absvalue(((open – close) / (open[1] – close[1])-1));
def sizeConstraint = absvalue((range / priorrange)-1) >= .5 and nibsize >= .5;
def hiLowConstraint = high <=high[1] and low >= low[1];
def inside_bar = sizeConstraint and hiLowConstraint;
rec insideBarRange = CompoundValue(1, if inside_bar then range else insideBarRange[1], Double.NaN);
#plot s = inside_bar && lowest(range,count);
def plotRightExpansionArea = !IsNaN(close[1]) and IsNaN(close[0]);
rec longEntry = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then high[offset] + 0.01 else Double.NaN else longEntry[1], Double.NaN);
rec longExit = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then longEntry + insideBarRange else Double.NaN else longExit[1], Double.NaN);
rec shortEntry = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then low[offset] + 0.01 else Double.NaN else shortEntry[1], Double.NaN);
rec shortExit = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then shortEntry - insideBarRange else Double.NaN else shortExit[1], Double.NaN);
plot longEntryLevel = longEntry;
longEntryLevel.SetDefaultColor(Color.GREEN);
plot longExitLevel = longExit;
longExitLevel.SetDefaultColor(Color.DARK_GREEN);
longExitLevel.SetPaintingStrategy(PaintingStrategy.DASHES);
longExitLevel.SetLineWeight(3);
plot shortEntryLevel = shortEntry;
shortEntryLevel.SetDefaultColor(Color.RED);
plot shortExitLevel = shortExit;
shortExitLevel.SetDefaultColor(Color.RED);
shortExitLevel.SetPaintingStrategy(PaintingStrategy.DASHES);
shortExitLevel.SetLineWeight(3);
AssignPriceColor(if inside_bar then Color.WHITE else Color.CURRENT);
An inside day occurs when the stock trades within the range of the previous day high and low. Combining with Narrow Range 4 (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.
That is how I would personally trade Inside Day + NR4.
I found an indicator on Hahn's site but when i find inside days from my scans, it's not showing an entry for all of them like it should. I use wicks, so what im trying to do is:
If it had an inside day yesterday, i would like to draw a SOLID line at the top of the candle and bottom of that candle, long and short entries. I wouls also like to draw a DASHED line for the target, which would be the high/low of the bar prior to the inside day
Code:
input offset = 1;
#def count = 2;
def range = high – low;
#def priorrange = high[1] – low[1];
def priorrange = range[1];
def nibsize = absvalue(((open – close) / (open[1] – close[1])-1));
def sizeConstraint = absvalue((range / priorrange)-1) >= .5 and nibsize >= .5;
def hiLowConstraint = high <=high[1] and low >= low[1];
def inside_bar = sizeConstraint and hiLowConstraint;
rec insideBarRange = CompoundValue(1, if inside_bar then range else insideBarRange[1], Double.NaN);
#plot s = inside_bar && lowest(range,count);
def plotRightExpansionArea = !IsNaN(close[1]) and IsNaN(close[0]);
rec longEntry = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then high[offset] + 0.01 else Double.NaN else longEntry[1], Double.NaN);
rec longExit = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then longEntry + insideBarRange else Double.NaN else longExit[1], Double.NaN);
rec shortEntry = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then low[offset] + 0.01 else Double.NaN else shortEntry[1], Double.NaN);
rec shortExit = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then shortEntry - insideBarRange else Double.NaN else shortExit[1], Double.NaN);
plot longEntryLevel = longEntry;
longEntryLevel.SetDefaultColor(Color.GREEN);
plot longExitLevel = longExit;
longExitLevel.SetDefaultColor(Color.DARK_GREEN);
longExitLevel.SetPaintingStrategy(PaintingStrategy.DASHES);
longExitLevel.SetLineWeight(3);
plot shortEntryLevel = shortEntry;
shortEntryLevel.SetDefaultColor(Color.RED);
plot shortExitLevel = shortExit;
shortExitLevel.SetDefaultColor(Color.RED);
shortExitLevel.SetPaintingStrategy(PaintingStrategy.DASHES);
shortExitLevel.SetLineWeight(3);
AssignPriceColor(if inside_bar then Color.WHITE else Color.CURRENT);
Mayhaps you can try this.
note: i tried to keep as much of the original code as possible
note: removed the constraints, so it picks up all inside bars [some were missing with the constraints in there]
the main change: modified longExit and shortExit to refer to the high and low of the bar prior to your inside_bar
Code:
input offset = 1;
input exceed = 0.00;
def inside_bar = high <=high[1] and low >= low[1];
def plotRightExpansionArea = !IsNaN(close[1]) and IsNaN(close[0]);
rec longEntry = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then high[offset] + exceed else Double.NaN else longEntry[1], Double.NaN);
rec longExit = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then high[offset + 1] else Double.NaN else longExit[1], Double.NaN);
rec shortEntry = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then low[offset] - exceed else Double.NaN else shortEntry[1], Double.NaN);
rec shortExit = CompoundValue(1, if plotRightExpansionArea[-1] then if inside_bar[offset] then low[offset + 1] else Double.NaN else shortExit[1], Double.NaN);
plot longEntryLevel = longEntry;
longEntryLevel.SetDefaultColor(Color.GREEN);
plot longExitLevel = longExit;
longExitLevel.SetDefaultColor(Color.DARK_GREEN);
longExitLevel.SetPaintingStrategy(PaintingStrategy.DASHES);
longExitLevel.SetLineWeight(3);
plot shortEntryLevel = shortEntry;
shortEntryLevel.SetDefaultColor(Color.RED);
plot shortExitLevel = shortExit;
shortExitLevel.SetDefaultColor(Color.RED);
shortExitLevel.SetPaintingStrategy(PaintingStrategy.DASHES);
shortExitLevel.SetLineWeight(3);
AssignPriceColor(if inside_bar then Color.WHITE else Color.CURRENT);
An inside day occurs when the stock trades within the range of the previous day high and low. Combining with Narrow Range 4 (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.
Thanks @BenTen! So if I were to look for stocks whose yesterday's range is well contained with day-before-yesterday(ie 2 bars ago on daily) AND yesterday's range is smaller than 3 previous bars, would I do something like this?
def lowVol = (VolatilityStdDev(6) / VolatilityStdDev(100)) < 0.5;
def insideDay = high[1] < high[2] and low[1] > low[2];
def range = high[1] - low[1];
def NR4 = range < Lowest(range[1], 3);
def s = lowVol and insideDay and NR4;
plot signal = s within 1 bars;
Thanks @BenTen! So if I were to look for stocks whose yesterday's range is well contained with day-before-yesterday(ie 2 bars ago on daily) AND yesterday's range is smaller than 3 previous bars, would I do something like this?
def lowVol = (VolatilityStdDev(6) / VolatilityStdDev(100)) < 0.5;
def insideDay = high[1] < high[2] and low[1] > low[2];
def range = high[1] - low[1];
def NR4 = range < Lowest(range[1], 3);
def s = lowVol and insideDay and NR4;
plot signal = s within 1 bars;
I didn't test this, but the logic and syntax is correct.
Recommend you put it on your chart. Nothing beats personal experience The only way you will know what works best for you is to play with the settings and see how the indicator line up w/ your strategy and with your other indicators. To determine if this indicator brings value, analyze it over different timeframes, across history and with multiple instruments.
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.
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.