Need Inside Candle Touches 9ema Scan

om4

New member
The below script looks for an Inside Candle that has been triggered on the low of the inside candle.

I need the following added to the script:
  • the triggered candle (current candle) touch the 9ema
  • can be used to scan on the daily chart
Code:
# Generation time: 2025-07-21T17:23:36.710783Z

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
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) and
Lowest(low[2], 1) < Lowest(low[1], 1);
 
Last edited by a moderator:
Solution
The below script looks for an Inside Candle that has been triggered on the low of the inside candle.

I need the following added to the script:
  • the triggered candle (current candle) touch the 9ema
  • can be used to scan on the daily chart
Code:
# Generation time: 2025-07-21T17:23:36.710783Z

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
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) and
Lowest(low[2], 1) < Lowest(low[1], 1);

that code is very long...
The below script looks for an Inside Candle that has been triggered on the low of the inside candle.

I need the following added to the script:
  • the triggered candle (current candle) touch the 9ema
  • can be used to scan on the daily chart
Code:
# Generation time: 2025-07-21T17:23:36.710783Z

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
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) and
Lowest(low[2], 1) < Lowest(low[1], 1);

that code is very long and complicated. did you copy it from TOS?
tos has some horrible codes. best to take the time to learn thinkscript and make your own.

all you need to find an inside bar, is one line,
def inside = high < high[1] and low > low[1];
to compare the high to the previous high and compare the low to the previous low.

https://trendspider.com/learning-center/the-inside-and-outside-bars-a-traders-guide/

this doesn't make any sense,
'has been triggered on the low of the inside candle.'
an AND formula is true when all parts are true, no one part is more important than any other.


this finds inside and outside bars
inside bars have a cyan dot below the bar
outside bars have a yellow triangle above the bar

a white square is drawn if an inside or outside bar crosses the average line


Code:
# inside_bar_simple

def na = double.nan;
def bn = barnumber();
def h = high;
def l = low;
def o = open;
def c = close;

# look for inside bar and/or outside bar
#  inside bar - bar is smaller than prev bar
#  outside bar - bar is bigger than prev bar
def inside = h < h[1] and l > l[1];
def outside = h > h[1] and l < l[1];

def y = 0.003;
input show_inside_bars_dots = yes;
input show_outside_bars_triangles = yes;

plot zin = if inside and show_inside_bars_dots then l*(1-y) else na;
zin.SetPaintingStrategy(PaintingStrategy.points);
zin.SetDefaultColor(Color.cyan);
zin.setlineweight(3);
zin.hidebubble();

plot zout = if outside and show_outside_bars_triangles then h*(1+y) else na;
zout.SetPaintingStrategy(PaintingStrategy.triangles);
zout.SetDefaultColor(Color.yellow);
zout.setlineweight(3);
zout.hidebubble();




def data = close;
input avg1_type = AverageType.exponential;
input avg1_length = 9;
def avg1 = MovingAverage(avg1_type, data, avg1_length );

input show_avg_line = yes;
plot zavg1 = if show_avg_line then avg1 else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();


# did bar cross over avg line ?
#  or is current bar on one side of line and prev bar is on other side?
def bar_cross_avg = (h > avg1 and l < avg1) 
 or (l > avg1 and h[1] < avg1)
 or (h < avg1 and l[1] > avg1);


def insidex = inside and show_inside_bars_dots and bar_cross_avg;
plot z2 = if insidex then l*(1-(3*y)) else na;
z2.SetPaintingStrategy(PaintingStrategy.squares);
z2.SetDefaultColor(Color.white);
z2.setlineweight(3);
z2.hidebubble();

def outsidex = outside and show_outside_bars_triangles and bar_cross_avg;
plot z3 = if outsidex then h*(1+(3*y)) else na;
z3.SetPaintingStrategy(PaintingStrategy.squares);
z3.SetDefaultColor(Color.white);
z3.setlineweight(3);
z3.hidebubble();


#---------------------------
# ref
# https://trendspider.com/learning-center/the-inside-and-outside-bars-a-traders-guide/
#
 

Attachments

  • img1.JPG
    img1.JPG
    51.1 KB · Views: 22
Solution

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