Builder7 min read·Updated 11/19/2026

Price Action Patterns as Rules: Turning Pin Bars, Inside Bars and Double Tops into Explicit Logic

How to convert recognisable candlestick and chart patterns into measurable conditions a builder can export, including confirmation, invalidation and the once-per-pattern problem.

Educational content only. It is not financial advice, and examples do not promise results.

A price action pattern is easy to point at and hard to define. On a chart, a pin bar looks like a rejection; an inside bar looks like consolidation. To a computer there is no looks like — there are only numbers compared with numbers. This guide is about closing that gap: taking the patterns most people can recognise and writing them as explicit, testable rules.

Key takeaways

  • Every pattern needs a geometric definition before it can be automated at all.
  • A definition alone is not a strategy: you still need confirmation, invalidation and position size.
  • Patterns can be detected repeatedly on the same structure unless you add a once-per-occurrence rule.
  • Detection must use only data available on the bar it fires — hindsight labelling is not detection.
  • In Lupuso, the Price Action template family (Inside Bar Breakout, Double Top/Bottom, Pin Bar at Pivot, Break & Retest) gives you editable starting points for exactly this work.

Why does a pattern need measurements?

Because a visual impression hides several decisions. When you look at a candle and call it a pin bar, you have silently decided that the wick is long enough, the body is small enough, and the candle sits somewhere relevant. Those three judgements are exactly what has to become explicit. The good news is that they are all measurable: lengths, ratios, comparisons against neighbours, and positions relative to prior highs and lows.

A useful habit is to describe the pattern in words first, then replace every adjective with a number or a comparison. Where you cannot replace it, you have found the part of the idea you do not understand yet.

How do you turn a pin bar into a rule?

A pin bar is usually described as a candle whose wick is much longer than its body, appearing after a move and projecting away from it. Written as conditions:

  1. Wick-to-body ratio. Define which wick you measure (lower for a bullish pin, upper for a bearish pin) and require it to be at least a chosen multiple of the body. That multiple is an input, not a truth.
  2. Body placement. Require the body to sit in one part of the candle range — for example within the outer portion — so a doji-like candle and a marubozu are not both accepted.
  3. Projection. Require the wick to extend beyond the range of one or more previous candles. Without this, a pattern inside a wide bar will qualify.
  4. Location. This is where at a pivot comes in. Define a pivot as a swing point using a fixed number of bars on each side, then require the pin's extreme to be at or beyond that swing.
  5. Confirmation. Decide whether the pin itself is enough, or whether the next candle must close in the direction of the rejection, or break the pin's opposite extreme.
  6. Invalidation. State exactly where the idea is wrong — typically beyond the tip of the wick — because that point becomes your stop and therefore your size.

Notice that steps 4 and 6 do more work than the ratio in step 1. Most of the meaning in a pin bar comes from where it appears and where it fails, not from its proportions.

How do you turn an inside bar into a rule?

An inside bar is a candle whose entire range sits inside the previous candle's range. As a rule:

codeLupuso
high[1] <= high[2]
AND low[1]  >= low[2]

Two decisions hide in those two lines. First, do you allow equality, or require strict containment? Second, do you require only the immediately preceding bar, or allow a wider mother bar? Both are choices, and both change how often the pattern fires.

An inside bar on its own is not an entry. The common structure is a breakout: after the inside bar forms, wait for price to close beyond the mother bar's high or low, then act. That adds three more parameters — the breakout reference, whether a close or a touch counts, and how many bars you are willing to wait before the setup expires. Lupuso's Inside Bar Breakout template packages exactly this chain, with each of those thresholds exposed as an input.

How do you turn a double top into a rule?

A double top is two highs at roughly the same level, separated by a pullback, followed by a break of the level between them. To write it down you must choose:

  1. Swing detection. How a swing high is identified (for example a high higher than N bars on each side).
  2. Tolerance. How close the two highs must be — a fixed amount, a percentage, or a multiple of ATR. This is the single most sensitive parameter in the whole pattern.
  3. Separation. The minimum and maximum number of bars between the two swings.
  4. The neckline. Which low defines the level that must break.
  5. Trigger and invalidation. A close below the neckline as the trigger, and the second high as the level beyond which the pattern is void.

Double Top/Bottom in Lupuso is this chain with editable thresholds, so you can see how much of the pattern's behaviour is driven by your tolerance choice rather than by the idea itself.

What about break and retest?

Break & Retest is a pattern you have already met in another form. A level is crossed, then price returns to it for the first time. The retest is a first-return condition, which means it inherits all the questions from first-return logic: what counts as a touch, how long the level stays valid, and whether the return must come from the expected side. Combining a break with a first return is one of the cleanest examples of how two simple rules compose into a tradable structure — and of how many small decisions the composition contains.

How do you stop a pattern firing repeatedly?

This is the most commonly forgotten piece. A candle can satisfy a pin bar definition on several consecutive evaluations, and the same double top remains detectable for many bars after it completes. Without state, a backtest can record the same structure as several signals and distort everything downstream.

The fix is to treat each detected pattern as an instance with its own lifecycle: created, confirmed, invalidated, or expired. Once an instance has fired, it is closed and cannot fire again, even if the underlying conditions remain true. In a block builder this is what the state and trade-management blocks are for — they turn a pattern from a repeating measurement into a single event.

Common mistakes

  • Defining the pattern from the chart after seeing how it turned out, then testing as if the definition came first.
  • Leaving the tolerance of a double top or the ratio of a pin bar implicit, so results cannot be reproduced or discussed.
  • No invalidation, which means there is no objective place for a stop and no way to compute position size.
  • Counting one structure multiple times because there is no once-per-instance rule.
  • Requiring confirmation from a future bar without accounting for the delay that introduces.
  • Mixing timeframes in the definition without stating which bar belongs to which timeframe.

Risk note

Patterns are descriptions of price behaviour, and their definitions are conventions rather than discoveries. Different reasonable thresholds mark different patterns on the same chart, which means a backtest of a pattern rule is largely a test of your thresholds. Backtests are not predictions, and a pattern that appears clear in hindsight is often ambiguous in the moment it must be acted on. Trading carries a risk of loss. Build the definition, test it on data you did not use to write it, and keep position sizes aligned with the distance to your stated invalidation point rather than with your confidence in the pattern.

English · Español · Français · Deutsch · Português · 中文 · العربية · हिन्दी · 9 supported locales