OPEN-SOURCE SCRIPT

Gold M15 Signal Engine with H4 Trend Filter

3 708
WHAT THIS SCRIPT DOES

This indicator detects intraday entry setups on the 15-minute chart and attaches a complete, pre-calculated trade frame to each one: an entry, a stop-loss, and three targets. It then tracks that setup bar by bar and reports what actually happened to it — which target was reached, whether the stop was hit, and when the setup has gone stale.

It was built and tuned for gold (XAU/USD) on the 15-minute timeframe. The script deliberately refuses to run on any other timeframe.


WHY IT IS DIFFERENT FROM A STANDARD SIGNAL SCRIPT

Most published signal scripts stop at the arrow. They mark an entry and leave the trader to guess the rest. Three design choices separate this one:

1. Every signal ships with its own risk frame.
The stop-loss is derived from the structural level that produced the signal, not from a fixed pip distance, and it is then capped by a percentage-of-price ceiling so a single wide candle cannot create an unreasonable stop. The first target is ATR-based. The second target prefers a real support or resistance level detected on the chart, and only falls back to an ATR multiple when no suitable level exists. This means targets sit where price is actually likely to react, not at arbitrary distances.

2. The higher timeframe has a veto.
A 4-hour EMA200 trend filter gates every signal. A long is only permitted when the 4-hour close is above its own EMA200, and a short only when it is below. This removes the most common failure mode of intraday signal scripts — firing counter-trend entries during a strong higher-timeframe move. The filter can be switched off in the settings.

3. Signals report their own outcome.
Once a signal is active the script follows it: it marks the bar where each target was reached, automatically moves the displayed stop to breakeven after the first target and to the first target after the second, and hides the setup once the stop is hit. Setups that neither complete nor fail within a configurable number of bars are marked as expired rather than being left on the chart indefinitely.


HOW THE SIGNAL ENGINE WORKS

Three independent detection paths can produce a signal. All of them must additionally pass the RSI gate, the higher-timeframe filter, and a cooldown period.

EMA pullback. In an aligned trend (EMA20 above EMA50 and price above EMA200 for longs, inverted for shorts), price wicks into the EMA20 and closes back on the trend side of it. The candle must close in the outer 55% of its own range, which filters out indecisive bars.

Support and resistance reaction. Price tests a detected level within a 0.15% tolerance and closes back on the correct side of it with the same candle-strength requirement.

N-bar breakout. Price closes beyond the highest high or lowest low of the previous N bars with a directional close.

Support and resistance levels are built from confirmed pivot highs and lows. A minimum-gap rule prevents clustered levels from stacking on top of each other, and the number of active levels on each side is capped.

RSI gate. The pullback path requires RSI between 35 and 65 — it avoids entries that are already stretched. The reaction and breakout paths use wider one-sided bounds appropriate to their context.

Cooldown. A minimum number of bars must pass between signals, and a new signal in the same direction is blocked while an earlier one is still running.


READING THE PANEL

The panel in the top-right corner shows the direction of the active signal, its entry, the current stop, all three targets, the bar the signal was created on, its live status, and the current 4-hour trend state.

The status line progresses through: active, then first target reached with the stop moved to entry, then second target reached with the stop moved to the first target, then complete. If the stop is hit the panel is removed and the bar is marked on the chart.


SETTINGS

Moving averages — lengths for the three EMAs.
Support / resistance — pivot lookback, how many levels to keep on each side, and the minimum percentage gap between them.
Signal engine — RSI length, cooldown bars, breakout lookback, and how many bars before a setup is marked expired.
Targets and stop — ATR length, the three ATR multipliers, and the maximum stop size as a percentage of price.
Higher-timeframe filter — enable or disable the 4-hour trend veto.


LIMITATIONS - PLEASE READ

It runs on the 15-minute timeframe only. On any other timeframe the script draws a warning and produces nothing. The thresholds were tuned for 15-minute gold behaviour and do not transfer.

It was tuned on gold. The tolerance values, ATR multipliers and RSI bounds reflect how XAU/USD moves. On other instruments the defaults will need adjustment and the results may differ substantially.

Signals are evaluated on confirmed bars only. Nothing is drawn or evaluated from an unclosed bar, so the script does not repaint — but this also means a signal appears at the close of its bar, not during it.

The 4-hour filter uses the last closed 4-hour bar. The higher-timeframe request uses lookahead_off, so no future data is used. The consequence is that within a forming 4-hour bar the filter reflects the previous one.

Target and stop levels are calculated at the moment the signal fires and are not recalculated afterwards. If volatility changes materially after entry, the levels do not adapt.

The stop and target tracking uses bar high and low values. When both the stop and a target fall inside the same bar's range, the script resolves the stop first. Real intrabar sequence may have differed.

It does not know about scheduled news. Economic releases routinely produce moves that invalidate technical setups. The script has no awareness of the economic calendar.

This is an analysis tool, not a trading system. It does not account for spread, commission, slippage or position sizing, and no historical behaviour implies future results.


ON PERFORMANCE CLAIMS

This publication makes no claim about win rate, accuracy or profitability, because no such claim can be substantiated for future market conditions. What the script does is make each setup's assumptions explicit and visible so you can evaluate them yourself.


ORIGINALITY

The three detection paths use well-known building blocks — EMAs, RSI, ATR, pivot-based levels. The original work is in how they are combined: a structural stop bounded by a percentage ceiling, a second target that prefers real chart levels over a fixed multiple, a higher-timeframe veto applied uniformly across all three detection paths, and a per-signal outcome tracker with automatic stop progression and expiry. The code is entirely original and is published open-source so every one of these mechanics can be inspected and modified.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.