Finding candlesticks


New member
Hello all,

Trying to write a script with the following conditions:

1. Find a Green bar.
2. Find a Topping Tail Red bar with a higher high and higher low in any 15 bars after condition 1 is met.
3. If both conditions are met, then draw a red arrow on any 20 bars after the 2nd condition is met that makes a lower low (trades below the low of the Topping Tail Red bar).

Is it possible to write a working script for the conditions mentioned above?

I tried Chatgpt but getting errors (please see code).

Any help with this is appreciated.

Thank you in advance.

# Define Green Candle Conditions
def isGreenBar = close > open;

# Define Topping Tail Red Candle Conditions
def isToppingTailRed = close < open
                    and high - open > close - low;
# Initialize variables to track Green and Topping Tail Red Candles
def greenBar = 0;
def toppingTailBar = 0;

# Find Green Bar
if isGreenBar {
    greenBar = 1 else;

# Find Topping Tail Red Bar with Higher High and Higher Low within the next 15 bars
for i = 1 to 15 {
    if isToppingTailRed
       and high > high[i]
       and low < low[i] {
        toppingTailBar = i;

# Initialize variables to track the lower low condition
def lowerLowBar = -1;

# Find a bar with a lower low within the next 20 bars after the Topping Tail Red Bar
if toppingTailBar > 0 {
    for j = 1 to 20 {
        if low < low[toppingTailBar] {
            lowerLowBar = j;

# Draw a Red Arrow with "Sell" When the Lower Low Condition Is Met
def sellCondition = greenBar > 0 and toppingTailBar > 0 and lowerLowBar > 0;
plot sellSignal = if sellCondition then low else double.nan;
AddLabel(yes, "Sell", Color.RED);

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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