Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

TEMA-DEMA-HMA Strategy

A Pine Script v4 strategy built on EMA (close, 8), WMA (close, Hlength, round(sqrt(Hlength))) and Crossunder (dema, tema). 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.1% commission. 4 settings; defaults include TEMA Length 8, DEMA Length 43 and Hull Length 52.

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-DEMA-HMA 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 TEMA-DEMA-HMA Strategy do on BTCUSDT 1D with default settings?
+73.82%
From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can TEMA-DEMA-HMA 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 TEMA-DEMA-HMA Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does TEMA-DEMA-HMA Strategy run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 35 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • Arrow
  • 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 (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,701,530$2,025,273Equity from $1,000,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
+73.82%
$738,220.00
Buy and hold
+102.5%
same period
Closed trades
4
2 won · 2 lost
Profitable
50.0%
of closed trades
Profit factor
17.01
gross profit ÷ gross loss
Max drawdown
30.60%
−$306,031.00

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

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses transp =, which v5 removed line 26

    transp = on line 26, 27, 28, 29, 30. 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, wma → ta.wma, round → math.round, sqrt → math.sqrt, crossunder → ta.crossunder, rising → ta.rising, crossover → ta.crossover, falling → ta.falling.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 10: ema → ta.ema
  • Line 11: ema → ta.ema
  • Line 12: ema → ta.ema
  • Line 15: ema → ta.ema
  • Line 16: ema → ta.ema
20 more edits
  • Line 19: wma → ta.wma
  • Line 19: wma → ta.wma
  • Line 19: wma → ta.wma
  • Line 19: round → math.round
  • Line 19: sqrt → math.sqrt
  • Line 20: crossunder → ta.crossunder
  • Line 20: rising → ta.rising
  • Line 21: crossover → ta.crossover
  • Line 21: falling → ta.falling
  • Line 22: crossunder → ta.crossunder
  • Line 23: crossover → ta.crossover
  • Line 26: rising → ta.rising
  • Line 26: transp = 0 → color.new(rising(hma, Rlength) ? color.green : na, 0)
  • Line 27: falling → ta.falling
  • Line 27: transp = 0 → color.new(falling(hma, Rlength) ? color.red : na, 0)
  • Line 28: rising → ta.rising
  • Line 28: transp = 70 → color.new(rising(hma, Rlength) ? color.green : na, 70)
  • Line 29: falling → ta.falling
  • Line 29: transp = 70 → color.new(falling(hma, Rlength) ? color.red : na, 70)
  • Line 30: transp = 70 removed: the call sets no colour to fold it into, so its default colour loses the transparency
⋯// © tuned-com-//@version=4+//@version=5strategy("TEMA/DEMA/HMA", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000000, commission_type=strategy.commission.percent, commission_value=0.1)⋯//TEMA//-ema1 = ema(close, Tlength)+ema1 = ta.ema(close, Tlength)-ema2 = ema(ema1, Tlength)+ema2 = ta.ema(ema1, Tlength)-ema3 = ema(ema2, Tlength)+ema3 = ta.ema(ema2, Tlength)tema = 3 * (ema1 - ema2) + ema3//DEMA//-e1 = ema(close, Dlength)+e1 = ta.ema(close, Dlength)-e2 = ema(e1, Dlength)+e2 = ta.ema(e1, Dlength)dema = 2 * e1 - e2//HMA//-hma = wma(2 * wma(close, Hlength / 2) - wma(close, Hlength), round(sqrt(Hlength)))+hma = ta.wma(2 * ta.wma(close, Hlength / 2) - ta.wma(close, Hlength), math.round(math.sqrt(Hlength)))-up = crossunder(dema, tema) and rising(hma, Rlength)+up = ta.crossunder(dema, tema) and ta.rising(hma, Rlength)-down = crossover(dema, tema) and falling(hma, Rlength)+down = ta.crossover(dema, tema) and ta.falling(hma, Rlength)-downc = crossunder(dema, tema)+downc = ta.crossunder(dema, tema)-upc = crossover(dema, tema)+upc = ta.crossover(dema, tema)plot(dema, color=color.green, linewidth=2)plot(tema, color=color.aqua, linewidth=2)-plot(hma, color=rising(hma, Rlength) ? color.green : na, linewidth=2, transp=0)+plot(hma, color=color.new(ta.rising(hma, Rlength) ? color.green : na, 0), linewidth=2)-plot(hma, color=falling(hma, Rlength) ? color.red : na, linewidth=2, transp=0)+plot(hma, color=color.new(ta.falling(hma, Rlength) ? color.red : na, 0), linewidth=2)-bgcolor(rising(hma, Rlength) ? color.green : na, transp=70)+bgcolor(color.new(ta.rising(hma, Rlength) ? color.green : na, 70))-bgcolor(falling(hma, Rlength) ? color.red : na, transp=70)+bgcolor(color.new(ta.falling(hma, Rlength) ? color.red : na, 70))-plotarrow(tema - dema, colorup=color.green, colordown=color.red, transp=70)+plotarrow(tema - dema, colorup=color.green, colordown=color.red)if up⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.int()
  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
⋯strategy("TEMA/DEMA/HMA", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000000, commission_type=strategy.commission.percent, commission_value=0.1)-Tlength = input(8, title="TEMA Length", minval=1)+Tlength = input.int(8, title="TEMA Length", minval=1)-Dlength = input(43, title="DEMA Length", minval=1)+Dlength = input.int(43, title="DEMA Length", minval=1)-Hlength = input(52, title="Hull Length", minval=1)+Hlength = input.int(52, title="Hull Length", minval=1)-Rlength = input(2, title="Hull Trend Test Length", minval=1)+Rlength = input.int(2, title="Hull Trend Test Length", minval=1)//TEMA//⋯

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: 4 before, 23 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.

⋯// © tuned-com-//@version=5+//@version=6strategy("TEMA/DEMA/HMA", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000000, commission_type=strategy.commission.percent, commission_value=0.1)⋯

Settings

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

SettingDefaultType and rangeFeeds
TEMA Length8int · min 1ema1 ema2 ema3
DEMA Length43int · min 1e1 e2
Hull Length52int · min 1hma
Hull Trend Test Length2int · min 1up down plot bgcolor

What it calculates

  • EMA (ema, ta.ema in v5)close, TEMA Length (8)ema1 · line 10
  • EMA (ema, ta.ema in v5)ema1, TEMA Length (8)ema2 · line 11
  • EMA (ema, ta.ema in v5)ema2, TEMA Length (8)ema3 · line 12
  • EMA (ema, ta.ema in v5)close, DEMA Length (43)e1 · line 15
  • EMA (ema, ta.ema in v5)e1, DEMA Length (43)e2 · line 16
  • WMA (wma, ta.wma in v5)2 * wma(close, Hlength / 2) - wma(close, Hlength), round(sqrt(Hlength))hma · line 19
  • Crossunder (crossunder, ta.crossunder in v5)dema, temadownc · line 22
  • Crossover (crossover, ta.crossover in v5)dema, temaupc · line 23

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 dataTlengthTEMA Lengthsetting · 8DlengthDEMA Lengthsetting · 43HlengthHull Lengthsetting · 52RlengthHull Trend Test Lengthsetting · 2ema1EMA→ ema1ema2EMA→ ema2ema3EMA→ ema3e1EMA→ e1e2EMA→ e2hmaWMA→ hmadowncCrossunder→ downcupcCrossover→ upctematemavaluedemademavalueupupconditiondowndownconditionentry:Long EntryOpen Long Entrystrategy.entryentry:Short EntryOpen Short Entrystrategy.entryplot:24plotplotplot:25plotplotplot:26plotplotplot:27plotplotbgcolor:28bgcolorbgcolorbgcolor:29bgcolorbgcolorplotarrow:30plotarrowplotarrow

Order rules

OrderFires whenBy defaultLine
Open Long Entry longupOn32
Open Short Entry shortdownOn34

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+73.8%+102.5%450%17.0130.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−26.4%+5.5%333%0.0732.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+92.4%+9.8%367%11.4773.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+34.5%+8.4%850%3.9513.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−97.0%+16.7%825%0.0397.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−27.5%+21.5%450%0.2844.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−26.5%+148.3%540%0.2638.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+12.9%+17.1%425%1.8811.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 market20%−$44,384.50
Sideways market2100%$784,344.00
Falling market0—$0.00

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

How bad could the drawdown be?

3.0%

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

0%3%
All 4 trades
SideEntryExitBarsP&L
long5 Jun 2024 70,537.8013 Jun 2025 105,672.00373$495,093.00
short13 Jun 2025 105,672.0030 Jun 2025 108,357.0017−$41,019.50
long30 Jun 2025 108,357.0031 Oct 2025 108,323.00123−$3,364.93
short31 Oct 2025 108,323.005 Oct 2026 86,530.00339$289,251.00

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-DEMA-HMA Strategy this page—v4 strategy+73.8%430.6%
PMA Strategy Idea by QuantCTema rising fallingv4 strategy+51.7%12930.8%
SL1 Pips after TP2 (MA) by gpadiharema wmav4 strategy+0.4%330.1%
Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] by myncryptoema rising fallingv5 strategy−0.3%20.3%
5min MACD scalp by Joel by Zippy111ema rising fallingv5 strategydoes not run in Zeal Terminal
cRSI + Waves Strategy with VWMA overlay by Dr_Robotowma rising fallingv4 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msYes 1,000 bars in 35 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/// © tuned-com//@version=4strategy("TEMA/DEMA/HMA", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000000, commission_type=strategy.commission.percent, commission_value=0.1)Tlength = input(8, title="TEMA Length", minval=1)Dlength = input(43, title="DEMA Length", minval=1)Hlength = input(52, title="Hull Length", minval=1)Rlength = input(2, title="Hull Trend Test Length", minval=1)//TEMA//ema1 = ema(close, Tlength)ema2 = ema(ema1, Tlength)ema3 = ema(ema2, Tlength)tema = 3 * (ema1 - ema2) + ema3//DEMA//e1 = ema(close, Dlength)e2 = ema(e1, Dlength)dema = 2 * e1 - e2//HMA//hma = wma(2 * wma(close, Hlength / 2) - wma(close, Hlength), round(sqrt(Hlength)))up = crossunder(dema, tema) and rising(hma, Rlength)down = crossover(dema, tema) and falling(hma, Rlength)downc = crossunder(dema, tema)upc = crossover(dema, tema)plot(dema, color=color.green, linewidth=2)plot(tema, color=color.aqua, linewidth=2)plot(hma, color=rising(hma, Rlength) ? color.green : na, linewidth=2, transp=0)plot(hma, color=falling(hma, Rlength) ? color.red : na, linewidth=2, transp=0)bgcolor(rising(hma, Rlength) ? color.green : na, transp=70)bgcolor(falling(hma, Rlength) ? color.red : na, transp=70)plotarrow(tema - dema, colorup=color.green, colordown=color.red, transp=70)if up    strategy.entry("Long Entry", strategy.long)if down    strategy.entry("Short Entry", strategy.short)