Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[LunaOwl] Support Resistance Strategy V4

A Pine Script v4 strategy built on Valuewhen or Cross or SMA or Highest (high, LB), Valuewhen or Cross or SMA or Lowest (low, LB) and Crossover (close, R). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.05% commission. 2 settings; defaults include 回溯期數 50.

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 [LunaOwl] Support Resistance Strategy V4 repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did [LunaOwl] Support Resistance Strategy V4 do on BTCUSDT 1D with default settings?
−1.28%
From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [LunaOwl] Support Resistance Strategy V4 be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does [LunaOwl] Support Resistance Strategy V4 use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does [LunaOwl] Support Resistance Strategy V4 run in Zeal Terminal?
Yes
It compiles in 8 ms and runs 1,000 bars in 24 ms, in the browser.

BTCUSDT · 1D · default settings

  • 壓力
  • 支撐
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$12,062$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
−1.28%
−$128.17
Buy and hold
+102.5%
same period
Closed trades
7
3 won · 4 lost
Profitable
42.9%
of closed trades
Profit factor
0.98
gross profit ÷ gross loss
Max drawdown
25.50%
−$3,170.27

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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

    Uses an argument v6 removed

    when = on line 50, 51. The upgraded version below moves each call inside an if block.

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 valuewhen → ta.valuewhen, cross → ta.cross, sma → ta.sma, highest → ta.highest, lowest → ta.lowest, crossover → ta.crossover, crossunder → ta.crossunder.
  • 2 strategy calls use the when = argument (line 50, 51). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 5: //@version=4 → //@version=5
  • Line 37: input(type = input.integer) → input.int()
  • Line 38: input(type = input.bool) → input.bool()
  • Line 40: valuewhen → ta.valuewhen
  • Line 40: cross → ta.cross
  • Line 40: sma → ta.sma
7 more edits
  • Line 40: highest → ta.highest
  • Line 41: valuewhen → ta.valuewhen
  • Line 41: cross → ta.cross
  • Line 41: sma → ta.sma
  • Line 41: lowest → ta.lowest
  • Line 45: crossover → ta.crossover
  • Line 46: crossunder → ta.crossunder
⋯//-//@version=4+//@version=5//⋯//==設定輸入==//-LB = input(50, title = "回溯期數", type = input.integer)+LB = input.int(50, title = "回溯期數")-button = input(true, title = "請問要繪製K線麼?", type = input.bool)+button = input.bool(true, title = "請問要繪製K線麼?")//==支撐壓力線==//-R = valuewhen(cross(sma(close, LB),close), highest(high, LB), 1)+R = ta.valuewhen(ta.cross(ta.sma(close, LB),close), ta.highest(high, LB), 1)-S = valuewhen(cross(close,sma(close, LB)),  lowest( low, LB), 1)+S = ta.valuewhen(ta.cross(close,ta.sma(close, LB)),  ta.lowest( low, LB), 1)plot(R, title = "壓力", color = color.green)⋯//==定義輸出結果==//-Trend_up = crossover(close, R) ? 1 : 0+Trend_up = ta.crossover(close, R) ? 1 : 0-Trend_dn = crossunder(close, S) ? -1 : 0+Trend_dn = ta.crossunder(close, S) ? -1 : 0//==設定出場規則==//⋯

Clean v5

VerifiedDownload the v5 script

Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 50: when = Enter → if block
  • Line 51: when = Exit → if block
⋯Exit  = Trend_dn == -1 and Trend_dn[1] == 0 ? Trend_dn : na-strategy.entry("多", strategy.long, when = Enter)+if Enter+    strategy.entry("多", strategy.long)-strategy.entry("空", strategy.short, when = Exit)+if Exit+    strategy.entry("空", strategy.short)//==繪製燭台==//⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 7 before, 19 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯//-//@version=5+//@version=6//⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
回溯期數50int (written input.integer)R S
請問要繪製K線麼?truebool燭台顏色

What it calculates

  • Valuewhen / Cross / SMA / Highest (valuewhen, ta.valuewhen in v5)cross(sma(close, LB),close), highest(high, LB), 1R · line 40
  • Valuewhen / Cross / SMA / Lowest (valuewhen, ta.valuewhen in v5)cross(close,sma(close, LB)), lowest( low, LB), 1S · line 41
  • Crossover (crossover, ta.crossover in v5)close, RTrend_up · line 45
  • Crossunder (crossunder, ta.crossunder in v5)close, STrend_dn · line 46

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.

highhighprice dataclosecloseprice dataLB回溯期數setting · 50lowlowprice dataRValuewhen / Cross / SMA…→ RSValuewhen / Cross / SMA…→ STrend_upCrossover→ Trend_upTrend_dnCrossunder→ Trend_dnEnterEntervalueExitExitvalueTrend_colColourTrend_colentry:多Open 多strategy.entryentry:空Open 空strategy.entryplot:42壓力plotplot:43支撐plotbarcolor:54燭台顏色barcolor

Order rules

OrderFires whenBy defaultLine
Open 多 longEnterOn50
Open 空 shortExitOn51

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−1.3%+102.5%743%0.9825.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.1%+5.5%743%0.9913.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.6%+9.8%743%0.9961.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−19.9%+8.4%838%0.5830.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+4.8%+16.7%450%1.1633.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+15.7%+21.5%650%1.6216.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−55.1%+148.3%825%0.2758.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+12.6%+17.1%450%1.9115.2%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market0—$0.00
Sideways market560%$4,077.22
Falling market20%−$4,200.45

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

43.5%

The 95th percentile of the worst drawdown when the same 7 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 21.8% to 43.5%; the tick is what actually happened, 23.7%. Order luck alone moves it this much.

0%50%
All 7 trades
SideEntryExitBarsP&L
short8 Jul 2024 55,857.8016 Oct 2024 67,074.20100−$2,018.03
long16 Oct 2024 67,074.2026 Feb 2025 88,680.30133$2,562.56
short26 Feb 2025 88,680.3029 Apr 2025 95,011.2062−$763.70
long29 Apr 2025 95,011.205 Nov 2025 101,497.00190$657.63
short5 Nov 2025 101,497.0018 Apr 2026 77,072.10164$2,502.82
long18 Apr 2026 77,072.104 Jun 2026 64,142.7047−$2,182.42
short4 Jun 2026 64,142.7020 Aug 2026 69,334.8077−$882.09

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
[LunaOwl] Support Resistance Strategy V4 this page—v4 strategy−1.3%725.5%
Trend Bounce [racer8] by racer8highest lowest sma valuewhenv4 strategy+2.4%2232.2%
TradeIQ - Crazy Scalping Trading Strategy [Kaspricci] by Kaspriccihighest lowest valuewhen sma crossv5 strategy+1,326.3%61,046.4%
Chandelier + BB + EMAS by juanchezhighest lowest sma crossv4 strategy−20.6%1038.6%
TradingGroundhog - Strategy & Fractal V1 by UnknownUnicorn27666852highest lowest valuewhen smav4 strategy−2.9%85.9%
CITI Moku Strategy(Free) by @MiaIsTheNewBird by CITIAlgocross highest lowest valuewhenv5 strategy−8.7%4816.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 8 msYes 1,000 bars in 24 msNot measured
PineTSNo v5 and v6 only—Not measured

“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//-- 開源代碼受Mozilla公眾授權條款2.0版規範, 網址是https://mozilla.org/MPL/2.0/////@version=4////  作品: [LunaOwl] 支撐壓力策略第4版//  英文: [LunaOwl] Support Resistance Strategy V4////////////////////////////////////     ~~!!*(๑╹◡╹๑) **       ////  製作:  @LunaOwl 彭彭      ////  日期:  2019年03月05日     ////  修改:  2019年04月22日     ////  四版:  2020年06月16日     ////  發表:  2020年06月17日     //////////////////////////////////////一個簡單的支撐阻力突破策略,唯一的差異在於它是PineScript第四版//#_____________________________//==設定策略==//strategy("[LunaOwl] 支撐壓力策略 [回測]",     shorttitle          = "支撐壓力策略 [回測]",     overlay             = true,     calc_on_order_fills = false,     calc_on_every_tick  = false,     pyramiding          = 0,     currency            = currency.NONE,     initial_capital     = 10000,     slippage            = 5,     default_qty_value   = 100,     default_qty_type    = strategy.percent_of_equity,     commission_type     = strategy.commission.percent,     commission_value    = 0.05     )//==設定輸入==//LB = input(50, title = "回溯期數", type = input.integer)button = input(true, title = "請問要繪製K線麼?", type = input.bool)//==支撐壓力線==//R = valuewhen(cross(sma(close, LB),close), highest(high, LB), 1)S = valuewhen(cross(close,sma(close, LB)),  lowest( low, LB), 1)plot(R, title = "壓力", color = color.green)plot(S, title = "支撐", color = color.red)//==定義輸出結果==//Trend_up = crossover(close, R) ? 1 : 0Trend_dn = crossunder(close, S) ? -1 : 0//==設定出場規則==//Enter = Trend_up ==  1 and Trend_up[1] == 0 ? Trend_up : naExit  = Trend_dn == -1 and Trend_dn[1] == 0 ? Trend_dn : nastrategy.entry("多", strategy.long, when = Enter)strategy.entry("空", strategy.short, when = Exit)//==繪製燭台==//Trend_col = R < close ? color.green : S > close ? color.red : color.orangebarcolor(not button ? na : Trend_col, editable = true, title = "燭台顏色")