Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Strategy Timeframe

A Pine Script v4 strategy built on Crossover or SMA (close, 14, close, 28) and Crossunder or SMA (close, 14, close, 28). 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 is one contract and pays no commission. 6 settings; defaults include From Month 1, From Day 1 and From Year 2020.

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

BTCUSDT · 1D · default settings

  • Crossover
  • Crossunder
  • 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 (6)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$80,755$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
Net profit
−16.79%
−$16,790.50
Buy and hold
+102.5%
same period
Closed trades
42
13 won · 29 lost
Profitable
31.0%
of closed trades
Profit factor
0.89
gross profit ÷ gross loss
Max drawdown
52.85%
−$54,413.30

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short 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.

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 crossover → ta.crossover, sma → ta.sma, crossunder → ta.crossunder.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 16: crossover → ta.crossover
  • Line 16: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 19: crossunder → ta.crossunder
  • Line 19: sma → ta.sma
  • Line 19: sma → ta.sma
⋯// © melihtuna-//@version=4+//@version=5strategy("Strategy Timeframe", overlay=true)⋯window()  => time >= start and time <= finish ? true : false -longCondition = crossover(sma(close, 14), sma(close, 28))+longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))if (window() and longCondition)    strategy.entry("My Long Entry Id", strategy.long)-shortCondition = crossunder(sma(close, 14), sma(close, 28))+shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))if (window() and shortCondition)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
⋯// === INPUT BACKTEST RANGE ===-FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+FromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+FromDay   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-FromYear  = input(defval = 2020, title = "From Year", minval = 2017)+FromYear  = input.int(defval = 2020, title = "From Year", minval = 2017)-ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+ToMonth   = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+ToDay     = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-ToYear    = input(defval = 9999, title = "To Year", minval = 2017)+ToYear    = input.int(defval = 9999, title = "To Year", minval = 2017)// === FUNCTION EXAMPLE ===⋯

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: 42 before, 31 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.

⋯// © melihtuna-//@version=5+//@version=6strategy("Strategy Timeframe", overlay=true)⋯

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 · min 1 · max 12start
From Day1int · min 1 · max 31start
From Year2020int · min 2017start
To Month1int · min 1 · max 12finish
To Day1int · min 1 · max 31finish
To Year9999int · min 2017finish

What it calculates

  • Crossover / SMA (crossover, ta.crossover in v5)sma(close, 14), sma(close, 28)longCondition · line 16
  • Crossunder / SMA (crossunder, ta.crossunder in v5)sma(close, 14), sma(close, 28)shortCondition · line 19

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 dataFromYearFrom Yearsetting · 2020FromMonthFrom Monthsetting · 1FromDayFrom Daysetting · 1ToYearTo Yearsetting · 9999ToMonthTo Monthsetting · 1ToDayTo Daysetting · 1longConditionCrossover / SMA→ longConditionshortConditionCrossunder / SMA→ shortConditionstartstartvaluefinishfinishvalueentry:My Long Entry IdOpen My Long Entry Idstrategy.entryentry:My Short Entry IdOpen My Short Entry Idstrategy.entry

Order rules

OrderFires whenBy defaultLine
Open My Long Entry Id long(window() and longCondition)On18
Open My Short Entry Id short(window() and shortCondition)On21

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.

11/11trades 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−16.8%+102.5%4231%0.8952.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−12.1%+5.5%4527%0.7319.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.8%+9.8%3842%1.332.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%4730%0.950.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.3%+16.7%3259%3.110.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.1%+21.5%4141%2.040.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%3625%1.021.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.2%+17.1%4330%0.550.3%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 market1443%$11,975.10
Sideways market1828%−$5,807.41
Falling market1020%−$22,958.20

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

How bad could the drawdown be?

70.3%

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

0%81%
All 42 trades
SideEntryExitBarsP&L
short29 Mar 2024 70,780.606 Apr 2024 67,820.608$2,959.97
long6 Apr 2024 67,820.6016 Apr 2024 63,420.0010−$4,400.64
short16 Apr 2024 63,420.0019 May 2024 66,915.2033−$3,495.21
long19 May 2024 66,915.2017 Jun 2024 66,676.9029−$238.34
short17 Jun 2024 66,676.9021 Jul 2024 67,140.0034−$463.11
long21 Jul 2024 67,140.008 Aug 2024 55,133.8018−$12,006.20
short8 Aug 2024 55,133.8027 Aug 2024 62,834.0019−$7,700.24
long27 Aug 2024 62,834.007 Sep 2024 53,963.0011−$8,871.03
short7 Sep 2024 53,963.0022 Sep 2024 63,349.0015−$9,386.00
long22 Sep 2024 63,349.0012 Oct 2024 62,540.0020−$808.98
short12 Oct 2024 62,540.0018 Oct 2024 67,421.806−$4,881.79
long18 Oct 2024 67,421.8030 Dec 2024 93,738.2073$26,316.40
short30 Dec 2024 93,738.2015 Jan 2025 96,560.9016−$2,822.66
long15 Jan 2025 96,560.908 Feb 2025 96,506.8024−$54.05
short8 Feb 2025 96,506.8031 Mar 2025 82,390.0051$14,116.80
long31 Mar 2025 82,390.008 Apr 2025 79,163.208−$3,226.76
short8 Apr 2025 79,163.2022 Apr 2025 87,516.2014−$8,352.98
long22 Apr 2025 87,516.209 Jun 2025 105,734.0048$18,217.80
short9 Jun 2025 105,734.0020 Jun 2025 104,659.0011$1,075.42
long20 Jun 2025 104,659.0024 Jun 2025 105,334.004$675.35
short24 Jun 2025 105,334.005 Jul 2025 107,984.0011−$2,650.31
long5 Jul 2025 107,984.006 Aug 2025 114,130.0032$6,145.50
short6 Aug 2025 114,130.0017 Aug 2025 117,381.0011−$3,250.91
long17 Aug 2025 117,381.0027 Aug 2025 111,763.0010−$5,617.44
short27 Aug 2025 111,763.0015 Sep 2025 115,268.0019−$3,504.79
long15 Sep 2025 115,268.001 Oct 2025 114,049.0016−$1,219.07
short1 Oct 2025 114,049.006 Oct 2025 123,482.005−$9,433.38
long6 Oct 2025 123,482.0020 Oct 2025 108,643.0014−$14,839.60
short20 Oct 2025 108,643.0011 Dec 2025 92,015.4052$16,627.40
long11 Dec 2025 92,015.4020 Dec 2025 88,136.909−$3,878.43
short20 Dec 2025 88,136.907 Jan 2026 93,748.0018−$5,611.02
long7 Jan 2026 93,748.0029 Jan 2026 89,300.0022−$4,447.97
short29 Jan 2026 89,300.0010 Mar 2026 68,432.2040$20,867.80
long10 Mar 2026 68,432.2031 Mar 2026 66,797.4021−$1,634.78
short31 Mar 2026 66,797.4014 Apr 2026 74,418.0014−$7,620.62
long14 Apr 2026 74,418.0024 May 2026 76,752.0040$2,334.00
short24 May 2026 76,752.0014 Jul 2026 62,334.5051$14,417.50
long14 Jul 2026 62,334.505 Aug 2026 64,106.6022$1,772.03
short5 Aug 2026 64,106.6020 Aug 2026 69,334.8015−$5,228.23
long20 Aug 2026 69,334.8018 Sep 2026 76,417.0029$7,082.23
short18 Sep 2026 76,417.0023 Sep 2026 86,208.605−$9,791.56
long23 Sep 2026 86,208.6016 Oct 2026 82,245.9023−$3,962.64

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
Strategy Timeframe this page—v4 strategy−16.8%4252.8%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 6 msYes 1,000 bars in 22 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/// © melihtuna//@version=4strategy("Strategy Timeframe", overlay=true)// === INPUT BACKTEST RANGE ===FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)FromYear  = input(defval = 2020, title = "From Year", minval = 2017)ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)ToYear    = input(defval = 9999, title = "To Year", minval = 2017)// === FUNCTION EXAMPLE ===start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        window()  => time >= start and time <= finish ? true : false longCondition = crossover(sma(close, 14), sma(close, 28))if (window() and longCondition)    strategy.entry("My Long Entry Id", strategy.long)shortCondition = crossunder(sma(close, 14), sma(close, 28))if (window() and shortCondition)    strategy.entry("My Short Entry Id", strategy.short)