VIBE QSFM-00155037 S v1.0 Trailing SL Indicator Pine by Panduck

281
# QSFM-00155037 S — Indicator setup, trailing stop and recreation
ulti-Timeframe Bearish Momentum Continuation with Trailing SL
Current artifact: **VIBE QSFM-00155037 S v1.0 Trailing SL Indicator Pine.pine**.
This is the indicator for the strategy we are currently finishing. Strategy Pine is v1.1; indicator versioning starts independently at v1.0. **QSFM-00220347 S has NOT been checked by the user. Work remains one strategy at a time.**

## Install and enable alerts
1. Copy ALL text from the indicator file into a NEW TradingView indicator. Save and add to **standard OANDA:XAUUSD, 5-minute candles**.
2. Set **Mode = Live** for future signals. Live mode has no signal end date and permits only one virtual position at a time. Default source seed/first signal date is June 3, 2026 UTC; changing it may alter initialization and model history.
3. For historical checking, use Original backtest (Jan 1, 2025 23:00 UTC–May 27, 2026 11:45 UTC) or Forward reference (June 3–October 16, 2026, exclusive 09:10 UTC). These historical modes expire at their end date. Return to Live before creating an alert for future signals.
4. Create **ONE alert** with this indicator selected and **Any alert() function call** as the condition. Turn on your preferred phone/app/sound notifications and choose the alert expiration. All four event toggles default ON; disable unwanted types in indicator inputs before creating the alert.
5. Delete/recreate the alert after changes to code, inputs, mode, symbol or timeframe. TradingView stores the script/settings as a server copy. The script cannot create that alert or update its saved settings. [Official alerts documentation](tradingview.com/pine-script-docs/concepts/alerts/).

## The four messages
- **PREPARE:** provisional intrabar momentum heads-up. Developing three-bar momentum is below −0.60 ATR by default (adjustable 0–0.8), with all other current filters, bearish direction, cooldown and position gate passing. It can cancel. Wait before entering. It is not a new entry filter and is not a prerequisite for EXECUTE. At most one PREPARE per developing bar; historical prepares are not reconstructed from OHLC.
- **EXECUTE:** ALL exact source conditions pass at candle CLOSE, including momentum strictly below −0.8 ATR. Enter at the next available candle if taking the signal. Alert price/SL/TP are estimates based on the decision close; recalculate using your actual fill.
- **MOVE SL:** a completed surviving candle lowers the chart-model stop for the following candle. It cannot modify your broker order.
- **MODEL EXIT:** a completed chart candle touched an existing model SL or TP. This is not proof of broker execution; broker protection should trigger when reached, without waiting for an alert at candle close.
Distinct event types can occur on the same bar close. Avoid duplicate UI alerts for the same event set. Alerts fire on realtime data only; historical markers do not send notifications.

## Session in Bangkok
Signal candles OPEN during **18:00–18:59 UTC**, on UTC weekdays. Their confirmations/next entries occur **18:05–19:00 UTC**, which is **01:05–02:00 Bangkok the NEXT DAY**.
For example, a Friday evening UTC setup can validly execute early Saturday in Bangkok. The weekday filter uses UTC, not the Bangkok calendar. Fixed UTC timing does not shift with DST.

## Manual short management: TP stays fixed; SL trails
All distances are gold PRICE dollars, not pips/ticks or the amount of account risk.
Let **E = your actual short fill**. Immediately place regular broker protection:
- Initial **SL = E + $10.00**.
- Fixed **TP = E − $20.00**.
- Trailing activation threshold **E − $10.00**.

After each completed 5-minute candle, if the trade is still open:
1. Honor the SL/TP already in force during that candle. Stop managing a trade that has closed.
2. Update **L = lowest low since YOUR entry**, including the entry candle's post-fill movement. If you entered late, do not count a low reached before your fill. For actual short management, use a consistent executable buy-back/ask-price basis if available; midpoint chart prices are reference data.
3. If E−L < $10, leave SL unchanged.
4. If E−L >= $10, calculate **new SL = minimum(existing SL, L + $10)**.
5. Lower the broker stop after the candle closes, for the next candle. **Never raise/widen a short stop. Never move the fixed TP.**
A candle's LOW wick can activate the trail even if it closes higher. New protection is not applied retroactively to that candle's earlier high.

### Example: short fill 4300.00
| Surviving completed-candle stage | Lowest low since entry | SL for next candle | Fixed TP |
|---|---:|---:|---:|
| Initial protection |4300.00|4310.00|4280.00|
| Before activation |4291.00|4310.00|4280.00|
| Activation at −10 |4290.00|4300.00|4280.00|
| Further favorable movement |4285.00|4295.00|4280.00|
| Later higher low |4285.00 remains|4295.00 unchanged|4280.00|

TP or the current active SL closes the trade when executable prices reach it. Nominal entry-price breakeven is not necessarily net breakeven after costs. If price has already bounced above a new short stop when you amend it, the broker may reject the amendment or require immediate exit. Do not widen the stop just to obtain acceptance; following the rule may require closing at the next tradable price, which can differ from the model.
A broker's continuous trailing-stop feature moves intrabar and is a different rule. To follow this model, use a regular SL and lower it on completed-candle updates.

## Chart references and position gate
Cyan is model next-bar-open entry, red is SL active during that bar, orange dots/labels are next-bar SL, green is fixed TP, yellow is trailing activation. Optional completed H1/H2/H4 EMA lines are available. EXEC S marks the confirmed decision, EXIT marks a chart-model touch. The table shows filter values, custom H4 start time, one-position state and estimated/reference levels. Use the display/anchor controls to suit your chart.
The indicator cannot see your real fill, skipped trades, manual exits or broker stops. It maintains one VIRTUAL position and source 30-minute cooldown. A skipped signal still creates a virtual trade; if real and virtual positions diverge, subsequent signals/management messages may not describe your actual account. Do not assume the broker is flat just because the model is flat.
OANDA TradingView charts are midpoint based; broker orders execute at bid/ask. Set SL/TP from YOUR fill, verify broker position status and treat plotted/model-alert levels as references. [Official price-basis explanation](tradingview.com/support/solutions/43000612408-why-was-my-order-executed-not-executed-although-the-price-on-the-chart-reached-or-didn-t-reach-the-order-level/).
This indicator does not size, place or amend orders.

## Historical evidence — preserve sample labels
| Sample | Trades / wins | WR | Net USD | Status |
|---|---:|---:|---:|---|
| Original Jan 2025–May 2026 source training |21 /16|76.19%|9612.50|Original engine replayed; full TV window not yet supplied|
| June–Oct 2026 source forward |8 /6|75%|5361.00|User TV matched times/size/PnL; one price-pair shift|
| User TV v1.1 Last365days subset |14 /12|85.71%|10371.00|Excludes first7 source trades; one SL/TP conflict|
The subset's 85.71% is NOT the original training result and is not a future win-rate forecast. March4, 2026 both SL/TP are touched: source stop-first earns377.50 versus nativeTV TP2000. Thus fullsource9612.50 − omittedearly7net864 + exitdifference1622.50 = partialTV10371.00. The June24 forward price pair is0.145lower onTV with unchanged1000loss.
The indicator uses the source's conservative stop-first OHLC management. It may differ from native Strategy Tester on the March4 exit even with identical entries. No hardcoded dates or trades force a match.

## Verification and next check
Entry/initialization code is copied unchanged from this strategy's v1.1 calculation block. A separately executed translation of the indicator's next-bar/array/old-stop-first management on the original99,023M5bars reproduced ALL21 entry/exit times, entry prices, stops, targets and P/L:16wins,9612.50. See Indicator verification.json. This is numerical model verification, not execution of Pine itself.
**Indicator TradingView compilation, historical chart overlay and realtime alert delivery are pending.** Send any compiler error verbatim or a screenshot of the loaded indicator. Default LIVE has no expired signal-end date; historical modes are for comparison only.
Indicators use available CHART history; they do not inherit a Strategy Report's Deep Backtesting history. The seed-history warning identifies missing coverage. Load at least241 source bars for readiness, and the complete selected seed context when comparing history. The actual original forward initialization context remains unconfirmed.

## Self-contained recreation summary for another chat
Pine comments and implementation contain exact rules. Preserve:
- M5 OANDA standard candles, source first-close HTF EMA seeds and full-count buckets only.
- H1 EMA50, H2 EMA20, fixedUTC+3 H4 EMA50. H4 starts03,07,11,15,19,23UTC. Each completed HTF close must be strictly below its EMA. At decision bar OPEN use only HTF buckets whose end<=that opening time. Discard incomplete12/24/48M5 buckets without EMA updates; no broker-default H4 substitution.
- ATR14 mean-of-first14TR then Wilder; inclusive last120 ATR rank including current,0.40..0.95 inclusive. RSI14 seeded first14 price changes then Wilder; avgLoss0=>100. RSI>28, bearish candle, close-close[3]<−0.8ATR strictly; source index>=240.
- UTC18 weekday opening session, confirmed-close execute, next-bar-open model fill, 30-minute signal-open versus last-entry-open cooldown, one virtual position including pending reservation.
- E+10 initial SL, E−20 FIXED TP, wick-low activation at−10, old protection before ratcheting SL down for next bar, conservative stop-first if both hit.
- Live no-end default versus independent historical phase dates/seeds. Provisional prepare0.60ATR threshold affects heads-up only. Four dynamic event toggles, varip once-bar prepare latch, confirmed state commits and one server alert recreated after changes.
Naming is VIBE QSFM-00155037 S v1.0 Trailing SL Indicator Pine. Use Windows CRLF/UTF8 without BOM. Do not add body-size, range, M5EMA, RSI-upper, daily-cap or metadata loss-pause filters.

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.