OPEN-SOURCE SCRIPT

Custom Buy/Sell Pattern Builder

107
Are you tired of using trading indicators that only let you follow fixed, pre-designed rules? Do you wish you could build your own “Buy” or “Sell” signals, experiment with your own ideas, or see instantly if your unique pattern works—without learning coding or hiring a developer?

The Custom Buy/Sell Pattern Builder is designed for YOU.
This TradingView indicator lets ANY trader—even a complete beginner—define exactly what kind of price and volume conditions should create a BUY or SELL label on any chart, in any market, at any timeframe.
You don’t need to know programming. You don’t need to know the definition of a hammer, doji, volume spike, or Engulfing pattern.

With a few clicks and easy dropdown choices, you can:

Make your own rules for buying or selling

Choose how many candles your pattern should look at

Decide if you want the biggest body, the lowest volume, the biggest movement, or any combination you can imagine

The result?
You’ll see clear “BUY” or “SELL” labels automatically show up on your chart whenever the exact rule YOU built matches current price action.
No more guessing. No more forced strategies. Just pure control and visual feedback!

Why Is This Powerful?
Traditional indicators (like MACD, RSI, or even classic candlestick scanners) work the same for everyone—and only as their inventors defined.
But every trader, and every market, is unique.
What if you could say:

“Show me a ‘SELL’ every time the newest candle is bigger than the one before, but with LESS volume, while the bar before that had an even smaller body—but more volume than all others?”

With this tool, it’s EASY!
You simply pick which candle you want to compare (most recent, previous, etc), what to compare (body or volume—body means the candle’s “thickness”, from open to close), choose “greater than”, “less than”, or “equal to”, and set a multiplier if you want (like “half as much”, “twice as big”, etc).

After this, if any bar on the chart fits all your rules, it will mark it as a BUY or SELL, depending on your selection.

This means—

Beginners can start experimenting with their intuition or small ideas, without tech hurdles

Experienced traders can visualize and fine-tune any possible logic, before they commit to backtesting or automating a real strategy

Every “what if” or “I wonder” setup is just 2–3 clicks away

How Does It Work? Simple Steps
1. Choose Your Signal Type
“Buy” or “Sell”

This tells the indicator whether to mark the qualifying bars with a green “BUY” or red “SELL” label

2. Pick How Many Candles To Use
“Pattern Candle Count” input (2, 3, or 4)

Example: If you use 4, the pattern will be applied to the most recent 4 candles at every step

3. Define Your Pattern With Inputs
For each candle (from newest “0” to oldest “3”), you can set:

Body Condition (example: “is this candle’s body bigger/smaller/equal to another?”)

Pick which candle to compare against

Pick “>”, “<”, “>=”, “<=”, or “=”

Set a multiplier if needed (like “0.5” to mean “half as big as” or “2” for “twice as big as”)

Volume Condition (exact same choices, but based on trading volume—not the candle’s price body)

For example:
“Candle0 Body > Candle2 Body”
means “the latest candle’s real-body (open–close) is bigger than the one two bars ago.”

“Candle1 Volume <= Candle2 Volume”
means “the previous candle’s volume is less than or equal to the volume of the bar two periods ago.”

You can leave a comparison blank if you don’t want to use it for a particular candle.

What Happens After You Set Your Rules?
Every bar on your chart is checked for your logic:

If ALL body AND volume conditions are true (for each candle you specified),
AND

The signal side (“Buy” or “Sell”) matches your dropdown,

Then a green “BUY” or red “SELL” label will show right on the bar, so you can visually spot exactly where your logic works!

Practical Example:
Suppose you want an entry setup that is:

“Sell whenever the newest candle’s body is bigger than two bars ago, body before that is bigger than three bars ago, AND the newest candle’s volume is less than or equal to two bars ago, AND the candle three bars ago’s volume is less than or equal to half the candle two bars ago’s volume.”

You’d set:

Pattern Candle Count: 4

Side: Sell

Candle0 Body Ref#: 2, Op: >, Mult: 1

Candle1 Body Ref#: 3, Op: >, Mult: 1

Candle0 Vol Ref#: 2, Op: <=, Mult: 1

Candle3 Vol Ref#: 2, Op: <=, Mult: 0.5

And the script will find all “SELL” bars on your chart matching these conditions.

Inputs Section: What Does Each Setting Do?
Let’s break down each input in the indicator’s Settings one by one, so even if you’re new, you’ll understand exactly how to use it!

1. Pattern Candle Count (2–4)
What is it?
This sets how many candles in a row you want your rule to look at.

Example:

“4” means your rules are based on the most recent candle and the 3 before it.

“2” means you are only comparing the current and previous candles.

Tip:
Beginners often use 4 to spot stronger patterns, but you can experiment!

2. Signal Side
What is it?
Choose “Buy” or “Sell”. The word you pick here decides which colored label (green for Buy, red for Sell) appears if your pattern matches.

Example:

Want to spot where “Sell” is likely? Pick “Sell”.

Change to “Buy” if you want bullish signals instead.

3. Body & Volume Comparison Settings (per Candle)
For each candle (#0 is newest/current, #3 is oldest in your pattern window):

Body Comparison
Candle# Body Ref#

Choose which other candle you want to compare this one’s body to.

“0” = newest, “1” = previous, “2” = two bars ago, “3” = three bars ago

Candle# Body Op (Operator; >, <, >=, <=, =)

How do you want to compare?

“>” means “greater than” (is bigger than)

“<” means “less than” (is smaller than)

“=” means “equal to”

Candle# Body Mult (Multiplier)

If you want relative comparisons. For example, with Mult=1:

“Candle0 body > Candle2 body x 1” means just “0 is larger than 2.”

“Candle0 body > Candle2 body x 2” means “0 is more than double 2.”

Volume Comparison
Candle# Vol Ref# / Op / Mult

Exact same logic as body, but works on the “Volume” of each candle (how much was traded during that bar).

How to Set Up a Rule (Step by Step Example)
Say you want to mark a Sell every time:

The most recent candle’s real body is BIGGER than the candle 2 bars ago;

The previous candle’s body is also BIGGER than the candle 3 bars ago;

The current candle’s volume is LESS than or equal to the volume of candle 2;

The previous candle’s volume is LESS than or equal to candle 2’s volume;

The candle 3 bars ago’s volume is LESS than or equal to HALF candle 2’s volume.

You’d set:

Pattern Candle Count: 4

Side: "Sell"

Candle0 Body Ref#: 2, Op: “>”, Mult: 1

Candle1 Body Ref#: 3, Op: “>”, Mult: 1

Candle0 Vol Ref#: 2, Op: “<=”, Mult: 1

Candle1 Vol Ref#: 2, Op: “<=”, Mult: 1

Candle3 Vol Ref#: 2, Op: “<=”, Mult: 0.5

All other comparisons (operators) can be left blank if you don’t want to use them!

When these rules are met, a bright red “SELL” label will appear right above the bar matching all your conditions.

Practical Tips & FAQ for Beginners
What does “body” mean?
It’s the “true range” of the candle: the difference between open and close. This ignores wicks for simple setups.

What does “volume” mean?
This is the total trading activity during that candle/bar. Many traders believe that patterns with different volume “meaning” (such as low-volume up bars, or high-volume down bars) signal a meaningful change.

What if nothing shows on chart?
It just means your current rules are rarely or never matched! Try making your comparisons simpler (maybe just 2-body and 2-volume conditions to start).

You can always hit “Reset Settings” to go back to default.

Can I use this for both buying and selling?
YES! You can detect both bullish (Buy) and bearish (Sell) custom conditions; just switch “Signal Side.”

Do I need to know coding?
Not at all! Everything is in simple input panels.

Creative Use Cases, Example Recipes & Troubleshooting
Creative Ways to Use
Spotting Reversals
Example:

Buy when: the newest candle body is LARGER than the previous 3 bars, but ALL volumes are lower than their neighbors.

Why? Sometimes, a big candle with surprisingly low volume after a sequence of small bars can signal a reversal.

Finding Exhaustion Moves
Example:

Sell when: the current bar body is twice as big as two bars ago, but volume is half.

Why? A very big candle with very little volume compared to similar bars may show the move is “running out of steam.”

Custom “Breakout + Confirmation” Patterns
Example:

Buy when:

Candle 0’s body is greater than Candle 2’s by at least 1.5x,

Candle 0’s volume is greater than Candle 1 and Candle 2,

Candle 1’s volume is less than Candle 0.

Why? This could catch strong breakouts but filter out noisy moves.

Multi-bar Bias/Squeeze Filter

Use “Pattern Candle Count: 4”

Set all 4 volume conditions to “<” and each reference to the previous candle.

Now, a BUY or SELL only marks when each bar is “dryer”/less active than the last — a classic squeeze or low-volatility buildup.

Troubleshooting Guide
“I don’t see any Buy/Sell label; is something broken?”

Most likely, your rules are too strict or rare! Try using only two comparisons and leave other “Op” inputs blank as a test.

Double-check you have enough candles on the chart: you need at least as many bars as your pattern count.

“Why does a label appear but not where I expect?”

Remember, the script checks your rules for every NEW candle. The candle “0” is always the most recent, then “1” is one bar back, etc.

Check the color and type chosen: “Signal Side” must be “Buy” for green, “Sell” for red.

“What if I want a more complex pattern?”

Stack conditions! You can demand the body/volume of each candle in your window meet a different rule or all follow the same rule in sequence.

Mini Glossary — For Newcomers
Candle/Bar: Each bar on the chart, shows price movement during a fixed time (e.g., one minute, one hour, one day).

Body: The colored (or filled) part of the candle — the open-to-close price range.

Volume: How much of the asset was actually traded that candle/bar.

Reference Index: When you pick “2” as a reference, it means “the candle two bars ago in the pattern window.”

Operator (“Op”): The math symbol used to compare (>, <, =, etc).

Signal Side: Whether you want to highlight bullish (“Buy”) or bearish (“Sell”) bars.

Tips for Getting More Value
Start Simple—try just one or two conditions at first. See what lights up. Slowly add more logic as you get comfortable.

Watch the chart live as you change settings. The labels update instantly—this makes strategy design fast and visual!

Try flipping your ideas: If a certain pattern doesn’t work for buys, try reversing the direction for possible “sell” setups.

Remember: There is NO wrong idea. This indicator is only limited by your creativity—it’s a “strategy playground.”

Example Quick-Start Recipes
Classic Sell:

4 candles, side = Sell

Candle0 Body > Candle2; Candle1 Body > Candle3

Candle0 Vol <= Candle2; Candle1 Vol <= Candle2; Candle3 Vol <= Candle2 × 0.5

Simple Buy After Pause:

3 candles, side = Buy

Candle0 Body > Candle1; Candle0 Vol > Candle1

All other Ops blank

Low-Volume Pullback for Entry:

4 candles, side = Buy

Candle0 Body > Candle2

Candle0 Vol < Candle1; Candle1 Vol < Candle2; Candle2 Vol < Candle3

Final Words
Think of this as your “pattern lab.” No code, no guesswork—just experiment, see what the market actually gives, and design your own visual rulebook.

If you’re stuck, reset the script to defaults—it’s always safe to start again!

If you want more ready-made “recipes” for different strategies/styles, just ask and I’ll send some more setups for you.

Happy building—and may your edge always be YOUR edge!

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.