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
- 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
VerifiedSame 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⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| TEMA Length | 8 | int · min 1 | ema1 ema2 ema3 |
| DEMA Length | 43 | int · min 1 | e1 e2 |
| Hull Length | 52 | int · min 1 | hma |
| Hull Trend Test Length | 2 | int · min 1 | up down plot bgcolor |
What it calculates
- EMA (
ema,ta.emain v5)close, TEMA Length (8)ema1 · line 10 - EMA (
ema,ta.emain v5)ema1, TEMA Length (8)ema2 · line 11 - EMA (
ema,ta.emain v5)ema2, TEMA Length (8)ema3 · line 12 - EMA (
ema,ta.emain v5)close, DEMA Length (43)e1 · line 15 - EMA (
ema,ta.emain v5)e1, DEMA Length (43)e2 · line 16 - WMA (
wma,ta.wmain v5)2 * wma(close, Hlength / 2) - wma(close, Hlength), round(sqrt(Hlength))hma · line 19 - Crossunder (
crossunder,ta.crossunderin v5)dema, temadownc · line 22 - Crossover (
crossover,ta.crossoverin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long Entry long | up | On | 32 |
| Open Short Entry short | down | On | 34 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +73.8% | +102.5% | 4 | 50% | 17.01 | 30.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −26.4% | +5.5% | 3 | 33% | 0.07 | 32.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +92.4% | +9.8% | 3 | 67% | 11.47 | 73.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +34.5% | +8.4% | 8 | 50% | 3.95 | 13.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −97.0% | +16.7% | 8 | 25% | 0.03 | 97.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −27.5% | +21.5% | 4 | 50% | 0.28 | 44.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −26.5% | +148.3% | 5 | 40% | 0.26 | 38.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +12.9% | +17.1% | 4 | 25% | 1.88 | 11.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 0% | −$44,384.50 |
| Sideways market | 2 | 100% | $784,344.00 |
| Falling market | 0 | — | $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.
All 4 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 Jun 2024 70,537.80 | 13 Jun 2025 105,672.00 | 373 | $495,093.00 |
| short | 13 Jun 2025 105,672.00 | 30 Jun 2025 108,357.00 | 17 | −$41,019.50 |
| long | 30 Jun 2025 108,357.00 | 31 Oct 2025 108,323.00 | 123 | −$3,364.93 |
| short | 31 Oct 2025 108,323.00 | 5 Oct 2026 86,530.00 | 339 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| TEMA-DEMA-HMA Strategy this page | — | v4 strategy | +73.8% | 4 | 30.6% |
| PMA Strategy Idea by QuantCT | ema rising falling | v4 strategy | +51.7% | 129 | 30.8% |
| SL1 Pips after TP2 (MA) by gpadihar | ema wma | v4 strategy | +0.4% | 33 | 0.1% |
| Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] by myncrypto | ema rising falling | v5 strategy | −0.3% | 2 | 0.3% |
| 5min MACD scalp by Joel by Zippy111 | ema rising falling | v5 strategy | does not run in Zeal Terminal | ||
| cRSI + Waves Strategy with VWMA overlay by Dr_Roboto | wma rising falling | v4 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | Yes 1,000 bars in 35 ms | Not measured |
| PineTS | No 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)