Pine Script v4 · Strategy
ZEGUELA DEMABOT
A Pine Script v4 strategy built on EMA (series, length). It has 7 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 90% of equity and pays 0.070% commission. 15 settings; defaults include Source Data close, Length DEMA #1 8 and Length DEMA #2 21.
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 ZEGUELA DEMABOT repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 18 of 18 trades.
- How did ZEGUELA DEMABOT do on BTCUSDT 1D with default settings?
- +29.26%
- From 26 Jan 2024 to 21 Oct 2026, over 78 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can ZEGUELA DEMABOT be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does ZEGUELA DEMABOT use a stop loss?
- Yes
- strategy.exit sets a stop on line 148, 151, 154, 156.
- Does ZEGUELA DEMABOT run in Zeal Terminal?
- Yes
- It compiles in 55 ms and runs 1,000 bars in 140 ms, in the browser.
BTCUSDT · 1D · default settings
- DEMA #1
- DEMA #2
- Entry Price
- Long Stop
- Long TP
- Short Stop
- Short TP
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +29.26%
- $29.26
- Buy and hold
- +102.5%
- same period
- Closed trades
- 78
- 29 won · 49 lost
- Profitable
- 37.2%
- of closed trades
- Profit factor
- 1.13
- gross profit ÷ gross loss
- Max drawdown
- 42.99%
- −$78.00
One run with the author's default settings, $100 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.
-
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 ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder, max → math.max, min → math.min, tostring → str.tostring, highest → ta.highest.
v4 → v5
DiffersTrades differ: 78 before, 78 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 8: input(type = input.source) → input.source()
- Line 10: input(type = input.integer) → input.int()
- Line 11: input(type = input.integer) → input.int()
- Line 12: input(type = input.integer) → input.int()
- Line 17: ema → ta.ema
32 more edits
- Line 18: ema → ta.ema
- Line 28: crossover → ta.crossover
- Line 31: crossover → ta.crossover
- Line 34: crossover → ta.crossover
- Line 36: crossover → ta.crossover
- Line 39: crossunder → ta.crossunder
- Line 42: crossunder → ta.crossunder
- Line 45: crossunder → ta.crossunder
- Line 47: crossunder → ta.crossunder
- Line 55: input(type = input.bool) → input.bool()
- Line 56: input(type = input.float) → input.float()
- Line 57: input(type = input.float) → input.float()
- Line 58: input(type = input.float) → input.float()
- Line 59: input(type = input.float) → input.float()
- Line 69: max → math.max
- Line 76: min → math.min
- Line 116: input(type = input.integer) → input.int()
- Line 118: input(type = input.integer) → input.int()
- Line 120: input(type = input.integer) → input.int()
- Line 122: input(type = input.integer) → input.int()
- Line 124: input(type = input.integer) → input.int()
- Line 126: input(type = input.integer) → input.int()
- Line 169: tostring → str.tostring
- Line 170: tostring → str.tostring
- Line 171: tostring → str.tostring
- Line 172: tostring → str.tostring
- Line 173: tostring → str.tostring
- Line 218: max → math.max
- Line 218: highest → ta.highest
- Line 221: tostring → str.tostring
- Line 222: tostring → str.tostring
- Line 223: tostring → str.tostring
⋯// ©zeguela-//@version=4+//@version=5strategy(title="ZEGUELA DEMABOT", commission_value=0.070, commission_type=strategy.commission.percent, initial_capital=100, default_qty_value=90, default_qty_type=strategy.percent_of_equity, overlay=true, process_orders_on_close=true)⋯// Input options-srcData = input(title="Source Data", type=input.source, defval=close)+srcData = input.source(title="Source Data", defval=close)// Length settings-len1 = input(title="Length DEMA #1", type=input.integer, defval=8, minval=1)+len1 = input.int(title="Length DEMA #1", defval=8, minval=1)-len2 = input(title="Length DEMA #2", type=input.integer, defval=21, minval=0)+len2 = input.int(title="Length DEMA #2", defval=21, minval=0)-len3 = input(title="Length DEMA #3", type=input.integer, defval=0, minval=0)+len3 = input.int(title="Length DEMA #3", defval=0, minval=0)// Step 2. Calculate indicator values⋯ if (length > 0)- emaValue = ema(series, length)+ emaValue = ta.ema(series, length)- 2 * emaValue - ema(emaValue, length)+ 2 * emaValue - ta.ema(emaValue, length) else⋯demaCrossover = if (len2 > 0) and (len3 > 0)- crossover(demaVal1, demaVal2) and (demaVal3 > demaVal3[1])+ ta.crossover(demaVal1, demaVal2) and (demaVal3 > demaVal3[1])else if (len2 > 0) and (len3 == 0)- crossover(demaVal1, demaVal2)+ ta.crossover(demaVal1, demaVal2) else if (len3 > 0) and (len2 == 0)- crossover(demaVal1, demaVal3)+ ta.crossover(demaVal1, demaVal3) else- crossover(close, demaVal1)+ ta.crossover(close, demaVal1)// Check if there's a DEMA crossunderdemaCrossunder = if (len2 > 0) and (len3 > 0)- crossunder(demaVal1, demaVal2) and (demaVal3 < demaVal3[1])+ ta.crossunder(demaVal1, demaVal2) and (demaVal3 < demaVal3[1])else if (len2 > 0) and (len3 == 0)- crossunder(demaVal1, demaVal2)+ ta.crossunder(demaVal1, demaVal2) else if (len3 > 0) and (len2 == 0)- crossunder(demaVal1, demaVal3)+ ta.crossunder(demaVal1, demaVal3) else- crossunder(close, demaVal1)+ ta.crossunder(close, demaVal1)// Step 4. Output indicator data⋯//TRAILING STOP CODE-a = input(title="Usar Trailing Stop?", type=input.bool, defval=false)+a = input.bool(title="Usar Trailing Stop?", defval=false)-stopPerlong = input(10.0, title='Stop Loss Long %', type=input.float, group="Stop Loss & Take Profit Settings") / 100+stopPerlong = input.float(10.0, title='Stop Loss Long %', group="Stop Loss & Take Profit Settings") / 100-stopPershort = input(5.0, title='Stop Loss Short %', type=input.float, group="Stop Loss & Take Profit Settings") / 100+stopPershort = input.float(5.0, title='Stop Loss Short %', group="Stop Loss & Take Profit Settings") / 100-take1Perlong = input(40.0, title='Take Profit Long % 1', type=input.float, group="Stop Loss & Take Profit Settings") / 100+take1Perlong = input.float(40.0, title='Take Profit Long % 1', group="Stop Loss & Take Profit Settings") / 100-take1Pershort = input(10.0, title='Take Profit Short % 1', type=input.float, group="Stop Loss & Take Profit Settings") / 100+take1Pershort = input.float(10.0, title='Take Profit Short % 1', group="Stop Loss & Take Profit Settings") / 100// Determine stop loss price⋯ stopValue = close * (1 - stopPerlong)- max(stopValue, longStopPriceTrail[1])+ math.max(stopValue, longStopPriceTrail[1])else⋯ stopValue = close * (1 + stopPershort)- min(stopValue, shortStopPriceTrail[1])+ math.min(stopValue, shortStopPriceTrail[1])else⋯// Make input options that configure backtest date range-_startDate = input(title="Start Date", type=input.integer,+_startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31, group="BackTest Period")-_startMonth = input(title="Start Month", type=input.integer,+_startMonth = input.int(title="Start Month", defval=4, minval=1, maxval=12, group="BackTest Period")-_startYear = input(title="Start Year", type=input.integer,+_startYear = input.int(title="Start Year", defval=2021, minval=1800, maxval=2100, group="BackTest Period")-_endDate = input(title="End Date", type=input.integer,+_endDate = input.int(title="End Date", defval=31, minval=1, maxval=31, group="BackTest Period")-_endMonth = input(title="End Month", type=input.integer,+_endMonth = input.int(title="End Month", defval=12, minval=1, maxval=12, group="BackTest Period")-_endYear = input(title="End Year", type=input.integer,+_endYear = input.int(title="End Year", defval=2031, minval=1800, maxval=2100, group="BackTest Period")⋯// Insert label with value-stopLossOnLong = "Stop Loss = " + tostring(longStop)+stopLossOnLong = "Stop Loss = " + str.tostring(longStop)-stopLossOnShort = "Stop Loss = " + tostring(shortStop)+stopLossOnShort = "Stop Loss = " + str.tostring(shortStop)-takeprofitOnLong = "Take Profit = " + tostring(longTake1Price)+takeprofitOnLong = "Take Profit = " + str.tostring(longTake1Price)-takeprofitOnShort = "Take Profit = " + tostring(shortTake1Price)+takeprofitOnShort = "Take Profit = " + str.tostring(shortTake1Price)-precoentrada = "Entry Price = " + tostring(strategy.position_avg_price)+precoentrada = "Entry Price = " + str.tostring(strategy.position_avg_price)var label FinalLabelpriceL = na⋯label.delete(lb)-lb := label.new(bar_index, max(high, highest(4)[1]), textcolor=color.white,+lb := label.new(bar_index, math.max(high, ta.highest(4)[1]), textcolor=color.white, color=posCol, text="Pos: "+ posDir +- "\nPnL: "+tostring(posProfit, "#.##")+"%" ++ "\nPnL: "+str.tostring(posProfit, "#.##")+"%" +- "\nAvg Price: "+tostring(strategy.position_avg_price, "#.####") ++ "\nAvg Price: "+str.tostring(strategy.position_avg_price, "#.####") +- "\nClose: "+tostring(close, "#.####"))+ "\nClose: "+str.tostring(close, "#.####"))Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L189:C32: cannot use the history-referencing operator '[]' on the literal '0' in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// ©zeguela-//@version=5+//@version=6strategy(title="ZEGUELA DEMABOT", commission_value=0.070, commission_type=strategy.commission.percent, initial_capital=100, default_qty_value=90, default_qty_type=strategy.percent_of_equity, overlay=true, process_orders_on_close=true)⋯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 |
|---|---|---|---|
| Source Data | close | source | demaVal1 demaVal2 demaVal3 |
| Length DEMA #1 | 8 | int (written input.integer) · min 1 | demaVal1 |
| Length DEMA #2 | 21 | int (written input.integer) · min 0 | demaVal2 demaCrossover demaCrossunder |
| Length DEMA #3 | 0 | int (written input.integer) · min 0 | demaVal3 demaCrossover demaCrossunder |
| Usar Trailing Stop? | false | bool | longStop shortStop |
| Stop Loss & Take Profit Settings | |||
| Stop Loss Long % | 10.0 | float | longStopPrice longStopPriceTrail longStopEntrada stopL stopValue |
| Stop Loss Short % | 5.0 | float | shortStopPrice stopValue shortStopPriceTrail shortStopEntrada stopS |
| Take Profit Long % 1 | 40.0 | float | longTake1Price longTPEntrada takeL |
| Take Profit Short % 1 | 10.0 | float | shortTake1Price shortTPEntrada takeS |
| BackTest Period | |||
| Start Date | 1 | int (written input.integer) · min 1 · max 31 | _inDateRange |
| Start Month | 4 | int (written input.integer) · min 1 · max 12 | _inDateRange |
| Start Year | 2021 | int (written input.integer) · min 1800 · max 2100 | _inDateRange |
| End Date | 31 | int (written input.integer) · min 1 · max 31 | _inDateRange |
| End Month | 12 | int (written input.integer) · min 1 · max 12 | _inDateRange |
| End Year | 2031 | int (written input.integer) · min 1800 · max 2100 | _inDateRange |
What it calculates
- EMA (
ema,ta.emain v5)series, lengthemaValue · line 17
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.
The script has 67 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open LONG long | (demaCrossover) | On | 147 |
| Exit Close Long TP1 stop and limit | (demaCrossover) | On | 148 |
| Open SHORT short | (demaCrossunder) | On | 150 |
| Exit Close Short TP1 stop and limit | (demaCrossunder) | On | 151 |
| Exit TP/SL stop and limit | strategy.position_size > 0 | On | 154 |
| Exit TP/SL stop and limit | strategy.position_size < 0 | On | 156 |
| Close | (not _inDateRange) | On | 208 |
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.
- 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +29.3% | +102.5% | 78 | 37% | 1.13 | 43.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +5.6% | +5.5% | 73 | 37% | 1.08 | 17.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.5% | +9.8% | 75 | 35% | 1.01 | 43.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −6.7% | +8.4% | 77 | 29% | 0.93 | 29.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +300.4% | +16.7% | 59 | 49% | 1.98 | 23.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.0% | +21.5% | 73 | 34% | 1.01 | 30.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −30.4% | +148.3% | 75 | 36% | 0.82 | 42.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.0% | +17.1% | 81 | 32% | 1.01 | 17.5% | 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 | 23 | 39% | $12.23 |
| Sideways market | 37 | 46% | $20.06 |
| Falling market | 18 | 17% | −$2.95 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
48.2%
The 95th percentile of the worst drawdown when the same 78 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 24.0% to 48.2%; the tick is what actually happened, 41.7%. Order luck alone moves it this much.
All 78 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 15 Mar 2024 69,499.90 | 19 Mar 2024 62,549.90 | 4 | $8.87 |
| long | 23 Apr 2024 66,414.00 | 24 Apr 2024 64,289.60 | 1 | −$3.27 |
| short | 24 Apr 2024 64,289.60 | 1 May 2024 57,860.60 | 7 | $9.38 |
| long | 5 May 2024 64,012.00 | 11 May 2024 60,826.00 | 6 | −$5.29 |
| short | 11 May 2024 60,826.00 | 12 May 2024 61,484.00 | 1 | −$1.21 |
| long | 12 May 2024 61,484.00 | 30 May 2024 68,352.20 | 18 | $10.76 |
| short | 30 May 2024 68,352.20 | 4 Jun 2024 70,537.80 | 5 | −$3.58 |
| long | 4 Jun 2024 70,537.80 | 8 Jun 2024 69,310.50 | 4 | −$1.96 |
| short | 8 Jun 2024 69,310.50 | 24 Jun 2024 62,379.40 | 16 | $10.10 |
| long | 2 Jul 2024 62,135.50 | 3 Jul 2024 60,208.60 | 1 | −$3.61 |
| short | 3 Jul 2024 60,208.60 | 5 Jul 2024 54,187.70 | 2 | $10.67 |
| long | 12 Jul 2024 57,889.10 | 31 Jul 2024 64,628.00 | 19 | $13.53 |
| short | 31 Jul 2024 64,628.00 | 4 Aug 2024 58,165.20 | 4 | $12.82 |
| long | 17 Aug 2024 59,492.00 | 18 Aug 2024 58,427.30 | 1 | −$2.73 |
| short | 18 Aug 2024 58,427.30 | 19 Aug 2024 59,438.50 | 1 | −$2.60 |
| long | 19 Aug 2024 59,438.50 | 29 Aug 2024 59,359.00 | 10 | −$0.37 |
| short | 29 Aug 2024 59,359.00 | 6 Sep 2024 53,423.10 | 8 | $13.45 |
| long | 11 Sep 2024 57,338.00 | 1 Oct 2024 60,805.80 | 20 | $8.76 |
| short | 1 Oct 2024 60,805.80 | 7 Oct 2024 63,846.10 | 6 | −$8.04 |
| long | 14 Oct 2024 66,084.00 | 25 Oct 2024 66,698.30 | 11 | $1.18 |
| short | 25 Oct 2024 66,698.30 | 28 Oct 2024 70,033.30 | 3 | −$7.72 |
| long | 28 Oct 2024 69,962.20 | 2 Nov 2024 69,374.70 | 5 | −$1.40 |
| short | 2 Nov 2024 69,374.70 | 6 Nov 2024 72,843.50 | 4 | −$7.30 |
| long | 6 Nov 2024 75,572.00 | 25 Nov 2024 93,010.00 | 19 | $31.01 |
| short | 25 Nov 2024 93,010.00 | 29 Nov 2024 97,660.50 | 4 | −$8.40 |
| long | 16 Dec 2024 106,059.00 | 18 Dec 2024 100,204.00 | 2 | −$8.80 |
| short | 18 Dec 2024 100,204.00 | 4 Jan 2025 98,220.50 | 17 | $2.72 |
| long | 4 Jan 2025 98,220.50 | 9 Jan 2025 92,552.50 | 5 | −$8.88 |
| short | 9 Jan 2025 92,552.50 | 14 Jan 2025 97,180.10 | 5 | −$7.32 |
| long | 15 Jan 2025 100,497.00 | 28 Jan 2025 101,336.00 | 13 | $0.94 |
| short | 28 Jan 2025 101,336.00 | 30 Jan 2025 106,402.00 | 2 | −$7.02 |
| long | 20 Feb 2025 98,305.00 | 24 Feb 2025 91,552.90 | 4 | −$9.11 |
| short | 24 Feb 2025 91,552.90 | 26 Feb 2025 82,397.60 | 2 | $12.04 |
| long | 5 Mar 2025 90,606.00 | 9 Mar 2025 81,545.40 | 4 | −$13.45 |
| short | 9 Mar 2025 80,734.40 | 14 Mar 2025 84,771.10 | 5 | −$6.21 |
| long | 15 Mar 2025 84,338.40 | 31 Mar 2025 82,550.00 | 16 | −$2.60 |
| short | 31 Mar 2025 82,550.00 | 1 Apr 2025 85,158.30 | 1 | −$3.73 |
| long | 1 Apr 2025 85,158.30 | 6 Apr 2025 78,430.00 | 5 | −$8.80 |
| short | 6 Apr 2025 78,430.00 | 9 Apr 2025 82,351.50 | 3 | −$5.22 |
| long | 11 Apr 2025 83,423.80 | 5 May 2025 94,733.70 | 24 | $12.98 |
| short | 5 May 2025 94,733.70 | 6 May 2025 96,834.00 | 1 | −$2.56 |
| long | 6 May 2025 96,834.00 | 17 May 2025 103,127.00 | 11 | $6.75 |
| short | 17 May 2025 103,127.00 | 20 May 2025 106,850.00 | 3 | −$4.21 |
| long | 20 May 2025 106,850.00 | 24 May 2025 107,762.00 | 4 | $0.77 |
| short | 24 May 2025 107,762.00 | 10 Jun 2025 110,274.00 | 17 | −$2.70 |
| long | 10 Jun 2025 110,274.00 | 12 Jun 2025 105,672.00 | 2 | −$4.60 |
| short | 12 Jun 2025 105,672.00 | 25 Jun 2025 107,341.00 | 13 | −$1.77 |
| long | 25 Jun 2025 107,341.00 | 21 Jul 2025 117,380.00 | 26 | $9.30 |
| short | 21 Jul 2025 117,380.00 | 10 Aug 2025 119,294.00 | 20 | −$1.94 |
| long | 10 Aug 2025 119,294.00 | 16 Aug 2025 117,381.00 | 6 | −$1.88 |
| short | 16 Aug 2025 117,381.00 | 5 Sep 2025 110,660.00 | 20 | $5.92 |
| long | 5 Sep 2025 110,660.00 | 22 Sep 2025 112,651.00 | 17 | $1.85 |
| short | 22 Sep 2025 112,651.00 | 1 Oct 2025 118,284.00 | 9 | −$5.81 |
| long | 1 Oct 2025 118,595.00 | 10 Oct 2025 106,735.00 | 9 | −$10.91 |
| short | 10 Oct 2025 112,775.00 | 25 Oct 2025 111,646.00 | 15 | $0.84 |
| long | 25 Oct 2025 111,646.00 | 3 Nov 2025 106,583.00 | 9 | −$4.61 |
| short | 3 Nov 2025 106,583.00 | 14 Nov 2025 95,924.70 | 11 | $9.33 |
| long | 26 Nov 2025 90,484.00 | 17 Dec 2025 86,243.20 | 21 | −$4.96 |
| short | 17 Dec 2025 86,243.20 | 20 Dec 2025 88,360.90 | 3 | −$2.56 |
| long | 20 Dec 2025 88,360.90 | 20 Jan 2026 88,427.70 | 31 | −$0.06 |
| short | 20 Jan 2026 88,427.70 | 31 Jan 2026 79,584.90 | 11 | $9.48 |
| long | 15 Feb 2026 68,832.60 | 22 Mar 2026 67,859.00 | 35 | −$1.62 |
| short | 22 Mar 2026 67,859.00 | 24 Mar 2026 71,251.90 | 2 | −$5.31 |
| long | 25 Mar 2026 71,336.50 | 26 Mar 2026 68,820.30 | 1 | −$3.60 |
| short | 26 Mar 2026 68,820.30 | 5 Apr 2026 69,034.20 | 10 | −$0.43 |
| long | 5 Apr 2026 69,034.20 | 28 Apr 2026 76,342.80 | 23 | $9.89 |
| short | 28 Apr 2026 76,342.80 | 4 May 2026 80,159.90 | 6 | −$5.33 |
| long | 4 May 2026 79,861.00 | 12 May 2026 80,504.50 | 8 | $0.66 |
| short | 12 May 2026 80,504.50 | 1 Jun 2026 72,454.00 | 20 | $9.81 |
| long | 13 Jun 2026 64,458.00 | 26 Jun 2026 60,097.30 | 13 | −$7.47 |
| short | 26 Jun 2026 60,097.30 | 1 Jul 2026 60,024.00 | 5 | −$0.02 |
| long | 1 Jul 2026 60,024.00 | 27 Jul 2026 63,755.90 | 26 | $6.17 |
| short | 27 Jul 2026 63,755.90 | 7 Aug 2026 64,923.20 | 11 | −$2.11 |
| long | 7 Aug 2026 64,923.20 | 11 Aug 2026 63,600.00 | 4 | −$2.29 |
| short | 11 Aug 2026 63,600.00 | 18 Aug 2026 64,725.40 | 7 | −$1.97 |
| long | 18 Aug 2026 64,725.40 | 2 Sep 2026 77,340.00 | 15 | $19.60 |
| short | 2 Sep 2026 77,340.00 | 4 Sep 2026 81,270.40 | 2 | −$6.22 |
| long | 20 Sep 2026 81,178.00 | 29 Sep 2026 83,663.70 | 9 | $3.31 |
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 |
|---|---|---|---|---|---|
| ZEGUELA DEMABOT this page | — | v4 strategy | +29.3% | 78 | 43.0% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 55 ms | Yes 1,000 bars in 140 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/// This code is based on the study you can find here: https://kodify.net/tradingview/indicators/dema/// ©zeguela//@version=4strategy(title="ZEGUELA DEMABOT", commission_value=0.070, commission_type=strategy.commission.percent, initial_capital=100, default_qty_value=90, default_qty_type=strategy.percent_of_equity, overlay=true, process_orders_on_close=true)// Step 1. Script settings// Input optionssrcData = input(title="Source Data", type=input.source, defval=close)// Length settingslen1 = input(title="Length DEMA #1", type=input.integer, defval=8, minval=1)len2 = input(title="Length DEMA #2", type=input.integer, defval=21, minval=0)len3 = input(title="Length DEMA #3", type=input.integer, defval=0, minval=0)// Step 2. Calculate indicator values// Function that calculates the DEMADEMA(series, length) => if (length > 0) emaValue = ema(series, length) 2 * emaValue - ema(emaValue, length) else na// Calculate the DEMA valuesdemaVal1 = DEMA(srcData, len1)demaVal2 = DEMA(srcData, len2)demaVal3 = DEMA(srcData, len3)// Step 3. Determine indicator signals// See if there's a DEMA crossoverdemaCrossover = if (len2 > 0) and (len3 > 0) crossover(demaVal1, demaVal2) and (demaVal3 > demaVal3[1])else if (len2 > 0) and (len3 == 0) crossover(demaVal1, demaVal2) else if (len3 > 0) and (len2 == 0) crossover(demaVal1, demaVal3) else crossover(close, demaVal1)// Check if there's a DEMA crossunderdemaCrossunder = if (len2 > 0) and (len3 > 0) crossunder(demaVal1, demaVal2) and (demaVal3 < demaVal3[1])else if (len2 > 0) and (len3 == 0) crossunder(demaVal1, demaVal2) else if (len3 > 0) and (len2 == 0) crossunder(demaVal1, demaVal3) else crossunder(close, demaVal1)// Step 4. Output indicator data// Plot DEMAs on the chartplot(series=demaVal1, color=color.green, linewidth=2, title="DEMA #1")plot(series=demaVal2, color=color.red, linewidth=2, title="DEMA #2")plot(series=demaVal3, color=color.fuchsia, linewidth=2, title="DEMA #3")// Step 5. Trailing Stop, Stop Loss and Take Profit calculation//TRAILING STOP CODEa = input(title="Usar Trailing Stop?", type=input.bool, defval=false)stopPerlong = input(10.0, title='Stop Loss Long %', type=input.float, group="Stop Loss & Take Profit Settings") / 100stopPershort = input(5.0, title='Stop Loss Short %', type=input.float, group="Stop Loss & Take Profit Settings") / 100take1Perlong = input(40.0, title='Take Profit Long % 1', type=input.float, group="Stop Loss & Take Profit Settings") / 100take1Pershort = input(10.0, title='Take Profit Short % 1', type=input.float, group="Stop Loss & Take Profit Settings") / 100// Determine stop loss pricelongStopPrice = strategy.position_avg_price * (1 - stopPerlong)shortStopPrice = strategy.position_avg_price * (1 + stopPershort)longTake1Price = strategy.position_avg_price * (1 + take1Perlong)shortTake1Price = strategy.position_avg_price * (1 - take1Pershort)// Determine trail stop loss priceslongStopPriceTrail = 0.0longStopPriceTrail := if (strategy.position_size > 0) stopValue = close * (1 - stopPerlong) max(stopValue, longStopPriceTrail[1])else 0// Determine trailing short priceshortStopPriceTrail = 0.0shortStopPriceTrail := if (strategy.position_size < 0) stopValue = close * (1 + stopPershort) min(stopValue, shortStopPriceTrail[1])else 999999//Calculate wich stop to uselongStop = a ? longStopPriceTrail : longStopPriceshortStop = a ? shortStopPriceTrail : shortStopPrice//Calculate SL and TP value to throw through alertlongStopEntrada = close * (1 - stopPerlong)shortStopEntrada = close * (1 + stopPershort) longTPEntrada = close * (1 + take1Perlong)shortTPEntrada = close * (1 - take1Pershort)//Save the SL and TP price for furter results calculationprice_entryL = 0.0price_entryL := na(price_entryL) ? na : price_entryL[1]price_entryS = 0.0price_entryS := na(price_entryS) ? na : price_entryS[1]stopL = 0.0stopL := na(stopL) ? na : stopL[1]stopS = 0.0stopS := na(stopS) ? na : stopS[1]takeL = 0.0takeL := na(takeL) ? na : takeL[1]takeS = 0.0takeS := na(takeS) ? na : takeS[1]if (demaCrossover) price_entryL := close stopL := close * (1 - stopPerlong) takeL := close * (1 + take1Perlong) if (demaCrossunder) price_entryS := close stopS := close * (1 + stopPershort) takeS := close * (1 - take1Pershort)//Calculate P&L resultsresultadoL = ((close - price_entryL)/price_entryL) * 100resultadoLexit = "(SL = 1% e TP = 0,5%)"resultadoS = ((price_entryS - close)/price_entryS) * 100resultadoSexit = "(SL = 1% e TP = 0,5)%"// Step 6. Strategy setup// Make input options that configure backtest date range_startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31, group="BackTest Period")_startMonth = input(title="Start Month", type=input.integer, defval=4, minval=1, maxval=12, group="BackTest Period")_startYear = input(title="Start Year", type=input.integer, defval=2021, minval=1800, maxval=2100, group="BackTest Period")_endDate = input(title="End Date", type=input.integer, defval=31, minval=1, maxval=31, group="BackTest Period")_endMonth = input(title="End Month", type=input.integer, defval=12, minval=1, maxval=12, group="BackTest Period")_endYear = input(title="End Year", type=input.integer, defval=2031, minval=1800, maxval=2100, group="BackTest Period")// Look if the close time of the current bar// falls inside the date range_inDateRange = (time >= timestamp(syminfo.timezone, _startYear, _startMonth, _startDate, 0, 0)) and (time < timestamp(syminfo.timezone, _endYear, _endMonth, _endDate, 0, 0)) //Alert configuration _alertMessageOpenLong="OpenLong"_alertMessageCloseLong="CloseLong"_alertmessageExitLong="ExitLong"_alertmessageTPLong="TakeProfitLong"_alertMessageOpenShort="OpenShort"_alertMessageCloseShort="CloseShort"_alertMessageTPShort="TakeProfitShort"_alertMessageExitShort="ExitShort"// Step 7. Strategy Executionif (_inDateRange) //ENTER SOME SETUP TRADES FOR TSL EXAMPLE if (demaCrossover) strategy.entry("LONG", strategy.long, comment = "OPEN LONG", alert_message=_alertMessageOpenLong) strategy.exit(id="Close Long TP1", stop=stopL, limit=takeL, comment="CLOSE LONG", alert_message=_alertmessageExitLong) if (demaCrossunder) strategy.entry("SHORT", strategy.short, comment = "OPEN SHORT", alert_message=_alertMessageOpenShort) strategy.exit(id="Close Short TP1", stop=stopS, limit=takeS, comment="CLOSE SHORT", alert_message=_alertMessageExitShort) //EXIT TRADE @ TSL if strategy.position_size > 0 strategy.exit("TP/SL", "LONG", stop=longStop, limit=longTake1Price, comment="EXIT LONG", alert_message=_alertmessageExitLong) if strategy.position_size < 0 strategy.exit("TP/SL", "SHORT", stop=shortStop, limit=shortTake1Price, comment ="EXIT SHORT", alert_message=_alertMessageExitShort)// Step 8. Chart look and feel//Look & Feel - Plot stop loss and take profit areasp1=plot(strategy.position_avg_price, color=color.blue, style=plot.style_linebr, linewidth=1, title="Entry Price")p2=plot(series=strategy.position_size > 0 ? longStop : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Long Stop")p3=plot(series=strategy.position_size > 0 ? longTake1Price : na, color=color.green, style=plot.style_linebr, linewidth=1, title="Long TP")p4=plot(series=strategy.position_size < 0 ? shortStop : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Short Stop")p5=plot(series=strategy.position_size < 0 ? shortTake1Price : na, color=color.green, style=plot.style_linebr, linewidth=1, title="Short TP")fill(p1, p2, color=color.red)fill(p1, p3, color=color.green)fill(p1, p4, color=color.red)fill(p1, p5, color=color.green)// Insert label with valuestopLossOnLong = "Stop Loss = " + tostring(longStop)stopLossOnShort = "Stop Loss = " + tostring(shortStop)takeprofitOnLong = "Take Profit = " + tostring(longTake1Price)takeprofitOnShort = "Take Profit = " + tostring(shortTake1Price)precoentrada = "Entry Price = " + tostring(strategy.position_avg_price)var label FinalLabelpriceL = navar label FinalLabelpriceS = navar label slFinalLabelL = navar label slFinalLabelS = navar label slFinalLabelTPL = navar label slFinalLabelTPS = na//Draw entry and stop loss lines and labelsif strategy.position_size > 0 //write the price above the end of the stoploss line slFinalLabelL := label.new(bar_index, longStop, stopLossOnLong, style=label.style_none, size=size.normal, textcolor=color.red) slFinalLabelTPL := label.new(bar_index, longTake1Price, takeprofitOnLong, style=label.style_none, size=size.normal, textcolor=color.green) FinalLabelpriceL := label.new(bar_index, strategy.position_avg_price, precoentrada, style=label.style_none, size=size.normal, textcolor=color.blue) // Delete previous label when there is a consecutive new high, as there's no line plot in that case. if strategy.position_size > 0[1] label.delete(slFinalLabelL[1]) label.delete(slFinalLabelTPL[1]) label.delete(FinalLabelpriceL[1])if strategy.position_size < 0 //write the price above the end of the stoploss line slFinalLabelS := label.new(bar_index, shortStop, stopLossOnShort, style=label.style_none, size=size.normal, textcolor=color.red) slFinalLabelTPS := label.new(bar_index, shortTake1Price, takeprofitOnShort, style=label.style_none, size=size.normal, textcolor=color.green) FinalLabelpriceS := label.new(bar_index, strategy.position_avg_price, precoentrada, style=label.style_none, size=size.normal, textcolor=color.blue) // Delete previous label when there is a consecutive new high, as there's no line plot in that case. if strategy.position_size < 0[1] label.delete(slFinalLabelS[1]) label.delete(slFinalLabelTPS[1]) label.delete(FinalLabelpriceS[1]) // Exit open market position when date range endsif (not _inDateRange) strategy.close_all()//Plot the box with position and P&LposColor = color.new(color.green, 75)negColor = color.new(color.red, 75)dftColor = color.new(color.blue, 75)posProfit= (strategy.position_size > 0) ? (close * 100 / strategy.position_avg_price - 100) : strategy.position_size < 0 ? (strategy.position_avg_price * 100 / close - 100) : 0.0posDir = (strategy.position_size > 0) ? "long" : strategy.position_size < 0 ? "short" : "flat"posCol = (posProfit > 0) ? posColor : (posProfit < 0) ? negColor : dftColorvar label lb = nalabel.delete(lb)lb := label.new(bar_index, max(high, highest(4)[1]), textcolor=color.white, color=posCol, text="Pos: "+ posDir + "\nPnL: "+tostring(posProfit, "#.##")+"%" + "\nAvg Price: "+tostring(strategy.position_avg_price, "#.####") + "\nClose: "+tostring(close, "#.####"))