Tool
Cross
calc.cross
Inputs
The first number line (e.g. a fast moving average).
The second number line (e.g. a slow moving average or a level).
First bar of the scan window (windowed_count mode).
Last bar of the scan window (windowed_count mode).
Outputs
A boolean that is true on each bar the chosen cross event occurs.
Cross watches two lines and fires true on every bar where the relationship you picked happens. It's the workhorse for crossover strategies: a fast line crossing a slow line, a price touching a level, or two lines pulling apart.
How it works
You wire two number lines (series_a and series_b) plus a start and end bar for the scan window, choose a mode, and Cross checks each bar for that event. Pick one of nine events with the mode picker and the inspector greys out the settings that don't apply, so you only see the knobs that matter.
Modes
Mode options
Fires on the exact bar the two lines cross.
When to use: The classic crossover trigger — a fast line crossing a slow line.
Fires if a cross happened within the last few bars.
When to use: Catch a cross you may have missed by one or two bars.
Counts how many crosses fall inside a bar window.
When to use: Gate on 'at least N crosses' (or 'no crosses') over a span.
Fires only after the new side holds for `dwell` bars.
When to use: Filter out fake-outs that immediately cross back.
Fires once the lines separate by `min_gap` after crossing.
When to use: Require a real break, not a hairline touch.
Fires when the lines come within `epsilon` of each other.
When to use: Detect a test of a level without a full cross.
Fires when the lines touch then pull apart.
When to use: Bounce / rejection setups off a moving average or level.
Fires while the gap between the lines is shrinking.
When to use: Anticipate a cross as two lines close in.
Fires while the gap between the lines is widening.
When to use: Confirm a trend as the lines spread apart.
Direction options
Only when series_a rises through series_b.
When to use: Long-only crossover entries.
Only when series_a falls through series_b.
When to use: Short-only crossover entries.
Either direction fires.
When to use: Symmetric setups that trade both sides.
Bar alignment options
Evaluates only finished bars — never repaints.
When to use: The safe default for backtests and live trading.
Reacts inside the forming bar in tick mode.
When to use: Only when you knowingly want intra-bar reaction.
Gap unit options
min_gap / epsilon are raw price differences.
When to use: Single symbol where absolute distance is meaningful.
min_gap / epsilon are a percent of the midpoint.
When to use: Portable thresholds across symbols of different scale.
Equality policy options
A move off exact equality counts as a cross.
When to use: The recommended, most intuitive behavior.
A move off equality is suppressed.
When to use: Avoid double-counting flat ties.
Carries the prior side forward through equality.
When to use: Keep a stable bias across flat patches.
Configuration
Picks which crossing event to detect: instant_cross, recent_cross, windowed_count, confirmed_cross, threshold_cross, touch, touch_and_reject, convergence, or divergence.
Which side fires the signal — 'up' when series_a rises through series_b, 'down' when it falls through, or 'any' for both.
'Closed' (recommended) evaluates only finished bars so nothing repaints; 'live' reacts inside the current bar in tick mode but can flip before the bar closes.
How many bars back the event may have happened and still count; 1 means this bar only, larger values accept later entries.
When on, searches future bars instead of past ones — safe only with indicators already plotted into the future; leave off for normal indicators.
How many bars in a row the gap must shrink (convergence) or widen (divergence) to fire; larger values trigger rarely but with more conviction.
The smallest number of crossings the window must contain to fire; 1 is the classic 'at least one cross' gate.
The largest number of crossings the window may contain; -1 means no upper cap, and Min and Max both at 0 makes a 'no crosses allowed' gate.
Off (recommended) slides the window bar-by-bar so each bar gets its own answer; on fixes the window in time for legacy Shayan setups.
How many bars the new trend must hold before a confirmed cross fires; higher gives later but more reliable entries.
How far the lines must separate after a threshold cross before it fires; a re-cross before this distance cancels the pending signal.
How close the lines must be to count as touching; 0 requires exact equality, a small positive value means 'close enough'.
Units for min_gap and epsilon — 'price' uses the raw difference, 'percent' uses percent of the midpoint so it scales across symbols.
What to do when the lines were exactly equal last bar — 'treat_as_cross' (recommended) counts the move off equality, 'ignore' blocks it, 'hold_state' carries the prior side forward.
After a cross fires, ignore further crosses for this many bars to stop rapid back-and-forth signals; 0 disables it.
Connects to
Examples
- Signal trigger: in instant_cross mode with direction 'up', fire a long when a fast EMA crosses above a slow EMA (a golden cross).
- Filter: in touch mode, gate entries to only the bars where price comes within a pip of a moving average.
Common mistakes
- Turning on 'forward' with raw price — it peeks into future bars and produces unrealistic backtests; only use it with indicators already drawn into the future like Ichimoku's Senkou lines.
- Leaving direction on 'any' when you only want one side, so death crosses fire your long entry too.