Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MA Strength Strategy

A Pine Script v4 strategy built on SMA or EMA or HMA or RMA or VWMA or WMA (source, length), Crossunder (upwardSum, indexSma) and Crossover (upwardSum, indexSma). 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 100% of equity and pays 0.01% commission. 10 settings; defaults include Moving Average Type ema, Lookback Period 10 and Moving Average Type hma.

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 MA Strength Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did MA Strength Strategy do on BTCUSDT 1D with default settings?
+71.34%
From 26 Jan 2024 to 21 Oct 2026, over 13 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can MA Strength 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 MA Strength Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does MA Strength Strategy run in Zeal Terminal?
Yes
It compiles in 29 ms and runs 1,000 bars in 131 ms, in the browser.

BTCUSDT · 1D · default settings

  • Moving Average Strength
  • Strength MA
  • 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 (10)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctMoving Average Strength$34,268$40,505Equity from $20,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
+71.34%
$14,268.70
Buy and hold
+102.5%
same period
Closed trades
13
5 won · 8 lost
Profitable
38.5%
of closed trades
Profit factor
2.16
gross profit ÷ gross loss
Max drawdown
32.07%
−$12,746.70

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

    5 settings have no label

    In the settings dialog LookbackPeriod (line 6), IndexMAPeriod (line 8), considerTrendDirection (line 9), considerTrendDirectionForExit (line 10), offset (line 11) show an empty name. The labels on this page come from the variable names.

  • 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 63, 64, 65, 66. The upgraded version below moves each call inside an if block.

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 sma → ta.sma, ema → ta.ema, hma → ta.hma, rma → ta.rma, vwma → ta.vwma, wma → ta.wma, sum → math.sum, crossover → ta.crossover, crossunder → ta.crossunder.
  • 4 strategy calls use the when = argument (line 63, 64, 65, 66). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 13: input(type = input.time) → input.time()
  • Line 14: input(type = input.time) → input.time()
  • Line 17: sma → ta.sma
  • Line 19: ema → ta.ema
  • Line 21: hma → ta.hma
8 more edits
  • Line 23: rma → ta.rma
  • Line 25: vwma → ta.vwma
  • Line 27: wma → ta.wma
  • Line 54: sum → math.sum
  • Line 58: crossover → ta.crossover
  • Line 59: crossunder → ta.crossunder
  • Line 60: crossunder → ta.crossunder
  • Line 61: crossover → ta.crossover
⋯// © HeWhoMustNotBeNamed-//@version=4+//@version=5strategy("MA Strength Strategy", overlay=false, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])-i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)+i_startTime = input.time(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time")-i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)+i_endTime = input.time(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time")inDateRange = time >= i_startTime and time <= i_endTimef_getMovingAverage(source, MAType, length)=>-    ma = sma(source, length)+    ma = ta.sma(source, length)    if(MAType == "ema")-        ma := ema(source,length)+        ma := ta.ema(source,length)    if(MAType == "hma")-        ma := hma(source,length)+        ma := ta.hma(source,length)    if(MAType == "rma")-        ma := rma(source,length)+        ma := ta.rma(source,length)    if(MAType == "vwma")-        ma := vwma(source,length)+        ma := ta.vwma(source,length)    if(MAType == "wma")-        ma := wma(source,length)+        ma := ta.wma(source,length)    ma⋯[trendStrength, upwardScore] = f_getMaAlignment(MAType, includePartiallyAligned)-upwardSum = sum(upwardScore, LookbackPeriod)+upwardSum = math.sum(upwardScore, LookbackPeriod)indexSma = f_getMovingAverage(upwardSum,IndexMAType,IndexMAPeriod)⋯plot(indexSma, title="Strength MA", color=color.red, linewidth=1, style=plot.style_linebr)-buyCondition = crossover(upwardSum,indexSma) and (upwardSum > upwardSum[offset] or not considerTrendDirection) +buyCondition = ta.crossover(upwardSum,indexSma) and (upwardSum > upwardSum[offset] or not considerTrendDirection) -sellCondition = crossunder(upwardSum,indexSma) and (upwardSum < upwardSum[offset]  or not considerTrendDirection)+sellCondition = ta.crossunder(upwardSum,indexSma) and (upwardSum < upwardSum[offset]  or not considerTrendDirection)-exitBuyCondition = crossunder(upwardSum,indexSma)+exitBuyCondition = ta.crossunder(upwardSum,indexSma)-exitSellCondition = crossover(upwardSum,indexSma) +exitSellCondition = ta.crossover(upwardSum,indexSma) strategy.risk.allow_entry_in(tradeDirection)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.string()
  • Line 6: input() → input.int()
  • Line 7: input() → input.string()
  • Line 8: input() → input.int()
  • Line 9: input() → input.bool()
  • Line 10: input() → input.bool()
5 more edits
  • Line 11: input() → input.int()
  • Line 63: when = inDateRange and buyCondition → if block
  • Line 64: when = considerTrendDirectionForExit? sellCondition : exitBuyCondition → if block
  • Line 65: when = inDateRange and sellCondition → if block
  • Line 66: when = considerTrendDirectionForExit? buyCondition : exitSellCondition → if block
⋯strategy("MA Strength Strategy", overlay=false, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)-MAType = input(title="Moving Average Type", defval="ema", options=["ema", "sma", "hma", "rma", "vwma", "wma"])+MAType = input.string(title="Moving Average Type", defval="ema", options=["ema", "sma", "hma", "rma", "vwma", "wma"])-LookbackPeriod = input(10, step=10)+LookbackPeriod = input.int(10, step=10)-IndexMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])+IndexMAType = input.string(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])-IndexMAPeriod = input(200, step=10)+IndexMAPeriod = input.int(200, step=10)-considerTrendDirection = input(true)+considerTrendDirection = input.bool(true)-considerTrendDirectionForExit = input(true)+considerTrendDirectionForExit = input.bool(true)-offset = input(1, step=1)+offset = input.int(1, step=1)tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])⋯strategy.risk.allow_entry_in(tradeDirection)-strategy.entry("Buy", strategy.long, when= inDateRange and buyCondition, oca_name="oca_buy", oca_type=strategy.oca.cancel)+if inDateRange and buyCondition+    strategy.entry("Buy", strategy.long, oca_name="oca_buy", oca_type=strategy.oca.cancel)-strategy.close("Buy", when = considerTrendDirectionForExit? sellCondition : exitBuyCondition)+if considerTrendDirectionForExit? sellCondition : exitBuyCondition+    strategy.close("Buy")-strategy.entry("Sell", strategy.short, when= inDateRange and sellCondition, oca_name="oca_sell", oca_type=strategy.oca.cancel)+if inDateRange and sellCondition+    strategy.entry("Sell", strategy.short, oca_name="oca_sell", oca_type=strategy.oca.cancel)-strategy.close( "Sell", when = considerTrendDirectionForExit? buyCondition : exitSellCondition)+if considerTrendDirectionForExit? buyCondition : exitSellCondition+    strategy.close( "Sell")

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

⋯// © HeWhoMustNotBeNamed-//@version=5+//@version=6strategy("MA Strength Strategy", overlay=false, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯

Settings

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

SettingDefaultType and rangeFeeds
Moving Average Typeemastring · options ["ema", "sma", "hma", "rma", "vwma", "wma"]ma5 ma10 ma20 ma30 ma50 ma100 ma200 upwardScore trendStrength line 18 line 20 line 22 line 24 line 26
Lookback Period (no label in the script)10int · step 10upwardSum
Moving Average Typehmastring · options ["ema", "sma", "hma", "rma", "vwma", "wma"]indexSma
Index MAPeriod (no label in the script)200int · step 10indexSma
Consider Trend Direction (no label in the script)trueboolbuyCondition sellCondition
Consider Trend Direction For Exit (no label in the script)trueboolclose Buy close Sell
Offset (no label in the script)1int · step 1buyCondition sellCondition
Trade Directionstrategy.direction.longvalue · options [strategy.direction.all, strategy.direction.long, strategy.direction.short]line 62
Start Timetimestamp("01 Jan 2010 00:00 +0000")timeinDateRange
End Timetimestamp("01 Jan 2099 00:00 +0000")timeinDateRange

What it calculates

  • SMA / EMA / HMA / RMA / VWMA / WMA (sma, ta.sma in v5)source, lengthma · line 17
  • Crossunder (crossunder, ta.crossunder in v5)upwardSum, indexSmaexitBuyCondition · line 60
  • Crossover (crossover, ta.crossover in v5)upwardSum, indexSmaexitSellCondition · line 61

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 dataMATypeMoving Average Typesetting · emaLookbackPeriodLookback Periodsetting · 10IndexMATypeMoving Average Typesetting · hmaIndexMAPeriodIndex MAPeriodsetting · 200timetimeprice datai_startTimeStart Timesetting · timestamp("01 Jan 2…i_endTimeEnd Timesetting · timestamp("01 Jan 2…offsetOffsetsetting · 1maSMA / EMA / HMA / RMA /…→ maexitBuyConditionCrossunder→ exitBuyConditionexitSellConditionCrossover→ exitSellConditionma5, ma10, ma20, ma30, ma50, ma100, ma200ma5 · ma10 +57 valuesupwardScore, trendStrengthupwardScore · trendStre…2 valuesupwardSumupwardSumvalueindexSmaindexSmavalueinDateRangeinDateRangeconditionupwards, downwardsupwards · downwards2 conditionsbuyCondition, sellConditionbuyCondition · sellCond…2 conditionsentry:BuyOpen Buystrategy.entryclose:BuyClose Buystrategy.closeentry:SellOpen Sellstrategy.entryclose:SellClose Sellstrategy.closeplot:56Moving Average Strengthplotplot:57Strength MAplot

Order rules

OrderFires whenBy defaultLine
Open Buy longinDateRange and buyConditionOn63
Close BuyconsiderTrendDirectionForExit? sellCondition : exitBuyConditionOn64
Open Sell shortinDateRange and sellConditionOn65
Close SellconsiderTrendDirectionForExit? buyCondition : exitSellConditionOn66

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.

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.
  • 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+71.3%+102.5%1338%2.1632.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+24.0%+5.5%1233%2.736.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+141.6%+9.8%956%4.5533.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+16.7%+8.4%1533%1.7010.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+84.9%+16.7%1145%2.0931.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+50.3%+21.5%956%4.0711.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−7.5%+148.3%933%0.8335.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+7.7%+17.1%1242%1.565.8%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 market333%$1,616.46
Sideways market540%$5,343.68
Falling market540%$7,308.60

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

How bad could the drawdown be?

27.1%

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

0%31%
All 13 trades
SideEntryExitBarsP&L
long19 Sep 2024 61,760.004 Dec 2024 95,849.7076$11,033.20
long25 Jan 2025 104,871.0029 Jan 2025 101,336.004−$1,052.07
long30 Jan 2025 103,733.001 Feb 2025 102,430.002−$382.71
long15 Apr 2025 84,591.6019 Jun 2025 104,887.0065$7,093.91
long3 Jul 2025 108,850.0019 Jul 2025 117,925.0016$3,051.25
long18 Sep 2025 116,448.0028 Sep 2025 109,636.0010−$2,332.33
long6 Oct 2025 123,482.0019 Oct 2025 107,185.0013−$4,944.07
long31 Dec 2025 88,485.5031 Jan 2026 84,260.5031−$1,556.42
long22 Feb 2026 67,975.9025 Feb 2026 64,058.203−$1,787.36
long26 Feb 2026 67,988.0020 May 2026 76,834.4083$3,782.83
long11 Jul 2026 64,161.705 Aug 2026 64,106.6025−$34.87
long9 Aug 2026 64,962.6018 Aug 2026 64,532.109−$224.36
long22 Aug 2026 78,338.0016 Oct 2026 82,245.9055$1,621.74

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
MA Strength Strategy this page—v4 strategy+71.3%1332.1%
Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalaisma ema hma vwma rmav5 strategy+1.3%1135.6%
High-Low Channel Multi averages Crypto Swing strategy by exlux99sma ema wma rma vwmav4 strategyNo trades on this market
Ultra Moving Average Rating Trend Strategy by exlux99ema wma sma rma vwma hmav5 strategy+2.8%52.4%
VCP pivot buy by perrycc007sma ema rma vwma wmav4 strategydoes not run in Zeal Terminal
Multi Trend Cross Strategy Template by TradeAutomationema hma rma sma vwma wmav5 strategy+33.0%37.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 29 msYes 1,000 bars in 131 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/// © HeWhoMustNotBeNamed//@version=4strategy("MA Strength Strategy", overlay=false, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)MAType = input(title="Moving Average Type", defval="ema", options=["ema", "sma", "hma", "rma", "vwma", "wma"])LookbackPeriod = input(10, step=10)IndexMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])IndexMAPeriod = input(200, step=10)considerTrendDirection = input(true)considerTrendDirectionForExit = input(true)offset = input(1, step=1)tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)inDateRange = time >= i_startTime and time <= i_endTimef_getMovingAverage(source, MAType, length)=>    ma = sma(source, length)    if(MAType == "ema")        ma := ema(source,length)    if(MAType == "hma")        ma := hma(source,length)    if(MAType == "rma")        ma := rma(source,length)    if(MAType == "vwma")        ma := vwma(source,length)    if(MAType == "wma")        ma := wma(source,length)    ma    f_getMaAlignment(MAType, includePartiallyAligned)=>    ma5 = f_getMovingAverage(close,MAType,5)    ma10 = f_getMovingAverage(close,MAType,10)    ma20 = f_getMovingAverage(close,MAType,20)    ma30 = f_getMovingAverage(close,MAType,30)    ma50 = f_getMovingAverage(close,MAType,50)    ma100 = f_getMovingAverage(close,MAType,100)    ma200 = f_getMovingAverage(close,MAType,200)    upwardScore = 0.0    upwardScore := close > ma5? upwardScore+1.10:upwardScore    upwardScore := ma5 > ma10? upwardScore+1.10:upwardScore    upwardScore := ma10 > ma20? upwardScore+1.10:upwardScore    upwardScore := ma20 > ma30? upwardScore+1.10:upwardScore    upwardScore := ma30 > ma50? upwardScore+1.15:upwardScore    upwardScore := ma50 > ma100? upwardScore+1.20:upwardScore    upwardScore := ma100 > ma200? upwardScore+1.25:upwardScore        upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200    downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200    trendStrength = upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 6? 0.5: upwardScore < 2?-0.5:upwardScore>4?0.25:-0.25) : 0    [trendStrength, upwardScore]    includePartiallyAligned = true[trendStrength, upwardScore] = f_getMaAlignment(MAType, includePartiallyAligned)upwardSum = sum(upwardScore, LookbackPeriod)indexSma = f_getMovingAverage(upwardSum,IndexMAType,IndexMAPeriod)plot(upwardSum, title="Moving Average Strength", color=color.green, linewidth=2, style=plot.style_linebr)plot(indexSma, title="Strength MA", color=color.red, linewidth=1, style=plot.style_linebr)buyCondition = crossover(upwardSum,indexSma) and (upwardSum > upwardSum[offset] or not considerTrendDirection) sellCondition = crossunder(upwardSum,indexSma) and (upwardSum < upwardSum[offset]  or not considerTrendDirection)exitBuyCondition = crossunder(upwardSum,indexSma)exitSellCondition = crossover(upwardSum,indexSma) strategy.risk.allow_entry_in(tradeDirection)strategy.entry("Buy", strategy.long, when= inDateRange and buyCondition, oca_name="oca_buy", oca_type=strategy.oca.cancel)strategy.close("Buy", when = considerTrendDirectionForExit? sellCondition : exitBuyCondition)strategy.entry("Sell", strategy.short, when= inDateRange and sellCondition, oca_name="oca_sell", oca_type=strategy.oca.cancel)strategy.close( "Sell", when = considerTrendDirectionForExit? buyCondition : exitSellCondition)