Pine Script v4 · Strategy
S&P Bear Warning Indicator
A Pine Script v4 strategy built on ATR (14), Highest (close, 22) and Crossover (mom, VIXFix). It has 2 order rules, 1 entry among them, and trades short only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1 commission. 7 settings; defaults include Length 50, Source close and Band Upper 5.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does S&P Bear Warning Indicator repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did S&P Bear Warning Indicator do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can S&P Bear Warning Indicator be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- What alerts does S&P Bear Warning Indicator have?
- 1
- Sell SPY.
- Does S&P Bear Warning Indicator use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- MOM
- ATR
- VIXFix
- Upper Band
- Lower Band
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
4 settings have no label
In the settings dialog bandUpper (line 18), bandLower (line 19), showVixFix (line 21), showMomentum (line 22) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 55, 57. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 27
transp = on line 27, 28, 35, 36, 37. v5 folds the transparency into the colour with color.new(c, transp).
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames atr → ta.atr, highest → ta.highest, crossover → ta.crossover, crossunder → ta.crossunder.
- 2 strategy calls use the when = argument (line 55, 57). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 11: //@version=4 → //@version=5
- Line 25: atr → ta.atr
- Line 27: transp = 100 → color.new(color.silver, 100)
- Line 28: transp = 90 → color.new(color.orange, 90)
- Line 32: highest → ta.highest
- Line 32: highest → ta.highest
6 more edits
- Line 35: transp = 90 → color.new(color.red, 90)
- Line 36: transp = 90 → color.new(color.red, 90)
- Line 37: transp = 85 → color.new(color.red, 85)
- Line 48: crossover → ta.crossover
- Line 49: crossunder → ta.crossunder
- Line 55: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯//This is best used as a daily time frame indicator-//@version=4+//@version=5strategy(title="S&P Bear Warning", shorttitle="Bear Warning", pyramiding=0,⋯mom = src - src[len]-myAtr = atr(14)+myAtr = ta.atr(14)plot(showMomentum ? mom : na, color=color.blue, title="MOM")-plot(showMomentum ? 0 : na, color=color.silver, title="MOM Zero line", style=plot.style_circles, transp=100)+plot(showMomentum ? 0 : na, color=color.new(color.silver, 100), title="MOM Zero line", style=plot.style_circles)-plot(showMomentum ? myAtr : na, color=color.orange, title="ATR", transp=90)+plot(showMomentum ? myAtr : na, color=color.new(color.orange, 90), title="ATR") ⋯VIXFixLength = input(22,title="VIX Fix Length")-VIXFix = (highest(close,VIXFixLength)-low)/(highest(close,VIXFixLength))*100+VIXFix = (ta.highest(close,VIXFixLength)-low)/(ta.highest(close,VIXFixLength))*100plot(showVixFix ? VIXFix : na, "VIXFix", color=color.maroon) -band1 = plot(showVixFix ? bandUpper : na, "Upper Band", color.red, 1, plot.style_line, transp=90)+band1 = plot(showVixFix ? bandUpper : na, "Upper Band", color.new(color.red, 90), 1, plot.style_line)-band0 = plot(showVixFix ? bandLower : na, "Lower Band", color.red, 1, plot.style_line, transp=90) +band0 = plot(showVixFix ? bandLower : na, "Lower Band", color.new(color.red, 90), 1, plot.style_line) -fill(band1, band0, color=color.red, transp=85, title="Background")+fill(band1, band0, color=color.new(color.red, 85), title="Background") ⋯//VIX-Long2 = crossover(mom, VIXFix)+Long2 = ta.crossover(mom, VIXFix)-Short2 = crossunder(mom, VIXFix)+Short2 = ta.crossunder(mom, VIXFix)//Warning Alert⋯if time >= start and time <= end- strategy.entry("SELL", false, when = Short1)+ strategy.entry("SELL", strategy.short, when = Short1) ⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 16: input() → input.int()
- Line 17: input() → input.source()
- Line 18: input() → input.int()
- Line 19: input() → input.int()
- Line 21: input() → input.bool()
- Line 22: input() → input.bool()
3 more edits
- Line 31: input() → input.int()
- Line 55: when = Short1 → if block
- Line 57: when = Long2 → if block
⋯//Momentum-len = input(50, minval=1, title="Length")+len = input.int(50, minval=1, title="Length")-src = input(close, title="Source")+src = input.source(close, title="Source")-bandUpper = input( 5)+bandUpper = input.int( 5)-bandLower = input(-5)+bandLower = input.int(-5)// ————— Control plotting of each signal. You could use the same technique to be able to turn acc/dist on/off.-showVixFix = input(true)+showVixFix = input.bool(true)-showMomentum = input(true)+showMomentum = input.bool(true) ⋯//VIX-VIXFixLength = input(22,title="VIX Fix Length")+VIXFixLength = input.int(22,title="VIX Fix Length")VIXFix = (ta.highest(close,VIXFixLength)-low)/(ta.highest(close,VIXFixLength))*100⋯if time >= start and time <= end- strategy.entry("SELL", strategy.short, when = Short1)+ if Short1+ strategy.entry("SELL", strategy.short) -strategy.close("SELL", when = Long2)+if Long2+ strategy.close("SELL")Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯//This is best used as a daily time frame indicator-//@version=5+//@version=6strategy(title="S&P Bear Warning", shorttitle="Bear Warning", pyramiding=0,⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length | 50 | int · min 1 | mom |
| Source | close | source | mom |
| Band Upper (no label in the script) | 5 | int | Upper Band Long1 |
| Band Lower (no label in the script) | -5 | int | Lower Band Short1 |
| Show Vix Fix (no label in the script) | true | bool | Upper Band Lower Band VIXFix |
| Show Momentum (no label in the script) | true | bool | MOM MOM Zero line ATR |
| VIX Fix Length | 22 | int | VIXFix |
What it calculates
- ATR (
atr,ta.atrin v5)14myAtr · line 25 - Highest (
highest,ta.highestin v5)close, VIX Fix Length (22)VIXFix · line 32 - Crossover (
crossover,ta.crossoverin v5)mom, VIXFixLong2 · line 48 - Crossunder (
crossunder,ta.crossunderin v5)mom, VIXFixShort2 · line 49
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open SELL short | Short1mom < bandLower | On | 55 |
| Close SELL | Long2 | On | 57 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Sell SPY | alertcondition | Warning Selling off {{ticker}}, price= {{close}} | 52 |
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| S&P Bear Warning Indicator this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Choppiness Index by Zeal Terminal | atr highest | v5 indicator | indicator | ||
| Aggresive Scalper-Swing Crypto Strategy by exlux99 | highest atr | v4 strategy | −7.4% | 3 | 16.0% |
| Donchian Channels Strategy by KrisWaters by kriswaters | highest atr | v4 strategy | +55.8% | 21 | 23.3% |
| Chandelier Exit - Strategy by melihtuna | atr highest | v4 strategy | −34.8% | 11 | 43.2% |
| ETF trader by FX_minds | atr highest | v4 strategy | +78.3% | 17 | 32.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 16 ms | With a workaround 1,000 bars in 40 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 55) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © gary_trades//THIS SCRIPT HAS BEEN BUIL TO BE USED AS A S&P500 SPY CRASH INDICATOR (should not be used as a strategy).//THIS SCRIPT HAS BEEN BUILT AS A STRATEGY FOR VISUALIZATION PURPOSES ONLY AND HAS NOT BEEN OPTIMISED FOR PROFIT.//The script has been built to show as a lower indicator and also gives visual SELL signal on top when conditions are met. BARE IN MIND NO STOP LOSS, NOR ADVANCED EXIT STRATEGY HAS BEEN BUILT.//As well as the chart SELL signal an alert has also been built into this script.//The script utilizes a VIX indicator (marron line) and 50 period Momentum (blue line) and Danger/No trade zone(pink shading).//When the Momentum line crosses down across the VIX this is a sell off but in order to only signal major sell offs the SELL signal only triggers if the momentum continues down through the danger zone.//To use this indicator to identify ideal buying then you should only buy when Momentum line is crossed above the VIX and the Momentum line is above the Danger Zone. //This is best used as a daily time frame indicator//@version=4strategy(title="S&P Bear Warning", shorttitle="Bear Warning", pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, commission_value=0.1)//Momentumlen = input(50, minval=1, title="Length")src = input(close, title="Source")bandUpper = input( 5)bandLower = input(-5)// ————— Control plotting of each signal. You could use the same technique to be able to turn acc/dist on/off.showVixFix = input(true)showMomentum = input(true) mom = src - src[len]myAtr = atr(14)plot(showMomentum ? mom : na, color=color.blue, title="MOM")plot(showMomentum ? 0 : na, color=color.silver, title="MOM Zero line", style=plot.style_circles, transp=100)plot(showMomentum ? myAtr : na, color=color.orange, title="ATR", transp=90) //VIXVIXFixLength = input(22,title="VIX Fix Length")VIXFix = (highest(close,VIXFixLength)-low)/(highest(close,VIXFixLength))*100plot(showVixFix ? VIXFix : na, "VIXFix", color=color.maroon) band1 = plot(showVixFix ? bandUpper : na, "Upper Band", color.red, 1, plot.style_line, transp=90)band0 = plot(showVixFix ? bandLower : na, "Lower Band", color.red, 1, plot.style_line, transp=90) fill(band1, band0, color=color.red, transp=85, title="Background") //Identify Triggers//Back Test Rangestart = timestamp("America/New_York", 2000, 1, 1, 9,30)end = timestamp("America/New_York", 2020, 7, 1, 0, 0)//Momentum Long1 = mom > bandUpperShort1 = mom < bandLower //VIXLong2 = crossover(mom, VIXFix)Short2 = crossunder(mom, VIXFix)//Warning AlertSellAlert = Short1alertcondition(SellAlert, title="Sell SPY", message="Warning Selling off {{ticker}}, price= {{close}}") //Entry and Exitif time >= start and time <= end strategy.entry("SELL", false, when = Short1) strategy.close("SELL", when = Long2)