Pine Script v5 · Strategy
PresentTrend - Strategy [presentTrading]
A Pine Script v5 strategy built on SMA (ta.tr, 14), RSI or MFI (hlc3, 14) and Crossover (PresentTrend, PresentTrend[2]). 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 10% of equity and pays 0.1% commission. 5 settings; defaults include Source hlc3, Length 14 and Multiplier 1.618.
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 PresentTrend - Strategy [presentTrading] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did PresentTrend - Strategy [presentTrading] do on BTCUSDT 1D with default settings?
- −0.04%
- From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does PresentTrend - Strategy [presentTrading] run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L7:C25: the argument 'default_qty_type' is specified more than once. The v6 version is shown for reference and is not offered as a download.
- Does PresentTrend - Strategy [presentTrading] use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does PresentTrend - Strategy [presentTrading] run in Zeal Terminal?
- Yes
- It compiles in 28 ms and runs 1,000 bars in 40 ms, in the browser.
BTCUSDT · 1D · default settings
- PresentTrend
- Buy Signal
- Sell Signal
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.04%
- −$3.94
- Buy and hold
- +102.5%
- same period
- Closed trades
- 12
- 4 won · 8 lost
- Profitable
- 33.3%
- of closed trades
- Profit factor
- 1.00
- gross profit ÷ gross loss
- Max drawdown
- 6.08%
- −$608.38
One run with the author's default settings, $10,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.
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 |
|---|---|---|---|
| PresentTrend | |||
| Source | hlc3 | source | PresentTrend |
| Length | 14 | int | ATR PresentTrend |
| Multiplier | 1.618 | float · step 0.1 | upperThreshold lowerThreshold |
| Whether to use RSI or MFI | false | bool | PresentTrend |
| Trade Direction | Both | string · options ["Long", "Short", "Both"] | entry Buy entry Sell close Buy close Sell line 36 line 38 line 41 line 43 |
What it calculates
- SMAta.tr, Length (14)
ATR · line 16 - RSI / MFISource (hlc3), Length (14)
PresentTrend · line 22 - CrossoverPresentTrend, PresentTrend[2]
longSignal · line 24 - CrossunderPresentTrend, PresentTrend[2]
shortSignal · line 25 - BarssincelongSignal
barsSinceBuy · line 27 - BarssinceshortSignal
barsSinceSell · line 28 - BarssincelongSignal[1]
previousBuy · line 29 - BarssinceshortSignal[1]
previousSell · line 30
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Buy long | (trendDirection == 1 and (tradeDirection == "Long" or tradeDirection == "Both")) | On | 37 |
| Open Sell short | (trendDirection == -1 and (tradeDirection == "Short" or tradeDirection == "Both")) | On | 39 |
| Close Buy | (tradeDirection == "Long" and trendDirection == -1) | On | 42 |
| Close Sell | (tradeDirection == "Short" and trendDirection == 1) | On | 44 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −0.0% | +102.5% | 12 | 33% | 1.00 | 6.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.9% | +5.5% | 14 | 36% | 1.31 | 1.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +12.8% | +9.8% | 8 | 75% | 4.75 | 3.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.5% | +8.4% | 6 | 33% | 1.83 | 1.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −10.0% | +16.7% | 12 | 33% | 0.43 | 15.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.2% | +21.5% | 8 | 50% | 1.05 | 3.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +4.1% | +148.3% | 6 | 50% | 2.12 | 2.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 12 | 33% | 1.03 | 1.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 0% | −$142.21 |
| Sideways market | 10 | 40% | $148.18 |
| Falling market | 1 | 0% | −$8.92 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
7.2%
The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.1% to 7.2%; the tick is what actually happened, 5.4%. Order luck alone moves it this much.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 22 May 2024 70,148.40 | 25 Jun 2024 60,293.30 | 34 | −$142.21 |
| short | 25 Jun 2024 60,293.30 | 21 Jul 2024 67,140.00 | 26 | −$113.92 |
| long | 21 Jul 2024 67,140.00 | 7 Aug 2024 56,022.00 | 17 | −$163.00 |
| short | 7 Aug 2024 56,022.00 | 21 Sep 2024 63,201.10 | 45 | −$124.70 |
| long | 21 Sep 2024 63,201.10 | 26 Feb 2025 88,680.40 | 158 | $378.62 |
| short | 26 Feb 2025 88,680.40 | 24 Apr 2025 93,691.10 | 57 | −$57.54 |
| long | 24 Apr 2025 93,691.10 | 31 Aug 2025 108,816.00 | 129 | $155.59 |
| short | 31 Aug 2025 108,816.00 | 3 Oct 2025 120,529.00 | 33 | −$108.92 |
| long | 3 Oct 2025 120,529.00 | 18 Oct 2025 106,432.00 | 15 | −$116.65 |
| short | 18 Oct 2025 106,432.00 | 15 Apr 2026 74,131.60 | 179 | $292.69 |
| long | 15 Apr 2026 74,131.60 | 29 May 2026 73,617.50 | 44 | −$8.92 |
| short | 29 May 2026 73,617.50 | 21 Aug 2026 73,027.00 | 84 | $6.02 |
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 |
|---|---|---|---|---|---|
| PresentTrend - Strategy [presentTrading] this page | — | v5 strategy | −0.0% | 12 | 6.1% |
| CCU MFI + RSI + STOCH RSI by Bangsoul | mfi rsi sma | v4 strategy | +41.8% | 6 | 37.4% |
| AlphaTrend Strategy by only_fibonacci | sma rsi barssince | v5 strategy | −1.4% | 24 | 4.2% |
| AlphaTrend Strategy with Trailing SL - by rohanarora1313 | sma rsi barssince | v5 strategy | −1.0% | 32 | 5.2% |
| 3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders by ggekko21 | rsi sma mfi | v5 strategy | No trades on this market | ||
| SRJ RSI Outperformer Strategy by Sapt_Jash | rsi sma | v5 strategy | +0.6% | 8 | 2.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.
- No v6-only features. v6 is not needed to run this script.
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 @L7:C25: the argument 'default_qty_type' is specified more than once. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © PresentTrading-//@version=5+//@version=6// Define the strategy settings⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 28 ms | Yes 1,000 bars in 40 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © PresentTrading//@version=5// Define the strategy settingsstrategy('PresentTrend - Strategy [presentTrading]' , overlay=true, precision=3, default_qty_type=strategy.cash, commission_value= 0.1, commission_type=strategy.commission.percent, slippage= 1, currency=currency.USD, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, initial_capital= 10000)// Define the input parameterspriceSource = input.source(title='Source', defval=hlc3, group='PresentTrend') // The price source to uselengthParam = input.int(title='Length', defval=14, group='PresentTrend') // The length of the moving averagemultiplier = input.float(title='Multiplier', defval=1.618, step=0.1, group='PresentTrend') // The multiplier for the ATRindicatorChoice = input.bool(title='Whether to use RSI or MFI', defval=false, group='PresentTrend') // Whether to use RSI or MFI// Add a parameter for choosing Long or ShorttradeDirection = input.string(title="Trade Direction", defval="Both", options=["Long", "Short", "Both"])// Calculate the ATR and the upT and downT valuesATR = ta.sma(ta.tr, lengthParam)upperThreshold = low - ATR * multiplier lowerThreshold = high + ATR * multiplier // Initialize the PresentTrend indicatorPresentTrend = 0.0// Calculate the PresentTrend indicatorPresentTrend := (indicatorChoice ? ta.rsi(priceSource, lengthParam) >= 50 : ta.mfi(hlc3, lengthParam) >= 50) ? upperThreshold < nz(PresentTrend[1]) ? nz(PresentTrend[1]) : upperThreshold : lowerThreshold > nz(PresentTrend[1]) ? nz(PresentTrend[1]) : lowerThreshold// Calculate the buy and sell signalslongSignal = ta.crossover(PresentTrend, PresentTrend[2])shortSignal = ta.crossunder(PresentTrend, PresentTrend[2])// Calculate the number of bars since the last buy and sell signalsbarsSinceBuy = ta.barssince(longSignal)barsSinceSell = ta.barssince(shortSignal)previousBuy = ta.barssince(longSignal[1])previousSell = ta.barssince(shortSignal[1])// Initialize the direction variabletrendDirection = 0// Calculate the direction of the trendtrendDirection := longSignal and previousBuy > barsSinceSell ? 1 : shortSignal and previousSell > barsSinceBuy ? -1 : trendDirection[1]// Check the trade direction parameter before entering a tradeif (trendDirection == 1 and (tradeDirection == "Long" or tradeDirection == "Both")) strategy.entry("Buy", strategy.long) if (trendDirection == -1 and (tradeDirection == "Short" or tradeDirection == "Both")) strategy.entry("Sell", strategy.short) // Add a stop mechanism when the tradeDirection is one-sidedif (tradeDirection == "Long" and trendDirection == -1) strategy.close("Buy")if (tradeDirection == "Short" and trendDirection == 1) strategy.close("Sell")// Visualizationplot(PresentTrend, color=color.blue, title="PresentTrend")plotshape(series=longSignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")plotshape(series=shortSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")