Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

TEMA Cross +HTF Backtest

A Pine Script v4 strategy built on EMA (xPrice, 20). 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 commits 500 in cash and pays no commission. 12 settings; defaults include What type of Orders Longs+Shorts, From Month 1 and From Day 1.

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 TEMA Cross +HTF Backtest repaint?
Yes
At least one pattern in the source can repaint: higher-timeframe data.
How did TEMA Cross +HTF Backtest do on BTCUSDT 1D with default settings?
+82.59%
From 26 Jan 2024 to 21 Oct 2026, over 27 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can TEMA Cross +HTF Backtest 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 TEMA Cross +HTF Backtest use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does TEMA Cross +HTF Backtest run in Zeal Terminal?
Yes
It compiles in 31 ms and runs 1,000 bars in 189 ms, in the browser.

BTCUSDT · 1D · default settings

  • TEMA1
  • TEMA2
  • TEMA1
  • TEMA2
  • 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 (12)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$911$1,013Equity from $500
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
+82.59%
$412.96
Buy and hold
+102.5%
same period
Closed trades
27
13 won · 14 lost
Profitable
48.1%
of closed trades
Profit factor
1.90
gross profit ÷ gross loss
Max drawdown
42.98%
−$214.88

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

  • Note

    Uses an argument v6 removed

    when = on line 68, 69, 71, 72. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 38

    transp = on line 38, 48, 55, 57, 58, 59. 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 ema → ta.ema, security → request.security.
  • 4 strategy calls use the when = argument (line 68, 69, 71, 72). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 26: ema → ta.ema
  • Line 27: ema → ta.ema
  • Line 28: ema → ta.ema
  • Line 33: ema → ta.ema
  • Line 34: ema → ta.ema
15 more edits
  • Line 35: ema → ta.ema
  • Line 38: transp = 65 → color.new(xnRes > ynRes ? color.green : color.red, 65)
  • Line 40: input(type = input.resolution) → input.timeframe()
  • Line 41: security → request.security
  • Line 44: ema → ta.ema
  • Line 45: ema → ta.ema
  • Line 46: ema → ta.ema
  • Line 48: transp = 30 → color.new(color.yellow, 30)
  • Line 51: ema → ta.ema
  • Line 52: ema → ta.ema
  • Line 53: ema → ta.ema
  • Line 55: transp = 30 → color.new(color.purple, 30)
  • Line 57: transp = 90 → color.new(HTFxnRes > HTFynRes ? color.yellow : color.purple, 90)
  • Line 58: transp = 90 → color.new(HTFxnRes > HTFynRes ? color.yellow : na, 90)
  • Line 59: transp = 90 → color.new(HTFxnRes < HTFynRes ? color.purple : na, 90)
⋯// © Seltzer_-//@version=4+//@version=5strategy(title="TEMA Cross +HTF Backtest", shorttitle="TEMA_X_+HTF_BT", overlay=true, commission_type=strategy.commission.percent, commission_value=0, initial_capital = 500,  default_qty_type=strategy.cash, default_qty_value=500)⋯xPrice = close-xEMA1 = ema(xPrice, xLength)+xEMA1 = ta.ema(xPrice, xLength)-xEMA2 = ema(xEMA1, xLength)+xEMA2 = ta.ema(xEMA1, xLength)-xEMA3 = ema(xEMA2, xLength)+xEMA3 = ta.ema(xEMA2, xLength)xnRes = (3 * xEMA1) - (3 * xEMA2) + xEMA3⋯yPrice = close-yEMA1 = ema(yPrice, yLength)+yEMA1 = ta.ema(yPrice, yLength)-yEMA2 = ema(yEMA1, yLength)+yEMA2 = ta.ema(yEMA1, yLength)-yEMA3 = ema(yEMA2, yLength)+yEMA3 = ta.ema(yEMA2, yLength)ynRes = (3 * yEMA1) - (3 * yEMA2) + yEMA3ynResP = plot(ynRes, color=color.red, linewidth=2, title="TEMA2")-fill(xnResP, ynResP, color=xnRes > ynRes ? color.green : color.red, transp=65, editable=true)+fill(xnResP, ynResP, color=color.new(xnRes > ynRes ? color.green : color.red, 65), editable=true)//HTF Section-HTFres = input(defval="D", type=input.resolution, title="HTF Resolution")+HTFres = input.timeframe(defval="D", title="HTF Resolution")-f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)+f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)HTFxLength = input(5, minval=1, title="HTF Fast Length")HTFxPrice = close-HTFxEMA1 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFxPrice, HTFxLength))+HTFxEMA1 = f_secureSecurity(syminfo.tickerid, HTFres, ta.ema(HTFxPrice, HTFxLength))-HTFxEMA2 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFxEMA1, HTFxLength))+HTFxEMA2 = f_secureSecurity(syminfo.tickerid, HTFres, ta.ema(HTFxEMA1, HTFxLength))-HTFxEMA3 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFxEMA2, HTFxLength))+HTFxEMA3 = f_secureSecurity(syminfo.tickerid, HTFres, ta.ema(HTFxEMA2, HTFxLength))HTFxnRes = (3 * HTFxEMA1) - (3 * HTFxEMA2) + HTFxEMA3-HTFxnResP = plot(HTFxnRes, color=color.yellow, linewidth=1,transp=30, title="TEMA1")+HTFxnResP = plot(HTFxnRes, color=color.new(color.yellow, 30), linewidth=1, title="TEMA1")HTFyLength = input(15, minval=1, title="HTF Slow Length")HTFyPrice = close-HTFyEMA1 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFyPrice, HTFyLength))+HTFyEMA1 = f_secureSecurity(syminfo.tickerid, HTFres, ta.ema(HTFyPrice, HTFyLength))-HTFyEMA2 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFyEMA1, HTFyLength))+HTFyEMA2 = f_secureSecurity(syminfo.tickerid, HTFres, ta.ema(HTFyEMA1, HTFyLength))-HTFyEMA3 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFyEMA2, HTFyLength))+HTFyEMA3 = f_secureSecurity(syminfo.tickerid, HTFres, ta.ema(HTFyEMA2, HTFyLength))HTFynRes = (3 * HTFyEMA1) - (3 * HTFyEMA2) + HTFyEMA3-HTFynResP = plot(HTFynRes, color=color.purple, linewidth=1, transp=30, title="TEMA2")+HTFynResP = plot(HTFynRes, color=color.new(color.purple, 30), linewidth=1, title="TEMA2")// HTF Plot-fill(HTFxnResP, HTFynResP, color=HTFxnRes > HTFynRes ? color.yellow : color.purple, transp=90, editable=true)+fill(HTFxnResP, HTFynResP, color=color.new(HTFxnRes > HTFynRes ? color.yellow : color.purple, 90), editable=true)-bgcolor(HTFxnRes > HTFynRes ? color.yellow : na, transp=90, editable=true)+bgcolor(color.new(HTFxnRes > HTFynRes ? color.yellow : na, 90), editable=true)-bgcolor(HTFxnRes < HTFynRes ? color.purple : na, transp=90, editable=true)+bgcolor(color.new(HTFxnRes < HTFynRes ? color.purple : na, 90), editable=true)// }⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.string()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
9 more edits
  • Line 15: input() → input.int()
  • Line 24: input() → input.int()
  • Line 31: input() → input.int()
  • Line 42: input() → input.int()
  • Line 49: input() → input.int()
  • Line 68: when = LongEntryAlert → if block
  • Line 69: when = LongCloseAlert → if block
  • Line 71: when = ShortEntryAlert → if block
  • Line 72: when = ShortCloseAlert → if block
⋯strategy(title="TEMA Cross +HTF Backtest", shorttitle="TEMA_X_+HTF_BT", overlay=true, commission_type=strategy.commission.percent, commission_value=0, initial_capital = 500,  default_qty_type=strategy.cash, default_qty_value=500)-orderType = input("Longs+Shorts",title="What type of Orders", options=["Longs+Shorts","LongsOnly","ShortsOnly"])+orderType = input.string("Longs+Shorts",title="What type of Orders", options=["Longs+Shorts","LongsOnly","ShortsOnly"])isLong   = (orderType != "ShortsOnly")⋯// Backtest inputs-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=2010)+FromYear = input.int(defval=2020, title="From Year", minval=2010)-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)// Define backtest timewindow⋯//LTF Section-xLength = input(20, minval=1, title="Fast Length")+xLength = input.int(20, minval=1, title="Fast Length")xPrice = close⋯xnResP = plot(xnRes, color=color.green, linewidth=2, title="TEMA1")-yLength = input(60, minval=1, title="Slow Length")+yLength = input.int(60, minval=1, title="Slow Length")yPrice = close⋯f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)-HTFxLength = input(5, minval=1, title="HTF Fast Length")+HTFxLength = input.int(5, minval=1, title="HTF Fast Length")HTFxPrice = close⋯HTFxnResP = plot(HTFxnRes, color=color.new(color.yellow, 30), linewidth=1, title="TEMA1")-HTFyLength = input(15, minval=1, title="HTF Slow Length")+HTFyLength = input.int(15, minval=1, title="HTF Slow Length")HTFyPrice = close⋯if isLong-    strategy.entry("Long", strategy.long, when = LongEntryAlert)+    if LongEntryAlert+        strategy.entry("Long", strategy.long)-    strategy.close("Long", when = LongCloseAlert)+    if LongCloseAlert+        strategy.close("Long")if isShort-    strategy.entry("Short", strategy.short, when = ShortEntryAlert)+    if ShortEntryAlert+        strategy.entry("Short", strategy.short)-    strategy.close("Short", when = ShortCloseAlert)+    if ShortCloseAlert+        strategy.close("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: 27 before, 1 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.

⋯// © Seltzer_-//@version=5+//@version=6strategy(title="TEMA Cross +HTF Backtest", shorttitle="TEMA_X_+HTF_BT", overlay=true, commission_type=strategy.commission.percent, commission_value=0, initial_capital = 500,  default_qty_type=strategy.cash, default_qty_value=500)⋯

Settings

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

SettingDefaultType and rangeFeeds
What type of OrdersLongs+Shortsstring · options ["Longs+Shorts","LongsOnly","ShortsOnly"]isLong isShort
From Month1int · min 1 · max 12start
From Day1int · min 1 · max 31start
From Year2020int · min 2010start
To Month1int · min 1 · max 12finish
To Day1int · min 1 · max 31finish
To Year9999int · min 2017finish
Fast Length20int · min 1xEMA1 xEMA2 xEMA3
Slow Length60int · min 1yEMA1 yEMA2 yEMA3
HTF ResolutionDtimeframe (written input.resolution)HTFxEMA1 HTFxEMA2 HTFxEMA3 HTFyEMA1 HTFyEMA2 HTFyEMA3
HTF Fast Length5int · min 1HTFxEMA1 HTFxEMA2 HTFxEMA3
HTF Slow Length15int · min 1HTFyEMA1 HTFyEMA2 HTFyEMA3

What it calculates

  • EMA (ema, ta.ema in v5)xPrice, Fast Length (20)xEMA1 · line 26
  • EMA (ema, ta.ema in v5)xEMA1, Fast Length (20)xEMA2 · line 27
  • EMA (ema, ta.ema in v5)xEMA2, Fast Length (20)xEMA3 · line 28
  • EMA (ema, ta.ema in v5)yPrice, Slow Length (60)yEMA1 · line 33
  • EMA (ema, ta.ema in v5)yEMA1, Slow Length (60)yEMA2 · line 34
  • EMA (ema, ta.ema in v5)yEMA2, Slow Length (60)yEMA3 · line 35
  • EMA (ema, ta.ema in v5)HTFxPrice, HTF Fast Length (5)HTFxEMA1 · line 44
  • EMA (ema, ta.ema in v5)HTFxEMA1, HTF Fast Length (5)HTFxEMA2 · line 45
  • EMA (ema, ta.ema in v5)HTFxEMA2, HTF Fast Length (5)HTFxEMA3 · line 46
  • EMA (ema, ta.ema in v5)HTFyPrice, HTF Slow Length (15)HTFyEMA1 · line 51
  • EMA (ema, ta.ema in v5)HTFyEMA1, HTF Slow Length (15)HTFyEMA2 · line 52
  • EMA (ema, ta.ema in v5)HTFyEMA2, HTF Slow Length (15)HTFyEMA3 · line 53

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.

xLengthFast Lengthsetting · 20yLengthSlow Lengthsetting · 60HTFresHTF Resolutionsetting · DHTFxLengthHTF Fast Lengthsetting · 5HTFyLengthHTF Slow Lengthsetting · 15FromYearFrom Yearsetting · 2020FromMonthFrom Monthsetting · 1FromDayFrom Daysetting · 1ToYearTo Yearsetting · 9999ToMonthTo Monthsetting · 1ToDayTo Daysetting · 1closecloseprice dataorderTypeWhat type of Orderssetting · Longs+ShortsxEMA1EMA→ xEMA1xEMA2EMA→ xEMA2xEMA3EMA→ xEMA3yEMA1EMA→ yEMA1yEMA2EMA→ yEMA2yEMA3EMA→ yEMA3HTFxEMA1EMA→ HTFxEMA1HTFxEMA2EMA→ HTFxEMA2HTFxEMA3EMA→ HTFxEMA3HTFyEMA1EMA→ HTFyEMA1HTFyEMA2EMA→ HTFyEMA2HTFyEMA3EMA→ HTFyEMA3startstartvaluefinishfinishvaluexPrice, yPrice, HTFxPrice, HTFyPricexPrice · yPrice +24 valuesxnResxnResvalueynResynResvalueHTFxnResHTFxnResvalueHTFynResHTFynResvalueisLongisLongconditionisShortisShortconditionLongEntryAlertLongEntryAlertconditionLongCloseAlertLongCloseAlertconditionShortEntryAlertShortEntryAlertconditionShortCloseAlertShortCloseAlertconditionentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeentry:ShortOpen Shortstrategy.entryclose:ShortClose Shortstrategy.closeplot:30TEMA1plotplot:37TEMA2plotfill:38Fillfill × 2plot:48TEMA1plotplot:55TEMA2plotfill:57Fillfill × 2bgcolor:58bgcolorbgcolorbgcolor:59bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open Long longLongEntryAlertxnRes > ynRes and HTFxnRes > HTFynRes and window()On68
Close LongLongCloseAlertxnRes < ynRes and window()On69
Open Short shortShortEntryAlertxnRes < ynRes and HTFxnRes < HTFynRes and window()On71
Close ShortShortCloseAlertxnRes > ynResOn72

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

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

6/6trades 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.
  • CheckHigher-timeframe data1 security call(s) use lookahead_on (line 41). Without a [1] offset this reads future bars in history.
  • 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+82.6%+102.5%2748%1.9043.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+10.9%+5.5%2737%1.3211.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+119.8%+9.8%2450%1.8135.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+13.1%+8.4%2528%1.2720.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+39.6%+16.7%3438%1.2145.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+11.7%+21.5%2829%1.2215.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−36.6%+148.3%3339%0.7785.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.0%+17.1%3234%1.0315.4%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 market1155%$143.78
Sideways market1242%$133.22
Falling market450%$135.96

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

How bad could the drawdown be?

46.7%

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

0%54%
All 27 trades
SideEntryExitBarsP&L
long22 Jul 2024 68,165.405 Aug 2024 58,161.0014−$73.38
short5 Aug 2024 58,161.0023 Aug 2024 60,375.8018−$19.04
long23 Aug 2024 60,375.804 Sep 2024 57,487.7012−$23.92
short4 Sep 2024 57,487.7014 Sep 2024 60,498.0010−$26.18
long14 Sep 2024 60,498.0010 Oct 2024 60,636.0026$1.14
short11 Oct 2024 60,326.4015 Oct 2024 66,084.004−$47.72
long15 Oct 2024 66,084.006 Nov 2024 69,372.0022$24.88
short6 Nov 2024 69,372.007 Nov 2024 75,572.001−$44.69
long8 Nov 2024 75,857.903 Dec 2024 95,840.6025$131.71
short3 Dec 2024 95,840.6021 Jan 2025 102,260.0049−$33.49
long21 Jan 2025 102,260.002 Feb 2025 100,636.0012−$7.94
short2 Feb 2025 100,636.0020 Mar 2025 86,845.9046$68.51
long20 Mar 2025 86,845.9030 May 2025 105,590.0071$107.91
short30 May 2025 105,590.0011 Jul 2025 116,010.0042−$49.34
long11 Jul 2025 116,010.0029 Jul 2025 118,062.0018$8.85
short29 Jul 2025 118,062.0012 Sep 2025 115,483.0045$10.92
long12 Sep 2025 115,483.0027 Sep 2025 109,643.0015−$25.28
short27 Sep 2025 109,643.001 Oct 2025 114,049.004−$20.09
long1 Oct 2025 114,049.0015 Oct 2025 113,028.0014−$4.48
short15 Oct 2025 113,028.003 Dec 2025 91,277.9049$96.22
long4 Dec 2025 93,429.9026 Jan 2026 86,670.4053−$36.17
short26 Jan 2026 86,670.4027 Feb 2026 67,485.2032$110.68
long27 Feb 2026 67,485.2014 May 2026 79,313.6076$87.64
short14 May 2026 79,313.604 Jul 2026 62,583.3051$105.47
long4 Jul 2026 62,583.3012 Sep 2026 77,225.7070$116.98
short12 Sep 2026 77,225.7024 Sep 2026 84,397.6012−$46.43
long24 Sep 2026 84,397.6027 Sep 2026 84,433.103$0.21

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
TEMA Cross +HTF Backtest this page—v4 strategy+82.6%2743.0%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,274.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 31 msYes 1,000 bars in 189 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/// © Seltzer_//@version=4strategy(title="TEMA Cross +HTF Backtest", shorttitle="TEMA_X_+HTF_BT", overlay=true, commission_type=strategy.commission.percent, commission_value=0, initial_capital = 500,  default_qty_type=strategy.cash, default_qty_value=500)orderType = input("Longs+Shorts",title="What type of Orders", options=["Longs+Shorts","LongsOnly","ShortsOnly"])isLong   = (orderType != "ShortsOnly")isShort  = (orderType != "LongsOnly")// Backtest Section {// Backtest inputsFromMonth = 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=2010)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)// Define backtest timewindowstart = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start windowfinish = timestamp(ToYear, ToMonth, ToDay, 23, 59)  // backtest finish windowwindow() =>  // create function "within window of time"    time >= start and time <= finish ? true : false// }//TEMA Section {//LTF SectionxLength = input(20, minval=1, title="Fast Length")xPrice = closexEMA1 = ema(xPrice, xLength)xEMA2 = ema(xEMA1, xLength)xEMA3 = ema(xEMA2, xLength)xnRes = (3 * xEMA1) - (3 * xEMA2) + xEMA3xnResP = plot(xnRes, color=color.green, linewidth=2, title="TEMA1")yLength = input(60, minval=1, title="Slow Length")yPrice = closeyEMA1 = ema(yPrice, yLength)yEMA2 = ema(yEMA1, yLength)yEMA3 = ema(yEMA2, yLength)ynRes = (3 * yEMA1) - (3 * yEMA2) + yEMA3ynResP = plot(ynRes, color=color.red, linewidth=2, title="TEMA2")fill(xnResP, ynResP, color=xnRes > ynRes ? color.green : color.red, transp=65, editable=true)//HTF SectionHTFres = input(defval="D", type=input.resolution, title="HTF Resolution")f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)HTFxLength = input(5, minval=1, title="HTF Fast Length")HTFxPrice = closeHTFxEMA1 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFxPrice, HTFxLength))HTFxEMA2 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFxEMA1, HTFxLength))HTFxEMA3 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFxEMA2, HTFxLength))HTFxnRes = (3 * HTFxEMA1) - (3 * HTFxEMA2) + HTFxEMA3HTFxnResP = plot(HTFxnRes, color=color.yellow, linewidth=1,transp=30, title="TEMA1")HTFyLength = input(15, minval=1, title="HTF Slow Length")HTFyPrice = closeHTFyEMA1 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFyPrice, HTFyLength))HTFyEMA2 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFyEMA1, HTFyLength))HTFyEMA3 = f_secureSecurity(syminfo.tickerid, HTFres, ema(HTFyEMA2, HTFyLength))HTFynRes = (3 * HTFyEMA1) - (3 * HTFyEMA2) + HTFyEMA3HTFynResP = plot(HTFynRes, color=color.purple, linewidth=1, transp=30, title="TEMA2")// HTF Plotfill(HTFxnResP, HTFynResP, color=HTFxnRes > HTFynRes ? color.yellow : color.purple, transp=90, editable=true)bgcolor(HTFxnRes > HTFynRes ? color.yellow : na, transp=90, editable=true)bgcolor(HTFxnRes < HTFynRes ? color.purple : na, transp=90, editable=true)// }// Buy and Sell TriggersLongEntryAlert = xnRes > ynRes and HTFxnRes > HTFynRes and window()LongCloseAlert = xnRes < ynRes and window()ShortEntryAlert = xnRes < ynRes and HTFxnRes < HTFynRes and window()ShortCloseAlert = xnRes > ynRes// Entry & Exit signalsif isLong    strategy.entry("Long", strategy.long, when = LongEntryAlert)    strategy.close("Long", when = LongCloseAlert)if isShort    strategy.entry("Short", strategy.short, when = ShortEntryAlert)    strategy.close("Short", when = ShortCloseAlert)