Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Short In Downtrend Below MA100 (Coinrule)

A Pine Script v4 strategy built on SMA (close, 50) and RSI (close, 14). 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 no commission. 9 settings; defaults include From Month 1, From Day 10 and From Year 2019.

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 Short In Downtrend Below MA100 (Coinrule) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 25 of 25 trades.
How did Short In Downtrend Below MA100 (Coinrule) do on BTCUSDT 1D with default settings?
−34.49%
From 26 Jan 2024 to 21 Oct 2026, over 99 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Short In Downtrend Below MA100 (Coinrule) 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 Short In Downtrend Below MA100 (Coinrule) use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Short In Downtrend Below MA100 (Coinrule) run in Zeal Terminal?
Yes
It compiles in 7 ms and runs 1,000 bars in 33 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • 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 (9)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$655$2,025Equity from $1,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. Zeal Terminal's engine currently reads an order side written as long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 23) 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.
Net profit
−34.49%
−$344.88
Buy and hold
+102.5%
same period
Closed trades
99
53 won · 46 lost
Profitable
53.5%
of closed trades
Profit factor
0.81
gross profit ÷ gross loss
Max drawdown
45.40%
−$495.68

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

    1 setting does nothing

    “Show Date Range” is declared but never read.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • 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 23, 27. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 23

    long = on line 23. v5 writes it as direction = strategy.long or strategy.short.

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 sma → ta.sma, rsi → ta.rsi.
  • 2 strategy calls use the when = argument (line 23, 27). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.integer) → input.int()
  • Line 7: input(type = input.integer) → input.int()
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.integer) → input.int()
  • Line 10: input(type = input.integer) → input.int()
5 more edits
  • Line 11: input(type = input.integer) → input.int()
  • Line 12: input(type = input.bool) → input.bool()
  • Line 18: sma → ta.sma
  • Line 21: rsi → ta.rsi
  • Line 23: long = false → direction = strategy.short
⋯// © Coinrule-//@version=4+//@version=5strategy(shorttitle='Short In Downtrend',title='Short In Downtrend Below MA100', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)//Backtest dates-fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)+fromMonth = input.int(defval = 1,    title = "From Month", minval = 1, maxval = 12)-fromDay   = input(defval = 10,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)+fromDay   = input.int(defval = 10,    title = "From Day", minval = 1, maxval = 31)-fromYear  = input(defval = 2019, title = "From Year",       type = input.integer, minval = 1970)+fromYear  = input.int(defval = 2019, title = "From Year", minval = 1970)-thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)+thruMonth = input.int(defval = 1,    title = "Thru Month", minval = 1, maxval = 12)-thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)+thruDay   = input.int(defval = 1,    title = "Thru Day", minval = 1, maxval = 31)-thruYear  = input(defval = 2112, title = "Thru Year",       type = input.integer, minval = 1970)+thruYear  = input.int(defval = 2112, title = "Thru Year", minval = 1970)-showDate  = input(defval = true, title = "Show Date Range", type = input.bool)+showDate  = input.bool(defval = true, title = "Show Date Range")start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window⋯inSignal=input(50, title='MASignal')-MA= sma(close, inSignal)+MA= ta.sma(close, inSignal)// RSI inputs and calculationslengthRSI = input(14, title = 'RSI period', minval=1)-RSI = rsi(close, lengthRSI)+RSI = ta.rsi(close, lengthRSI)//Entry -strategy.entry(id="short", long = false, when = close < MA and RSI > 30)+strategy.entry(id="short", direction = strategy.short, when = close < MA and RSI > 30)//Exit⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 17: input() → input.int()
  • Line 20: input() → input.int()
  • Line 23: when = close < MA and RSI > 30 → if block
  • Line 27: when = close > shortStopPrice or close < shortTakeProfit and window() → if block
⋯//MA inputs and calculations-inSignal=input(50, title='MASignal')+inSignal=input.int(50, title='MASignal')MA= ta.sma(close, inSignal)// RSI inputs and calculations-lengthRSI = input(14, title = 'RSI period', minval=1)+lengthRSI = input.int(14, title = 'RSI period', minval=1)RSI = ta.rsi(close, lengthRSI)//Entry -strategy.entry(id="short", direction = strategy.short, when = close < MA and RSI > 30)+if close < MA and RSI > 30+    strategy.entry(id="short", direction = strategy.short)//Exit⋯shortTakeProfit = strategy.position_avg_price * (1 - 0.02)-strategy.close("short", when = close > shortStopPrice or close < shortTakeProfit and window())+if close > shortStopPrice or close < shortTakeProfit and window()+    strategy.close("short")plot(MA, color=color.purple, linewidth=2)

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: 99 before, 393 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.

⋯// © Coinrule-//@version=5+//@version=6strategy(shorttitle='Short In Downtrend',title='Short In Downtrend Below MA100', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)⋯

Settings

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

SettingDefaultType and rangeFeeds
From Month1int (written input.integer) · min 1 · max 12start
From Day10int (written input.integer) · min 1 · max 31start
From Year2019int (written input.integer) · min 1970start
Thru Month1int (written input.integer) · min 1 · max 12finish
Thru Day1int (written input.integer) · min 1 · max 31finish
Thru Year2112int (written input.integer) · min 1970finish
Show Date Rangetrueboolunused
MASignal50intMA
RSI period14int · min 1RSI

What it calculates

  • SMA (sma, ta.sma in v5)close, MASignal (50)MA · line 18
  • RSI (rsi, ta.rsi in v5)close, RSI period (14)RSI · line 21

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.

closecloseprice datainSignalMASignalsetting · 50lengthRSIRSI periodsetting · 14fromYearFrom Yearsetting · 2019fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 10thruYearThru Yearsetting · 2112thruMonthThru Monthsetting · 1thruDayThru Daysetting · 1MASMA→ MARSIRSI→ RSIstartstartvaluefinishfinishvalueshortStopPrice, shortTakeProfitshortStopPrice · shortT…2 valuesentry:shortOpen shortstrategy.entryclose:shortClose shortstrategy.closeplot:28plotplot

Order rules

OrderFires whenBy defaultLine
Open short shortclose < MA and RSI > 30On23
Close shortclose > shortStopPrice or close < shortTakeProfit and window()On27

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.

25/25trades 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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−34.5%+102.5%9954%0.8145.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−12.5%+5.5%2250%0.7327.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−27.8%+9.8%13556%0.9049.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−16.0%+8.4%3757%0.7834.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+14.2%+16.7%16757%1.0347.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.8%+21.5%5159%0.9928.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−15.6%+148.3%10155%0.9230.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−6.8%+17.1%3453%0.8825.5%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 market1747%−$171.83
Sideways market4657%−$51.06
Falling market3653%−$121.98

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

How bad could the drawdown be?

60.1%

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

0%69%
All 99 trades
SideEntryExitBarsP&L
short13 Apr 2024 63,924.5017 Apr 2024 61,277.404$41.41
short18 Apr 2024 63,470.1022 Apr 2024 66,819.304−$54.95
short23 Apr 2024 66,414.0024 Apr 2024 64,289.601$31.55
short25 Apr 2024 64,498.3028 Apr 2024 63,118.603$21.78
short29 Apr 2024 63,866.0030 Apr 2024 60,672.001$52.00
short1 May 2024 58,365.003 May 2024 62,882.002−$84.50
short4 May 2024 63,892.007 May 2024 62,312.103$24.91
short8 May 2024 61,193.009 May 2024 63,074.001−$31.73
short10 May 2024 60,800.0013 May 2024 62,940.103−$35.22
short14 May 2024 61,577.5015 May 2024 66,206.501−$72.56
short18 Jun 2024 65,175.3023 Jun 2024 63,210.005$26.92
short25 Jun 2024 61,806.0028 Jun 2024 60,427.803$20.51
short29 Jun 2024 60,986.701 Jul 2024 62,900.002−$29.49
short2 Jul 2024 62,135.503 Jul 2024 60,208.601$28.24
short6 Jul 2024 58,230.107 Jul 2024 55,857.801$38.25
short8 Jul 2024 56,714.6013 Jul 2024 59,204.005−$42.89
short14 Jul 2024 60,797.9015 Jul 2024 64,724.101−$60.33
short2 Aug 2024 61,498.304 Aug 2024 58,161.002$47.42
short6 Aug 2024 56,022.008 Aug 2024 61,686.002−$93.15
short9 Aug 2024 60,838.0011 Aug 2024 58,712.602$28.93
short12 Aug 2024 59,346.6015 Aug 2024 57,541.103$26.08
short16 Aug 2024 58,874.6021 Aug 2024 61,156.005−$34.22
short22 Aug 2024 60,375.8023 Aug 2024 64,037.201−$51.48
short27 Aug 2024 59,415.001 Sep 2024 57,301.905$28.36
short2 Sep 2024 59,132.103 Sep 2024 57,487.701$22.97
short4 Sep 2024 57,970.905 Sep 2024 56,180.001$26.22
short6 Sep 2024 53,963.009 Sep 2024 57,042.003−$49.93
short10 Sep 2024 57,636.0013 Sep 2024 60,498.003−$40.97
short15 Sep 2024 59,132.0018 Sep 2024 61,760.003−$34.85
short9 Oct 2024 60,636.0011 Oct 2024 62,540.002−$23.53
short27 Dec 2024 94,299.003 Jan 2025 98,174.207−$29.82
short7 Jan 2025 96,954.609 Jan 2025 92,552.502$31.60
short10 Jan 2025 94,726.1015 Jan 2025 100,497.005−$44.32
short2 Feb 2025 97,700.603 Feb 2025 101,329.001−$25.37
short4 Feb 2025 97,763.1011 Feb 2025 95,778.207$13.36
short12 Feb 2025 97,870.0017 Feb 2025 95,780.005$14.33
short18 Feb 2025 95,671.7024 Feb 2025 91,552.906$29.51
short1 Mar 2025 86,064.502 Mar 2025 94,270.001−$68.17
short3 Mar 2025 86,220.605 Mar 2025 90,606.002−$32.90
short6 Mar 2025 89,931.907 Mar 2025 86,801.801$21.37
short8 Mar 2025 86,222.409 Mar 2025 80,734.401$40.44
short10 Mar 2025 78,595.9011 Mar 2025 82,933.001−$37.29
short12 Mar 2025 83,680.1013 Mar 2025 81,115.801$19.57
short14 Mar 2025 83,983.2019 Mar 2025 86,845.905−$22.43
short20 Mar 2025 84,223.4024 Mar 2025 87,498.204−$24.71
short25 Mar 2025 87,392.9028 Mar 2025 84,424.403$20.75
short29 Mar 2025 82,648.501 Apr 2025 85,158.303−$19.18
short2 Apr 2025 82,516.306 Apr 2025 78,430.004$30.33
short7 Apr 2025 79,163.208 Apr 2025 76,322.401$23.07
short9 Apr 2025 82,615.2010 Apr 2025 79,607.301$24.24
short11 Apr 2025 83,423.8021 Apr 2025 87,516.2010−$33.85
short20 Jun 2025 103,298.0022 Jun 2025 100,964.002$14.83
short1 Jul 2025 105,681.003 Jul 2025 109,585.002−$24.79
short19 Aug 2025 112,873.0022 Aug 2025 116,936.003−$23.26
short23 Aug 2025 115,438.0025 Aug 2025 110,112.002$28.75
short26 Aug 2025 111,763.0029 Aug 2025 108,377.003$19.75
short30 Aug 2025 108,816.0010 Sep 2025 113,960.0011−$31.74
short22 Sep 2025 112,651.0025 Sep 2025 108,994.003$20.77
short26 Sep 2025 109,643.0029 Sep 2025 114,312.003−$28.13
short10 Oct 2025 112,775.0016 Oct 2025 108,194.006$25.68
short17 Oct 2025 106,432.0020 Oct 2025 110,532.003−$25.35
short21 Oct 2025 108,298.0025 Oct 2025 111,646.004−$19.56
short27 Oct 2025 114,108.0029 Oct 2025 110,021.002$21.96
short30 Oct 2025 108,323.004 Nov 2025 101,497.005$40.02
short5 Nov 2025 103,885.006 Nov 2025 101,346.001$16.50
short7 Nov 2025 103,339.0013 Nov 2025 99,692.006$24.41
short14 Nov 2025 94,594.0017 Nov 2025 92,215.103$18.01
short18 Nov 2025 92,960.8020 Nov 2025 86,637.202$49.94
short24 Nov 2025 88,300.0027 Nov 2025 91,333.903−$26.94
short28 Nov 2025 90,890.701 Dec 2025 86,286.003$38.36
short2 Dec 2025 91,277.905 Dec 2025 89,330.003$16.97
short6 Dec 2025 89,236.809 Dec 2025 92,678.803−$31.34
short10 Dec 2025 92,015.4014 Dec 2025 88,172.204$32.62
short15 Dec 2025 86,432.102 Jan 2026 89,995.1018−$33.54
short20 Jan 2026 88,427.7029 Jan 2026 84,650.209$33.33
short30 Jan 2026 84,260.5031 Jan 2026 78,741.101$53.29
short6 Feb 2026 70,580.3010 Feb 2026 68,841.304$21.36
short11 Feb 2026 67,082.5014 Feb 2026 69,822.903−$36.28
short15 Feb 2026 68,832.6018 Feb 2026 66,461.003$29.35
short19 Feb 2026 67,003.7023 Feb 2026 64,656.004$30.88
short24 Feb 2026 64,058.2025 Feb 2026 67,988.001−$55.95
short26 Feb 2026 67,485.2027 Feb 2026 65,872.101$20.46
short28 Feb 2026 66,973.304 Mar 2026 72,666.804−$74.52
short5 Mar 2026 70,890.706 Mar 2026 68,114.001$31.42
short7 Mar 2026 67,262.9010 Mar 2026 69,948.603−$33.28
short11 Mar 2026 70,191.9015 Mar 2026 72,815.204−$29.91
short19 Mar 2026 69,930.0022 Mar 2026 67,859.003$22.81
short26 Mar 2026 68,820.3027 Mar 2026 66,407.301$27.81
short28 Mar 2026 66,377.005 Apr 2026 69,034.208−$32.86
short22 May 2026 75,539.5028 May 2026 73,617.506$20.05
short29 May 2026 73,460.801 Jun 2026 71,408.903$22.57
short11 Jun 2026 63,626.0014 Jun 2026 65,746.403−$27.68
short15 Jun 2026 66,328.7017 Jun 2026 64,509.402$22.03
short18 Jun 2026 62,958.0024 Jun 2026 61,078.006$24.64
short25 Jun 2026 59,794.003 Jul 2026 62,583.308−$39.63
short4 Jul 2026 63,144.0014 Jul 2026 65,044.0010−$24.37
short16 Jul 2026 63,830.2021 Jul 2026 66,556.205−$33.55
short31 Jul 2026 62,887.907 Aug 2026 64,923.207−$24.34
short14 Aug 2026 63,043.6019 Aug 2026 69,334.805−$72.62

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
Short In Downtrend Below MA100 (Coinrule) this page—v4 strategy−34.5%9945.4%
SRJ RSI Outperformer Strategy by Sapt_Jashrsi smav5 strategy+0.6%82.4%
RSI SMA Crossover Strategy by reeesrsi smav5 strategy+39.8%4230.8%
Simple RSI and SMA Long and Short (by Coinrule) by Coinrulersi smav5 strategy−3.0%217.7%
Maximized Moving Average Crossing (by Coinrule) by Coinrulesma rsiv4 strategy−6.6%913.3%
RSI Mean Reversion Strategy by Zeal Terminalrsi smav5 strategy+2.2%161.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 7 msWith a workaround 1,000 bars in 33 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 23) 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/// © Coinrule//@version=4strategy(shorttitle='Short In Downtrend',title='Short In Downtrend Below MA100', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)//Backtest datesfromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)fromDay   = input(defval = 10,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)fromYear  = input(defval = 2019, title = "From Year",       type = input.integer, minval = 1970)thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)thruYear  = input(defval = 2112, title = "Thru Year",       type = input.integer, minval = 1970)showDate  = input(defval = true, title = "Show Date Range", type = input.bool)start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start windowfinish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish windowwindow()  => time >= start and time <= finish ? true : false       // create function "within window of time"//MA inputs and calculationsinSignal=input(50, title='MASignal')MA= sma(close, inSignal)// RSI inputs and calculationslengthRSI = input(14, title = 'RSI period', minval=1)RSI = rsi(close, lengthRSI)//Entry strategy.entry(id="short", long = false, when = close < MA and RSI > 30)//ExitshortStopPrice  = strategy.position_avg_price * (1 + 0.03)shortTakeProfit = strategy.position_avg_price * (1 - 0.02)strategy.close("short", when = close > shortStopPrice or close < shortTakeProfit and window())plot(MA, color=color.purple, linewidth=2)