Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

AlphaTrend For ProfitView

A Pine Script v5 strategy built on SMA (ta.tr, 15), RSI or MFI (close, 15) and Crossover (AlphaTrend, AlphaTrend[2]). It has 3 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. 12 settings; defaults include Multiplier 1.5 and Common Period 15.

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 AlphaTrend For ProfitView repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did AlphaTrend For ProfitView do on BTCUSDT 1D with default settings?
−26.47%
From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does AlphaTrend For ProfitView have?
4
pv_alert_long + "(" + exsym + "acc=" + pv_acc + ")"; pv_alert_short + "(" + exsym + "acc=" + pv_acc + ")"; <![Alert Test]!>\n" + pv_alert_long + "(" + exsym + "acc=" + pv_acc + "); <![Alert Test]!>\n" + pv_alert_short + "(" + exsym + "acc=" + pv_acc + ").
Does AlphaTrend For ProfitView 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: 14 before, 29 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 AlphaTrend For ProfitView use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • 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 (12)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$853$2,025Equity from $1,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
−26.47%
−$264.68
Buy and hold
+102.5%
same period
Closed trades
14
5 won · 9 lost
Profitable
35.7%
of closed trades
Profit factor
0.65
gross profit ÷ gross loss
Max drawdown
57.06%
−$582.76

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

    when = on line 38, 39. 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
Multiplier1.5float · step 0.1upT downT
Common Period15intATR AlphaTrend
Change calculation (no volume data)?falseboolAlphaTrend
Allow shortingtrueboolentry Short close Long
Backtesting
Backtesting Start Timetimestamp("01 Jan 2014 00:00 +0000")timetimeCond
Backtesting End Timetimestamp("01 Jan 2100 23:59 +0000")timetimeCond
PV Settings
ExchangeLeave empty to use the chart ticker instead (Warning: May differ from actual market name in some instances)stringexsym
SymbolLeave empty to use the chart ticker instead (Warning: May differ from actual market name in some instances)stringexsym
Accountstringalert
PV Alert Name Longsstringalert
PV Alert Name Shortsstringalert
Test AlertsWill immediately execute the alerts, so you may see what it sends. The first line on these test alerts will be excluded from any real alert triggersfalseboolline 42

What it calculates

  • SMAta.tr, Common Period (15)ATR · line 9
  • RSI / MFIclose, Common Period (15)AlphaTrend · line 24
  • CrossoverAlphaTrend, AlphaTrend[2]buySignalk · line 27
  • CrossunderAlphaTrend, AlphaTrend[2]sellSignalk · line 28

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.

high · low · closehigh · low · closeprice dataAPCommon Periodsetting · 15hlc3hlc3price dataclosecloseprice datalowlowprice datacoeffMultipliersetting · 1.5highhighprice datapv_exExchangesetting · pv_symSymbolsetting · timetimeprice datai_startTimeBacktesting Start Timesetting · timestamp("01 Jan 2…i_endTimeBacktesting End Timesetting · timestamp("01 Jan 2…pv_alert_longPV Alert Name Longssetting · pv_accAccountsetting · pv_alert_shortPV Alert Name Shortssetting · ATRSMA→ ATRAlphaTrendRSI / MFI→ AlphaTrendbuySignalkCrossover→ buySignalksellSignalkCrossunder→ sellSignalkupTupTvaluedownTdownTvalueexsymexsymvaluetimeCondtimeCondconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose:LongClose Longstrategy.closeplot:25plotplotplot:26plotplotalert:36alertalertalert:40alertalertalert:43alertalertalert:44alertalert

Order rules

OrderFires whenBy defaultLine
Open Long longstrategy.position_size <= 0 and buySignalkOn35
Open Short shortcanshortOn38
Close Longnot canshortOn39

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
(no title)alertpv_alert_long + "(" + exsym + "acc=" + pv_acc + ")"36
(no title)alertpv_alert_short + "(" + exsym + "acc=" + pv_acc + ")"40
(no title)alert<![Alert Test]!>\n" + pv_alert_long + "(" + exsym + "acc=" + pv_acc + ")43
(no title)alert<![Alert Test]!>\n" + pv_alert_short + "(" + exsym + "acc=" + pv_acc + ")44

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

Not measuredAn engine gap, not the scriptThe script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script. The answer comes from the checks on the source alone.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−26.5%+102.5%1436%0.6557.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.4%+5.5%1833%0.9912.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+43.4%+9.8%1258%1.4246.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+40.2%+8.4%1050%2.5016.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−84.3%+16.7%1833%0.2490.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+8.7%+21.5%1540%1.1432.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+85.5%+148.3%1040%1.7843.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−11.3%+17.1%1429%0.7117.7%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%−$256.99
Sideways market1136%−$6.95
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?

61.0%

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

0%70%
All 14 trades
SideEntryExitBarsP&L
long27 Feb 2024 57,037.301 May 2024 58,365.0064$21.23
short1 May 2024 58,365.0021 May 2024 70,148.3020−$208.43
long21 May 2024 70,148.3022 Jun 2024 64,262.0032−$69.80
short22 Jun 2024 64,262.0020 Jul 2024 67,140.0028−$34.79
long20 Jul 2024 67,140.005 Aug 2024 54,018.8016−$139.70
short5 Aug 2024 54,018.8020 Sep 2024 63,201.1046−$97.87
long20 Sep 2024 63,201.1025 Feb 2025 88,680.40158$188.69
short25 Feb 2025 88,680.4023 Apr 2025 93,691.1057−$38.61
long23 Apr 2025 93,691.1030 Aug 2025 108,816.00129$98.88
short30 Aug 2025 108,816.002 Oct 2025 120,529.0033−$78.97
long2 Oct 2025 120,529.0017 Oct 2025 106,432.0015−$76.16
short17 Oct 2025 106,432.0017 Mar 2026 73,909.40151$171.53
long17 Mar 2026 73,909.4028 May 2026 73,617.5072−$4.37
short28 May 2026 73,617.5020 Aug 2026 73,025.1084$4.43

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
AlphaTrend For ProfitView this page—v5 strategy−26.5%1457.1%
CCU MFI + RSI + STOCH RSI by Bangsoulmfi rsi smav4 strategy+41.8%637.4%
3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders by ggekko21rsi sma mfiv5 strategyNo trades on this market
SRJ RSI Outperformer Strategy by Sapt_Jashrsi smav5 strategy+0.6%82.4%
RSI SMA Crossover Strategy by reeesrsi smav5 strategy+39.8%4230.8%
Short In Downtrend Below MA100 (Coinrule) by Coinrulesma rsiv4 strategy−34.5%9945.4%

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.

  • 2 strategy calls use the when = argument (line 38, 39). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 2 settings use the untyped input() (line 8, 10). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.int()
  • Line 10: input() → input.bool()
  • Line 38: when = canshort → if block
  • Line 39: when = not canshort → if block
⋯coeff = input.float(1.5, 'Multiplier', step=0.1)-AP = input(15, 'Common Period')+AP = input.int(15, 'Common Period')ATR = ta.sma(ta.tr, AP)-novolumedata = input(title='Change calculation (no volume data)?', defval=false)+novolumedata = input.bool(title='Change calculation (no volume data)?', defval=false)canshort = input.bool(true, title="Allow shorting")⋯    if strategy.position_size >= 0 and sellSignalk-        strategy.entry("Short", strategy.short, when=canshort)+        if canshort+            strategy.entry("Short", strategy.short)-        strategy.close("Long", when=not canshort)+        if not canshort+            strategy.close("Long")        alert(pv_alert_short + "(" + exsym + "acc=" + pv_acc + ")", alert.freq_once_per_bar_close)⋯

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

⋯// pv additions, simplification and strategy conversion @ treigen-//@version=5+//@version=6strategy('AlphaTrend For ProfitView', overlay=true, calc_on_every_tick=true, process_orders_on_close=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, initial_capital=1000)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 24 msYes 1,000 bars in 52 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/// author © KivancOzbilgic// developer © KivancOzbilgic// pv additions, simplification and strategy conversion @ treigen//@version=5strategy('AlphaTrend For ProfitView', overlay=true, calc_on_every_tick=true, process_orders_on_close=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, initial_capital=1000)coeff = input.float(1.5, 'Multiplier', step=0.1)AP = input(15, 'Common Period')ATR = ta.sma(ta.tr, AP)novolumedata = input(title='Change calculation (no volume data)?', defval=false)canshort = input.bool(true, title="Allow shorting")i_startTime = input.time(defval = timestamp("01 Jan 2014 00:00 +0000"), title = "Backtesting Start Time", inline="timestart", group='Backtesting')i_endTime = input.time(defval = timestamp("01 Jan 2100 23:59 +0000"), title = "Backtesting End Time", inline="timeend", group='Backtesting')timeCond = (time > i_startTime) and (time < i_endTime)pv_ex = input.string('', title='Exchange', tooltip='Leave empty to use the chart ticker instead (Warning: May differ from actual market name in some instances)', group='PV Settings')pv_sym = input.string('', title='Symbol', tooltip='Leave empty to use the chart ticker instead (Warning: May differ from actual market name in some instances)', group='PV Settings')pv_acc = input.string("", title="Account", group='PV Settings')pv_alert_long = input.string("", title="PV Alert Name Longs", group='PV Settings')pv_alert_short = input.string("", title="PV Alert Name Shorts", group='PV Settings')pv_alert_test = input.bool(false, title="Test Alerts", tooltip="Will immediately execute the alerts, so you may see what it sends. The first line on these test alerts will be excluded from any real alert triggers" ,group='PV Settings')upT = low - ATR * coeffdownT = high + ATR * coeffAlphaTrend = 0.0AlphaTrend := (novolumedata ? ta.rsi(close, AP) >= 50 : ta.mfi(hlc3, AP) >= 50) ? upT < nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT : downT > nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : downTk1 = plot(AlphaTrend, color=color.new(#0022FC, 0), linewidth=3)k2 = plot(AlphaTrend[2], color=color.new(#FC0400, 0), linewidth=3)buySignalk = ta.crossover(AlphaTrend, AlphaTrend[2])sellSignalk = ta.crossunder(AlphaTrend, AlphaTrend[2])var exsym = ""if barstate.isfirst    exsym := pv_ex == "" ? "" : "ex=" + pv_ex + ","    exsym := pv_sym == "" ? exsym : exsym + "sym=" + pv_sym + ","if barstate.isconfirmed and timeCond     if strategy.position_size <= 0 and buySignalk        strategy.entry("Long", strategy.long)        alert(pv_alert_long + "(" + exsym + "acc=" + pv_acc + ")", alert.freq_once_per_bar_close)    if strategy.position_size >= 0 and sellSignalk        strategy.entry("Short", strategy.short, when=canshort)        strategy.close("Long", when=not canshort)        alert(pv_alert_short + "(" + exsym + "acc=" + pv_acc + ")", alert.freq_once_per_bar_close)//  Only used for testing/debugging alert messagesif pv_alert_test    alert("<![Alert Test]!>\n" + pv_alert_long + "(" + exsym + "acc=" + pv_acc + ")", alert.freq_once_per_bar)    alert("<![Alert Test]!>\n" + pv_alert_short + "(" + exsym + "acc=" + pv_acc + ")", alert.freq_once_per_bar)