Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

twisted SMA strategy [4h]

A Pine Script v5 strategy built on SMA (close, 4) and Change (close, 25). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.03% commission. 6 settings; defaults include 1-SMA Lenght 4, 2-SMA Lenght 9 and 3-SMA Lenght 18.

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 twisted SMA strategy [4h] repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
How did twisted SMA strategy [4h] do on BTCUSDT 1D with default settings?
+21.49%
From 26 Jan 2024 to 21 Oct 2026, over 9 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does twisted SMA strategy [4h] 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: 9 before, 12 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does twisted SMA strategy [4h] use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does twisted SMA strategy [4h] run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 31 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • SMA
  • SMA
  • SMA
  • Change
  • Change
  • 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$12,150$20,253Equity from $10,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
+21.49%
$2,149.47
Buy and hold
+102.5%
same period
Closed trades
9
5 won · 4 lost
Profitable
55.6%
of closed trades
Profit factor
1.62
gross profit ÷ gross loss
Max drawdown
19.22%
−$2,218.11

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

    Uses an argument v6 removed

    when = on line 34. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
SMA
1-SMA Lenght4int · min 1SMA1
2-SMA Lenght9int · min 1SMA2
3-SMA Lenght18int · min 1SMA3
SMA Lenght100int · min 1SMAas
Lenght25inter per
Self Poweredtrueboolpow

What it calculates

  • SMAclose, 1-SMA Lenght (4)SMA1 · line 9
  • SMAclose, 2-SMA Lenght (9)SMA2 · line 10
  • SMAclose, 3-SMA Lenght (18)SMA3 · line 11
  • SMAsrc, SMA Lenght (100)SMAas · line 15
  • Changeclose, Lenght (25)er · line 19
  • Changeclose, Lenght (25)per · line 21

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 dataLength1 1-SMA Lenghtsetting · 4Length2 2-SMA Lenghtsetting · 9Length3 3-SMA Lenghtsetting · 18LengthMainSMA SMA Lenghtsetting · 100lengthas Lenghtsetting · 25SMA1SMA→ SMA1SMA2SMA→ SMA2SMA3SMA→ SMA3SMAasSMA→ SMAaserChange→ erperChange→ persrcsrcvaluepowpowvalueaavaluelong_stoplong_stopvaluelong_condlong_condconditionLong_ma, Short_maLong_ma · Short_ma2 conditionsa_fa_fconditionBar_colorColourBar_colorentry:BUYOpen BUYstrategy.entryclose_all:close_all strategy.close_allbarcolor:28barcolorbarcolor

Order rules

OrderFires whenBy defaultLine
Open BUY longlong_condOn33
Close long_stopOn34

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.

3/3trades 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+21.5%+102.5%956%1.6219.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+22.3%+5.5%540%9.323.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+42.5%+9.8%863%2.5114.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+14.8%+8.4%757%3.426.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−55.0%+16.7%1217%0.2359.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+23.7%+21.5%838%2.5910.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−17.3%+148.3%1040%0.6732.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.9%+17.1%825%1.329.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 market250%−$446.36
Sideways market757%$2,595.83
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?

26.9%

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

0%31%
All 9 trades
SideEntryExitBarsP&L
long29 Jul 2024 68,249.904 Aug 2024 60,698.006−$1,111.84
long27 Sep 2024 65,174.006 Oct 2024 62,058.009−$430.02
long29 Oct 2024 69,962.2025 Dec 2024 98,663.6057$3,462.72
long2 May 2025 96,489.903 Jun 2025 105,858.0032$1,149.54
long11 Jul 2025 116,010.0029 Jul 2025 118,062.0018$223.25
long5 Oct 2025 122,391.0016 Oct 2025 110,763.0011−$1,270.17
long22 Apr 2026 76,336.1019 May 2026 77,001.9027$97.58
long21 Aug 2026 73,027.0013 Sep 2026 77,278.7023$698.02
long23 Sep 2026 86,208.609 Oct 2026 81,754.5016−$669.61

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
twisted SMA strategy [4h] this page—v5 strategy+21.5%919.2%
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%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 1 strategy call uses the when = argument (line 34). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 34: when = long_stop → if block
⋯    strategy.entry('BUY', strategy.long)-strategy.close_all(when=long_stop)+if long_stop+    strategy.close_all()//by wielkieef

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: 9 before, 12 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.

⋯// © Wielkieef-//@version=5+//@version=6strategy(title='twisted SMA strategy [4h] ', overlay=true, pyramiding=1, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0.03)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msYes 1,000 bars in 31 msNot measured
PineTSNot testedNot testedNot 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.

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/// © Wielkieef//@version=5strategy(title='twisted SMA strategy [4h] ', overlay=true, pyramiding=1, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0.03)src = closeLength1 = input.int(4, title='  1-SMA Lenght', minval=1, group='SMA')Length2 = input.int(9, title='  2-SMA Lenght', minval=1, group='SMA')Length3 = input.int(18, title='  3-SMA Lenght', minval=1, group='SMA')SMA1 = ta.sma(close, Length1)SMA2 = ta.sma(close, Length2)SMA3 = ta.sma(close, Length3)Long_ma = SMA1 > SMA2 and SMA2 > SMA3Short_ma = SMA1 < SMA2 and SMA2 < SMA3LengthMainSMA = input.int(100, title='  SMA Lenght', minval=1)SMAas = ta.sma(src, LengthMainSMA)//  Powered Kaufman Adaptive Moving Average by alexgrover (modificated by Wielkieef)lengthas = input.int(25, title='    Lenght')sp = input.bool(true, title='  Self Powered')er = math.abs(ta.change(close, lengthas)) / math.sum(math.abs(ta.change(close)), lengthas)pow = sp ? 1 / er : 2per = math.pow(math.abs(ta.change(close, lengthas)) / math.sum(math.abs(ta.change(close)), lengthas), pow)a = 0.a := per * src + (1 - per) * nz(a[1], src)mad4h = 0.a_f = a / a[1] > .999 and a / a[1] < 1.001///.Bar_color = close > SMAas ? color.green : Long_ma ? color.blue : Short_ma ? color.maroon : color.graybarcolor(color=Bar_color)long_cond = Long_ma and SMAas < close and not a_f  long_stop = Short_ma if  long_cond    strategy.entry('BUY', strategy.long)strategy.close_all(when=long_stop)//by wielkieef