Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Simple Buy-Sell Strategy

A Pine Script v4 strategy built on SAR (0.02, 0.02), SMA (close, 200) and MACD (close, 12). It has 4 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 is one contract and pays no commission. 8 settings; defaults include MA Length 200, Fast EMA Length 12 and Slow EMA Length 26.

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 Simple Buy-Sell Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Simple Buy-Sell Strategy do on BTCUSDT 1D with default settings?
+43.68%
From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Simple Buy-Sell Strategy 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 Simple Buy-Sell Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Simple Buy-Sell Strategy run in Zeal Terminal?
Yes
It compiles in 9 ms and runs 1,000 bars in 30 ms, in the browser.

BTCUSDT · 1D · default settings

  • Buy Signals
  • Sell Signals
  • 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 (8)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctBuy Signals$159,043$202,527Equity from $100,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
+43.68%
$43,677.10
Buy and hold
+102.5%
same period
Closed trades
6
3 won · 3 lost
Profitable
50.0%
of closed trades
Profit factor
2.91
gross profit ÷ gross loss
Max drawdown
15.49%
−$15,488.40

One run with the author's default settings, $100,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

    No commission

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

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

v4 → v5

Verified

Same 6 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: sar → ta.sar
  • Line 10: sma → ta.sma
  • Line 15: macd → ta.macd
  • Line 20: rsi → ta.rsi
⋯// © BlockchainSpecialists-//@version=4+//@version=5//Original Indicator by @Shizaru - simply made into a strategy!strategy("Simple Buy/Sell Strategy", overlay=false)-psar = sar(0.02,0.02,0.2)+psar = ta.sar(0.02,0.02,0.2)c1a = close > psar⋯malen = input(200, title="MA Length")-mm200 = sma(close, malen)+mm200 = ta.sma(close, malen)c2a = close > mm200⋯slow = input(26, title="Slow EMA Length")-[macd,signal,hist] = macd(close, fast,slow, 9)+[macd,signal,hist] = ta.macd(close, fast,slow, 9)c3a = macd >= 0⋯th = input(50, title="RSI Threshold")-rsi14 = rsi(close, rsilen)+rsi14 = ta.rsi(close, rsilen)c4a = rsi14 >= th⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 9: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 18: input() → input.int()
  • Line 19: input() → input.int()
  • Line 25: input() → input.bool()
6 more edits
  • Line 26: input() → input.bool()
  • Line 27: input() → input.bool()
  • Line 28: when = buy==1 and longtrades==true → if block
  • Line 29: when = quickexit==true ? buy==0 : sell==-1 → if block
  • Line 30: when = sell==-1 and shorttrades==true → if block
  • Line 31: when = quickexit==true ? sell==0 : buy==1 → if block
⋯c1v = close < psar-malen = input(200, title="MA Length")+malen = input.int(200, title="MA Length")mm200 = ta.sma(close, malen)⋯c2v = close < mm200-fast = input(12, title="Fast EMA Length")+fast = input.int(12, title="Fast EMA Length")-slow = input(26, title="Slow EMA Length")+slow = input.int(26, title="Slow EMA Length")[macd,signal,hist] = ta.macd(close, fast,slow, 9)⋯c3v = macd <= 0-rsilen = input(7, title="RSI Length")+rsilen = input.int(7, title="RSI Length")-th = input(50, title="RSI Threshold")+th = input.int(50, title="RSI Threshold")rsi14 = ta.rsi(close, rsilen)⋯sell = c1v and c2v and c3v and c4v ? -1 : 0-longtrades = input(true, title="Long Trades")+longtrades = input.bool(true, title="Long Trades")-shorttrades = input(true, title="Short Trades")+shorttrades = input.bool(true, title="Short Trades")-quickexit = input(false, title="Quick Exits")+quickexit = input.bool(false, title="Quick Exits")-strategy.entry("Buy", strategy.long, when=buy==1 and longtrades==true)+if buy==1 and longtrades==true+    strategy.entry("Buy", strategy.long)-strategy.close("Buy", when=quickexit==true ? buy==0 : sell==-1)+if quickexit==true ? buy==0 : sell==-1+    strategy.close("Buy")-strategy.entry("Sell", strategy.short, when=sell==-1 and shorttrades==true)+if sell==-1 and shorttrades==true+    strategy.entry("Sell", strategy.short)-strategy.close("Sell", when=quickexit==true ? sell==0 : buy==1)+if quickexit==true ? sell==0 : buy==1+    strategy.close("Sell")plot(buy, style=plot.style_histogram, color=color.green, linewidth=3, title="Buy Signals")⋯

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: 6 before, 9 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.

⋯// © BlockchainSpecialists-//@version=5+//@version=6//Original Indicator by @Shizaru - simply made into a strategy!⋯

Settings

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

SettingDefaultType and rangeFeeds
MA Length200intmm200
Fast EMA Length12intmacd signal hist
Slow EMA Length26intmacd signal hist
RSI Length7intrsi14
RSI Threshold50intc4a c4v
Long Tradestrueboolentry Buy
Short Tradestrueboolentry Sell
Quick Exitsfalseboolclose Buy close Sell

What it calculates

  • SAR (sar, ta.sar in v5)0.02, 0.02, 0.2psar · line 6
  • SMA (sma, ta.sma in v5)close, MA Length (200)mm200 · line 10
  • MACD (macd, ta.macd in v5)close, Fast EMA Length (12), Slow EMA Length (26), 9macd · line 15
  • MACD (macd, ta.macd in v5)close, Fast EMA Length (12), Slow EMA Length (26), 9signal · line 15
  • MACD (macd, ta.macd in v5)close, Fast EMA Length (12), Slow EMA Length (26), 9hist · line 15
  • RSI (rsi, ta.rsi in v5)close, RSI Length (7)rsi14 · line 20

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.

high · low · closehigh · low · closeprice dataclosecloseprice datamalenMA Lengthsetting · 200fastFast EMA Lengthsetting · 12slowSlow EMA Lengthsetting · 26rsilenRSI Lengthsetting · 7thRSI Thresholdsetting · 50psarSAR→ psarmm200SMA→ mm200macdMACD→ macdsignalMACD→ signalhistMACD→ histrsi14RSI→ rsi14buybuyvaluesellsellvaluec1a, c1vc1a · c1v2 conditionsc2a, c2vc2a · c2v2 conditionsc3a, c3vc3a · c3v2 conditionsc4a, c4vc4a · c4v2 conditionsentry:BuyOpen Buystrategy.entryclose:BuyClose Buystrategy.closeentry:SellOpen Sellstrategy.entryclose:SellClose Sellstrategy.closeplot:32Buy Signalsplotplot:33Sell Signalsplot

Order rules

OrderFires whenBy defaultLine
Open Buy longbuy==1 and longtrades==trueOn28
Close Buyquickexit==true ? buy==0 : sell==-1On29
Open Sell shortsell==-1 and shorttrades==trueOn30
Close Sellquickexit==true ? sell==0 : buy==1On31

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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+43.7%+102.5%650%2.9115.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−4.0%+5.5%1513%0.8111.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.4%+9.8%743%1.261.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.7%+8.4%450%7.290.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%933%0.970.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%1020%1.760.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.2%+148.3%1613%0.710.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%1217%1.450.1%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%$56,385.60
Falling market10%−$12,708.50

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

How bad could the drawdown be?

20.9%

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

0%24%
All 6 trades
SideEntryExitBarsP&L
long25 Aug 2024 64,157.0031 Aug 2024 59,124.006−$5,033.03
short31 Aug 2024 59,124.0025 Sep 2024 64,262.7025−$5,138.71
long25 Sep 2024 64,262.7010 Mar 2025 80,734.50166$16,471.80
short10 Mar 2025 80,734.5023 Apr 2025 93,443.0044−$12,708.50
long23 Apr 2025 93,443.0018 Oct 2025 106,432.00178$12,988.70
short18 Oct 2025 106,432.0020 Aug 2026 69,334.80306$37,096.90

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
Simple Buy-Sell Strategy this page—v4 strategy+43.7%615.5%
[VJ]Phoenix Force of PSAR +MACD +RSI by vikrissar sma macd rsiv4 strategyNo trades on this market
PowerX by jwitt98 by jwitt98rsi sma macdv5 strategy+107.9%78107.8%
PSAR + EMA-TEMA-RSI-OBV by UnknownUnicorn19826629sar rsi smav4 strategyNo trades on this market
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%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 9 msYes 1,000 bars in 30 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 at https://mozilla.org/MPL/2.0/// © BlockchainSpecialists//@version=4//Original Indicator by @Shizaru - simply made into a strategy!strategy("Simple Buy/Sell Strategy", overlay=false)psar = sar(0.02,0.02,0.2)c1a = close > psarc1v = close < psarmalen = input(200, title="MA Length")mm200 = sma(close, malen)c2a = close > mm200c2v = close < mm200fast = input(12, title="Fast EMA Length")slow = input(26, title="Slow EMA Length")[macd,signal,hist] = macd(close, fast,slow, 9)c3a = macd >= 0c3v = macd <= 0rsilen = input(7, title="RSI Length")th = input(50, title="RSI Threshold")rsi14 = rsi(close, rsilen)c4a = rsi14 >= thc4v = rsi14 <= thbuy = c1a and c2a and c3a and c4a ? 1 : 0sell = c1v and c2v and c3v and c4v ? -1 : 0longtrades = input(true, title="Long Trades")shorttrades = input(true, title="Short Trades")quickexit = input(false, title="Quick Exits")strategy.entry("Buy", strategy.long, when=buy==1 and longtrades==true)strategy.close("Buy", when=quickexit==true ? buy==0 : sell==-1)strategy.entry("Sell", strategy.short, when=sell==-1 and shorttrades==true)strategy.close("Sell", when=quickexit==true ? sell==0 : buy==1)plot(buy, style=plot.style_histogram, color=color.green, linewidth=3, title="Buy Signals")plot(sell, style=plot.style_histogram, color=color.red, linewidth=3, title="Sell Signals")