External Signals Strategy Tester v5

1. Purpose
This Pine Script strategy is a universal back‑tester that lets you plug in any external buy/sell series (for example, another indicator, webhook feed, or higher‑time‑frame condition) and evaluate a rich set of money‑management rules around it – with a single click on/off workflow for every module.
2. Core Workflow
Feed signals
Buy Signal / Sell Signal inputs accept any series (price, boolean, output of request.security(), etc.).
A crossover above 0 is treated as “signal fired”.
Date filter
Start Date / End Date restricts the test window so you can exclude unwanted history.
Trade engine
Optional Long / Short enable toggles.
Choose whether opposite signals simply close the trade or reverse it (flip direction in one transaction).
Risk modules – all opt‑in via check‑boxes
Classic % block – fixed % Take‑Profit / Stop‑Loss / Break‑Even.
Fibonacci Bollinger Bands (FBB) module
Draws dynamic VWMA/HMA/SMA/EMA/DEMA/TEMA mid‑line with ATR‑scaled Fibonacci envelopes.
Every line can be used for stops, trailing, or multi‑target exits.
Separate LONG and SHORT sub‑modules
Each has its own SL plus three Take‑Profits (TP1‑TP3).
Per TP you set line, position‑percentage to close, and an optional trailing flag.
Executed TP/SLs deactivate themselves so they cannot refire.
Trailing behaviour
If Trail is checked, the selected line is re‑evaluated once per bar; the order is amended via strategy.exit().
3. Inputs Overview
Group Parameter Notes
Trade Settings Enable Long / Enable Short Master switches
Close on Opposite / Reverse Position How to react to a counter‑signal
Risk % Use TP / SL / BE + their % Traditional fixed‑distance management
Fibo Bands FIBO LEVELS ENABLE + visual style/length Turn indicator overlay on/off
FBB LONG SL / TP1‑TP3 Enable, Line, %, Trail Rules applied only while a long is open
FBB SHORT SL / TP1‑TP3 Enable, Line, %, Trail Rules applied only while a short is open
Line choices: Basis, 0.236, 0.382, 0.5, 0.618, 0.764, 1.0 – long rules use lower bands, short rules use upper bands automatically.
4. Algorithm Details
Position open
On the very first bar after entry, the script checks the direction and activates the corresponding LONG or SHORT module, deactivating the other.
Order management loop (every bar)
FBB Stop‑Loss: placed/updated at chosen band; if trailing, follows the new value.
TP1‑TP3: each active target updates its limit price to the selected band (or holds static if trailing is off).
The classic % block runs in parallel; its exits have priority because they call strategy.close_all().
Exit handling
When any strategy.exit() fires, the script reads exit_id and flips the *_Active flag so that order will not be recreated.
A Stop‑Loss (SL) also disables all remaining TPs for that leg.
5. Typical Use Cases
Scenario Suggested Setup
Scalping longs into VWAP‐reversion Enable LONG TP1 @ 0.382 (30 %), TP2 @ 0.618 (40 %), SL @ 0.236 + trailing
Fade shorts during news spikes Enable SHORT SL @ 1.0 (no trail) and SHORT TP1,2,3 on consecutive lowers with small size‑outs
Classic trend‑follow Use only classic % TP/SL block and disable FBB modules
6. Hints & Tips
Signal quality matters – this script manages exits, it does not generate entries.
Keep TV time zone in mind when picking start/end dates.
For portfolio‑style testing allocate smaller default_qty_value than 100 % or use strategy.percent_of_equity sizing.
You can combine FBB exits with fixed‑% ones for layered management.
7. Limitations / Safety
No pyramiding; the script holds max one position at a time.
All calculations are bar‑close; intra‑bar touches may differ from real‑time execution.
The indicator overlay is optional, so you can run visual‑clean tests by unchecking FIBO LEVELS ENABLE.
A modular, click‑to‑configure strategy back‑tester for TradingView
1. Purpose
This script turns any external signal or custom line crossover into a fully featured trading system with:
Direction filters (enable Long / Short separately).
Automatic or manual Stop‑Loss + 3 Take‑Profits (each with optional trailing).
Dynamic exits driven by Fibonacci Bollinger Bands (FBB).
Classic fixed‑percent TP / SL / Break‑Even block.
Independent LONG and SHORT money‑management modules.
All options are exposed as intuitive check‑boxes and dropdowns—no code edits required.
2. How entries work
Mode Description Where to enable
External series Choose Buy Signal / Sell Signal – any series (indicator plot, security(), etc.). A crossover above 0 triggers the entry. Top‑level inputs
Line‑cross trigger Select Line Source (any plot/price) and crossing direction. Long Line Cross & Short Line Cross groups
Both mechanisms are combined with OR logic—either one can open a trade.
3. Exit arsenal
Each side (long/short) has its own module:
Element Options
Stop‑Loss ✓ Enable · Side (Upper/Lower) · Level (Basis … 1.0) · ✓ Trail with separate side/level
TP1‑TP3 same controls + % Qty to close
Band side logic Upper selects the band above Basis, Lower the one below. Exactly matches visible lines.
Trailing If checked, price re‑locks to the chosen band each bar; if off, price is fixed at entry.
Self‑deactivation When a TP fires its flag flips off so it cannot execute again. An SL cancels remaining TPs.
Classic % block (TP %, SL %, BE %) runs in parallel and, if triggered, uses strategy.close_all().
4. Fibonacci Bollinger Bands overlay
ATR‑scaled envelopes around a configurable base line (VWMA / HMA / SMA / EMA / DEMA / TEMA).
Levels: Basis, 0.236 … 1.0.
View modes: Full (all lines), Cloud, Extremes.
Completely optional—uncheck FIBO LEVELS ENABLE to hide visuals while using their prices internally.
5. Input groups quick map
Group Key fields
Date Range Start / End timestamp
Buy / Sell Signal External series for entry
Long / Short Line Cross ✓ Enable · Line Source · Direction
Trade Settings Enable Long / Short · Close‑on‑Opposite · Reverse Position
Risk % Use % TP / SL / BE + their percentages
Fibo Bands Visual toggle & styling
FBB LONG / SHORT SL Enable · Side · Level · Trailing options
FBB LONG / SHORT TP1‑TP3 ditto + % Qty
6. Typical set‑ups
Scenario Suggested inputs
Intraday trend follow Long Line Cross: price Below→Above VWAP; Long SL Lower 0.382 (trail); TP1‑3 on Upper bands; disable Short module.
Mean‑reversion scalps External Buy/Sell from RSI divergence; both modules active; SL on opposite 1.0 band, no trailing; TP1 Upper/Lower 0.382 only.
Classic fixed % Disable all FBB groups, keep Risk % block on.
7. Execution details & limitations
One position at a time – no scaling in (except partial exits via TP1‑3).
Calculations are end‑of‑bar; intra‑bar touches aren’t simulated.
Trailing updates once per bar – not tick‑by‑tick.
Strategy quantity defaults to 100 % equity; adjust Position Size or switch sizing mode as needed.
8. Changelog
v7
Added explicit Upper / Lower band selection for every SL / TP.
Fixed/Trailing price logic—levels captured at entry, only updated when Trail is on.
Retained all v6 features (generic line‑cross entry, separate long/short modules).
Earlier versions: v6 (line‑cross entry), v5 (dual long/short modules), v4 (multi‑TP with trailing), v1‑3 initial builds.
9. Usage
Load script on any symbol / timeframe.
Open settings ⚙️.
Toggle the modules you need, pick band sides/levels, hit OK.
Scroll the chart or run strategy tester to inspect performance.
A back‑testing engine that manages positions opened by your own entry signals and closes them on dynamically‑calculated Fibonacci Bollinger Band levels.
It is designed for strategy prototyping: you connect any indicator / alert to generate a buy‑ or sell‑pulse, then let this script handle position size, SL/TP logic and performance statistics.
▸ How it Enters Trades
External pulses
Buy Signal / Sell Signal inputs accept any series:
1 (or true) on the bar → long / short entry next bar open.
Optional line‑cross
Enable Long Line Cross or Short Line Cross to enter when close crosses a custom source line (MA, VWAP, etc.).
Date range filter – back‑test only the period you need.
▸ Fibonacci Bollinger Bands (FBB)
Combines a selectable basis (VWMA, HMA, SMA, EMA, DEMA, TEMA) with ATR‑scaled deviation.
Seven Fibonacci levels per side (0.236 … 1.0) are plotted; you can pick any of them for SL/TP.
View modes: Full / Cloud / Extremes to keep the chart clean.
▸ Position Management
Component Setting Behaviour
Stop‑Loss Side + Level (+ optional trailing) Updates each bar if Trail SL is on
TP1 (Trail‑enabled) Side + Level (+ optional trailing line) Trails every bar when enabled
TP2 / TP3 (Fixed) Side + Level Price is fixed on the first bar after entry
Close on Opposite / Reverse on Opposite — Either exit or flip the position on an opposite pulse
Classic %‑Risk block TP %, SL %, BE % Percent‑based kill‑switches that work in parallel to FBB exits
▸ Quick‑Start
Add your entry indicator to the same chart and pipe its boolean/binary output into Buy Signal / Sell Signal (or just paste a security‑call series).
Choose position side(s) (Enable Long / Enable Short).
Pick FBB levels for SL, TP1‑3.
Turn Trail TP1 on if you want it to follow another FBB line; leave TP2/TP3 as simple targets.
Press “Add to Chart” – the script will plot entries, exits, and a full TradingView Strategy Report.
▸ Tips & Notes
Works on any symbol / timeframe; no repaint – all calculations use historical data only.
If your entry signal fires inside the disabled Date Range, nothing happens.
Sum of TP quantities should be ≤ 100 %.
Trailing uses limit‑orders; if your market’s syminfo.mintick is large, TP1 may update in visible steps.
The script itself does not generate entries – that is left to your indicators or the optional line‑cross.
Happy testing and fine‑tuning!
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.