Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

PCT Trailing Stoploss-Strategy

A Pine Script v5 strategy built on EMA (close, 14), Valuewhen (buyAlert, close) and Crossunder (close, alertSellValueLow). 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 is one contract and pays no commission. 9 settings; defaults include Stop Loss Loss: 1% = .01 .035, Trailing Stop Arm: 1%=.01 .0065 and Trailing Stop Trigger: 1%=.01 .003.

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 PCT Trailing Stoploss-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 PCT Trailing Stoploss-Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings; it opened a long position that was still open on the last bar, so there is no result to report. It closed no trades on the other markets either. A backtest, not investment advice.
What alerts does PCT Trailing Stoploss-Strategy have?
2
Buy; Sell.
Does PCT Trailing Stoploss-Strategy 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: 0 before, 1 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 PCT Trailing Stoploss-Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • EMA
  • EMA
  • EMA
  • TSL Armed
  • Buy
  • Sell
  • 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 (9)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,020,550$2,025,273Equity from $1,000,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
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
1.16%
−$11,607.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

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

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

SettingDefaultType and rangeFeeds
Sell Settings
Stop Loss Loss: 1% = .01.035float · min 0alertSellValueLow
Trailing Stop Arm: 1%=.01.0065float · min 0TSLTriggerValue beginTrail
Trailing Stop Trigger: 1%=.01 .003float · min 0TSLStop
Trend Line Settings
ema 1 Length14int · min 1ema1
ema 1 Sourceclosesourceema1
ema 2 Length22int · min 1ema2
ema 2 Sourceclosesourceema2
ema 3 Length200int · min 1ema3
ema 2 Sourceclosesourceema3

What it calculates

  • EMAema 1 Source (close), ema 1 Length (14)ema1 · line 18
  • EMAema 2 Source (close), ema 2 Length (22)ema2 · line 22
  • EMAema 2 Source (close), ema 3 Length (200)ema3 · line 26
  • ValuewhenbuyAlert, close, 0alertBuyValue · line 44
  • Crossunderclose, alertSellValueLowSell2 · line 90

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 dataema1Len ema 1 Lengthsetting · 14ema2Len ema 2 Lengthsetting · 22ema3Len ema 3 Lengthsetting · 200sellLowStop Loss Loss: 1% = .01setting · .035trailStopArmTrailing Stop Arm: 1%=.…setting · .0065trailStopPctTrailing Stop Trigger: …setting · .003ema1EMA→ ema1ema2EMA→ ema2ema3EMA→ ema3alertBuyValueValuewhen→ alertBuyValueSell2Crossunder→ Sell2alertSellValueLowalertSellValueLowvalueTSLTriggerValueTSLTriggerValuevalueTSLStopTSLStopvalueSell1Sell1valuelongConditionlongConditionvalueshortConditionshortConditionvaluealertBuyalertBuyconditionbuyAlert, TSLTrigger, sellAlertbuyAlert · TSLTrigger +13 conditionsbeginTrailbeginTrailconditionrunTrailrunTrailconditionTSLTSLconditionalertSellalertSellconditionentry:BuyOpen Buystrategy.entryclose_all:sellAlertclose_all sellAlertstrategy.close_allplot:19EMAplotplot:23EMAplotplot:27EMAplotplotshape:78TSL Armedplotshapeplotshape:107Buyplotshapeplotshape:108Sellplotshapealert:122alertalertalert:127alertalert

Order rules

OrderFires whenBy defaultLine
Open Buy long(longCondition)On121
Close sellAlert(shortCondition)On126

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

Alerts

AlertCallMessageLine
(no title)alertBuy122
(no title)alertSell127

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%+102.5%00%—1.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

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
PCT Trailing Stoploss-Strategy this page—v5 strategy0.0%01.2%
MACD 50x Leveraged Short Strategy with Real Equity by Noldoema valuewhenv4 strategy+15,109.2%392,974.0%
MACD 50x Leveraged Long Strategy Results with Real Equity by Noldoema valuewhenv4 strategy+40,225.0%381,581.6%
Yesterday's High v.17.07 by tumiza999valuewhen emav5 strategy+10.1%1271.8%
Sentiment Oscillator by dannylimardiema valuewhenv4 strategy+1.4%520.6%
Initial template by trading_mentalistema valuewhenv4 strategyNo trades on this market

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.

  • 3 settings use the untyped input() (line 17, 21, 25). 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

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 17: input() → input.source()
  • Line 21: input() → input.source()
  • Line 25: input() → input.source()
⋯ema1Len = input.int(14, minval=1, title=" ema 1 Length", group="Trend Line Settings")-ema1Src = input(close, title="ema 1 Source", group="Trend Line Settings")+ema1Src = input.source(close, title="ema 1 Source", group="Trend Line Settings")ema1 = ta.ema(ema1Src, ema1Len)⋯ema2Len = input.int(22, minval=1, title=" ema 2 Length", group="Trend Line Settings")-ema2Src = input(close, title="ema 2 Source", group="Trend Line Settings")+ema2Src = input.source(close, title="ema 2 Source", group="Trend Line Settings")ema2 = ta.ema(ema2Src, ema2Len)⋯ema3Len = input.int(200, minval=1, title=" ema 3 Length", group="Trend Line Settings")-ema3Src = input(close, title="ema 2 Source", group="Trend Line Settings")+ema3Src = input.source(close, title="ema 2 Source", group="Trend Line Settings")ema3 = ta.ema(ema3Src, ema3Len)⋯

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

⋯// © Thumpyr-//@version=5+//@version=6/////////////////////////////////////////////////////////////////////////////////////////////⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 30 msYes 1,000 bars in 51 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/// © Thumpyr//@version=5/////////////////////////////////////////////////////////////////////////////////////////////// Comment out Strategy Line and remove // from Indicator line to turn into Indicator  //////// Do same for alertConidction at bottom                                               ///////////////////////////////////////////////////////////////////////////////////////////////////strategy("PCT Trailing Stoploss-Strategy", shorttitle="PCT Trailing Stoploss- Strategy", overlay=true, margin_long=100, margin_short=100)//indicator(title="PCT Trailing Stoploss- Indicator", shorttitle="PCT Trailing Stoploss - Indicator", timeframe="", timeframe_gaps=true, overlay=true)//sellLow=input.float(.035, minval=0, title="Stop Loss Loss: 1% = .01", group="Sell Settings")trailStopArm=input.float(.0065, minval=0, title="Trailing Stop Arm: 1%=.01", group="Sell Settings")trailStopPct=input.float(.003, minval=0, title="Trailing Stop Trigger: 1%=.01 ", group="Sell Settings")///////////////////////////////////////////////////               Indicators                    ///////////////////////////////////////////////////ema1Len = input.int(14, minval=1, title=" ema 1 Length", group="Trend Line Settings")ema1Src = input(close, title="ema 1 Source", group="Trend Line Settings")ema1 = ta.ema(ema1Src, ema1Len)plot(ema1, title="EMA", color=color.blue)ema2Len = input.int(22, minval=1, title=" ema 2 Length", group="Trend Line Settings")ema2Src = input(close, title="ema 2 Source", group="Trend Line Settings")ema2 = ta.ema(ema2Src, ema2Len)plot(ema2, title="EMA", color=color.orange)ema3Len = input.int(200, minval=1, title=" ema 3 Length", group="Trend Line Settings")ema3Src = input(close, title="ema 2 Source", group="Trend Line Settings")ema3 = ta.ema(ema3Src, ema3Len)plot(ema3, title="EMA", color=color.gray)/////////////////////////////////   Buy Conditions    /////////////////////////////////alertBuy = ta.crossover(ema1,ema2) and close>ema3////////////////////////////////////////////////////////////////////////   Filter redundant Buy Signals if Sell has not happened    ////////////////////////////////////////////////////////////////////////var lastsignal = 0showAlertBuy = 0if(alertBuy and lastsignal !=1)    showAlertBuy  := 1    lastsignal      := 1buyAlert= showAlertBuy > 0//////////////////////////////////////////////////////////////////////          Track Conditions at buy Signal                  //////////////////////////////////////////////////////////////////////alertBuyValue = ta.valuewhen(buyAlert, close,0)alertSellValueLow = alertBuyValue - (alertBuyValue*sellLow)/////////////////////////////////////////////////////////////////            Trailing Stop                         /////////////////////////////////////////////////////////////////var TSLActive=0         //Check to see if TSL has been activatedvar TSLTriggerValue=0.0 //Initial and climbing value of TSLvar TSLStop = 0.0       //Sell Triggervar TSLRunning =0       //Continuously check each bar to raise TSL or not//  Check if a Buy has been triggered and set initial value for TSL //if buyAlert    TSLTriggerValue := alertBuyValue+(alertBuyValue*trailStopArm)    TSLActive := 0    TSLRunning :=1    TSLStop := TSLTriggerValue - (TSLTriggerValue*trailStopPct)    //  Check that Buy has triggered and if Close has reached initial TSL//  //  Keeps from setting Sell Signal before TSL has been armed w/TSLActive//beginTrail=TSLRunning==1 and TSLActive==0 and close>alertBuyValue+(alertBuyValue*trailStopArm) and ta.crossover(close,TSLTriggerValue)if beginTrail    TSLTriggerValue :=close    TSLActive :=1    TSLStop :=TSLTriggerValue - (TSLTriggerValue*trailStopPct)    //  Continuously check if TSL needs to increase and set new value //    runTrail= TSLActive==1 and (ta.crossover(close,TSLTriggerValue) or close>=TSLTriggerValue)if runTrail    TSLTriggerValue :=close    TSLStop :=TSLTriggerValue - (TSLTriggerValue*trailStopPct)    //  Verify that TSL is active and trigger when close cross below TSL Stop//TSL=TSLActive==1 and (ta.crossunder(close,TSLStop) or (close[1]>TSLStop and close<TSLStop)) // Plot point of inital arming of TSL//TSLTrigger=TSLActive==1 and TSLActive[1]==0plotshape(TSLTrigger, title='TSL Armed', location=location.abovebar, color=color.new(color.blue, 0), size=size.small, style=shape.cross, text='TSL Armed')////////////////////////////////////////////////////////////// Plots used for troubleshooting and verification of TSL ////////////////////////////////////////////////////////////////plot(TSLActive,"Trailing Stop", color=#f48fb1)//plot(TSLRunning,"Trailing Stop", color=#f48fb1)//plot(TSLTriggerValue,"Trailing Stop Trigger", color.new(color=#ec407a, transp = TSLRunning==1 ? 0 : 100))//plot(TSLStop,"Trailing Stop", color.new(color=#f48fb1, transp = TSLRunning==1 ? 0 : 100))///////////////////////////////////////////////////////////////////             Sell Conditions                    ///////////////////////////////////////////////////////////////////Sell1 = TSLSell2 = ta.crossunder(close,alertSellValueLow)alertSell= Sell1 or Sell2////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////        Remove Redundant Signals                    ////////////////////////////////////////////////////////////////showAlertSell = 0if(alertSell and lastsignal != -1)    showAlertSell := 1    lastsignal      := -1sellAlert= showAlertSell > 0if sellAlert    TSLActive :=0    TSLRunning :=0///////////////////////////////////////////  Plot Buy and Sell Shapes on Chart  ///////////////////////////////////////////plotshape(buyAlert, title='Buy', location=location.belowbar, color=color.new(color.green, 0), size=size.small, style=shape.triangleup, text='Buy')plotshape(sellAlert, title='Sell', location=location.abovebar, color=color.new(color.red, 0), size=size.small, style=shape.triangledown, text='Sell')///////////////////////////////////////////////////////////////////////////////////////////////                        Remove // to setup for Indicator                                 /////////////////////////////////////////////////////////////////////////////////////////////////Alerts//alertcondition(title='Buy Alert', condition=buyAlert, message='Buy Conditions are Met')//alertcondition(title='Sell Alert', condition=sellAlert, message='Sell Conditions are Met')/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  Comment out this section if setup as Indicator    ////////////////////////////////////////////////////////////////longCondition = buyAlertif (longCondition)    strategy.entry("Buy", strategy.long)    alert(message='Buy', freq=alert.freq_once_per_bar_close)    shortCondition = sellAlertif (shortCondition)    strategy.close_all(sellAlert,"Sell")    alert(message='Sell', freq=alert.freq_once_per_bar_close)/////////////////////////////////////////////////////////////