Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

RSI+PA+PrTP

A Pine Script v5 strategy built on RMA or Change (14) and Valuewhen (co, close). It has 17 order rules, 8 entries among them, and trades long only with the default settings. Exits use a profit target and no stop loss. Each trade commits 15% of equity and pays 0.075% commission. 18 settings; defaults include Portfolio % Used To Open The 8 Positions 12, 2nd Long Entry % 2 and 3rd Long Entry % 3.

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 RSI+PA+PrTP repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 60 of 60 trades.
How did RSI+PA+PrTP do on BTCUSDT 1D with default settings?
+20.14%
From 26 Jan 2024 to 21 Oct 2026, over 97 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does RSI+PA+PrTP 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: 97 before, 97 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 RSI+PA+PrTP use a stop loss?
No
Its exits set a profit target but no stop.
Does RSI+PA+PrTP run in Zeal Terminal?
Yes
It compiles in 59 ms and runs 1,000 bars in 130 ms, in the browser.

BTCUSDT · 1D · default settings

  • Long entry 1
  • Long entry 2
  • Long entry 3
  • Long entry 4
  • Long entry 5
  • Long entry 6
  • Long entry 7
  • Long entry 8
  • Take Profit Limit
  • 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 (18)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$481$810Equity from $400
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
+20.14%
$80.56
Buy and hold
+102.5%
same period
Closed trades
97
70 won · 27 lost
Profitable
72.2%
of closed trades
Profit factor
4.34
gross profit ÷ gross loss
Max drawdown
7.85%
−$34.61

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

    strategy.exit is used without a stop, loss or trailing stop.

  • 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
Risk
Portfolio % Used To Open The 8 Positions12float · min 0.1 · max 100 · step 0.1q
Long Position Entry Layers
2nd Long Entry %2float · step 0.1long2
3rd Long Entry %3float · step 0.1long3
4th Long Entry %5float · step 0.1long4
5th Long Entry %10float · step 0.1long5
6th Long Entry %16float · step 0.1long6
7th Long Entry %25float · step 0.1long7
8th Long Entry %40float · step 0.1long8
Moving Average Filter
Plot Moving Averagefalseboolplot
MA Length100intco plot
RSI Settings
RSI Length14int · min 1up down
Sourceclosesourceup down
Oversold, Trigger to Enter First Position29intco
Take Profit Settings
Take Profit % (Per Position)3.0floatendVal tpl1 tpl2 tpl3 tpl4 tpl5 tpl6 tpl7 tpl8
Take Profit % (Exit All, Progressive Take Profit Limit4.0floattpLimit tpn
Take Profit ProgressionProgression is defined by the position size. By default 12% of the start equity (portfolio) is used to open a position, see Risk. This same % percentage is used to calculate the profit amount that will be deducted from the Take Profit Limit.12floatendVal
New entries affect Take Profit limitThis option changes the behaviour of the Progressive Take Profit. When switchted on, the difference between the former and current original Take Profit is deducted from the Progressive Take Profit. When switchted off, the Progressive Take Profit is only affected by the profit deduction or each closed position.trueboolline 101
Plot Average Price (FIFO)falseboolAverage price

What it calculates

  • RMA / Changemath.max(ta.change(rsiSourceInput), 0), RSI Length (14)up · line 41
  • RMA / Change-math.min(ta.change(rsiSourceInput), 0), RSI Length (14)down · line 42
  • Valuewhenco, close, 0long1 · line 48
  • Valuewhenco, close - close / 100 * ps2, 0long2 · line 49
  • Valuewhenco, close - close / 100 * ps3, 0long3 · line 50
  • Valuewhenco, close - close / 100 * ps4, 0long4 · line 51
  • Valuewhenco, close - close / 100 * ps5, 0long5 · line 52
  • Valuewhenco, close - close / 100 * ps6, 0long6 · line 53
  • Valuewhenco, close - close / 100 * ps7, 0long7 · line 54
  • Valuewhenco, close - close / 100 * ps8, 0long8 · line 55

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.

The script has 78 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long1 longco and strategy.opentrades == 0On133
Open Long2 longstrategy.opentrades == 1On135
Open Long3 longstrategy.opentrades == 2On137
Open Long4 longstrategy.opentrades == 3On139
Open Long5 longstrategy.opentrades == 4On141
Open Long6 longstrategy.opentrades == 5On143
Open Long7 longstrategy.opentrades == 6On145
Open Long8 longstrategy.opentrades == 7On147
Exit Exit 1 limitstrategy.position_size > 0On150
Exit Exit 2 limitstrategy.position_size > 0On151
Exit Exit 3 limitstrategy.position_size > 0On152
Exit Exit 4 limitstrategy.position_size > 0On153
Exit Exit 5 limitstrategy.position_size > 0On154
Exit Exit 6 limitstrategy.position_size > 0On155
Exit Exit 7 limitstrategy.position_size > 0On156
Exit Exit 8 limitstrategy.position_size > 0On157
cancel_all longCloseOn161

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.

60/60trades 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+20.1%+102.5%9772%4.347.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.0%+5.5%3067%1.8510.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+16.7%+9.8%5558%2.0626.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+2.4%+8.4%24345%1.2713.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+16.8%+16.7%10573%1.6424.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+3.3%+21.5%20428%1.309.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+11.8%+148.3%10150%1.9312.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.8%+17.1%2080%13.242.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 market0—$0.00
Sideways market2552%$18.76
Falling market7279%$61.80

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

How bad could the drawdown be?

2.7%

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

0%4%
All 97 trades
SideEntryExitBarsP&L
long26 Jun 2024 61,806.0030 Jun 2024 62,399.504$0.39
long26 Jun 2024 61,806.001 Jul 2024 63,689.205$0.01
long28 Jun 2024 60,569.901 Jul 2024 63,689.203$2.39
long7 Jul 2024 58,230.109 Jul 2024 58,184.702−$0.11
long8 Jul 2024 55,857.809 Jul 2024 58,184.701$0.02
long8 Jul 2024 55,857.8010 Jul 2024 58,807.002$2.33
long9 Jul 2024 56,483.2010 Jul 2024 58,807.001$0.02
long9 Jul 2024 56,483.2011 Jul 2024 58,797.302$1.87
long9 Jul 2024 56,483.2014 Jul 2024 59,931.605$0.05
long11 Jul 2024 57,065.5014 Jul 2024 59,931.603$2.33
long7 Aug 2024 56,022.008 Aug 2024 56,555.601$0.39
long7 Aug 2024 56,022.008 Aug 2024 57,676.001$0.05
long8 Aug 2024 54,901.608 Aug 2024 57,676.000$2.35
long2 Mar 2025 86,064.503 Mar 2025 94,270.001$4.73
long19 Nov 2025 92,960.8027 Nov 2025 91,027.308−$1.12
long20 Nov 2025 91,101.6027 Nov 2025 91,027.307−$0.00
long20 Nov 2025 91,101.6028 Nov 2025 92,912.008$0.86
long21 Nov 2025 86,637.2028 Nov 2025 92,912.007$0.15
long21 Nov 2025 86,637.202 Dec 2025 90,901.4011$2.12
long22 Nov 2025 85,129.402 Dec 2025 90,901.4010$0.24
long22 Nov 2025 85,129.403 Dec 2025 92,910.4011$3.99
long29 Nov 2025 90,172.003 Dec 2025 92,910.404$0.08
long29 Nov 2025 90,172.003 Dec 2025 93,841.604$1.84
long1 Dec 2025 88,312.803 Dec 2025 93,841.602$0.08
long1 Dec 2025 88,312.807 Dec 2025 90,989.906$1.38
long4 Dec 2025 91,101.607 Dec 2025 90,989.903−$0.01
long4 Dec 2025 91,101.609 Dec 2025 92,891.005$0.85
long5 Dec 2025 90,172.009 Dec 2025 92,891.004$0.09
long5 Dec 2025 90,172.009 Dec 2025 93,820.604$1.81
long5 Dec 2025 88,312.809 Dec 2025 93,820.604$0.26
long5 Dec 2025 88,312.804 Jan 2026 91,031.6030$1.40
long11 Dec 2025 91,101.604 Jan 2026 91,031.6024−$0.01
long11 Dec 2025 91,101.605 Jan 2026 92,917.9025$0.89
long12 Dec 2025 90,172.005 Jan 2026 92,917.9024$0.09
long12 Dec 2025 90,172.005 Jan 2026 93,847.5024$1.87
long14 Dec 2025 88,312.805 Jan 2026 93,847.5022$0.16
long14 Dec 2025 88,312.8013 Jan 2026 92,910.9030$2.42
long7 Jan 2026 91,101.6013 Jan 2026 92,910.906$0.03
long7 Jan 2026 91,101.6013 Jan 2026 93,840.506$1.41
long8 Jan 2026 90,172.0013 Jan 2026 93,840.505$0.05
long8 Jan 2026 90,172.0013 Jan 2026 95,675.405$2.91
long3 Feb 2026 78,738.6012 Feb 2026 68,152.909−$7.35
long4 Feb 2026 75,770.2012 Feb 2026 68,152.908−$0.36
long4 Feb 2026 75,770.2013 Feb 2026 68,128.609−$4.82
long5 Feb 2026 73,165.8013 Feb 2026 68,128.608−$0.67
long5 Feb 2026 73,165.8020 Feb 2026 68,150.6015−$2.86
long6 Feb 2026 62,909.9020 Feb 2026 68,150.6014$0.95
long6 Feb 2026 62,909.9025 Feb 2026 68,062.2019$2.50
long7 Feb 2026 70,580.3025 Feb 2026 68,062.2018−$0.69
long7 Feb 2026 70,580.301 Mar 2026 68,149.6022−$1.44
long11 Feb 2026 66,140.401 Mar 2026 68,149.6018$0.37
long11 Feb 2026 66,140.402 Mar 2026 68,113.7019$1.02
long13 Feb 2026 66,140.402 Mar 2026 68,113.7017$0.41
long13 Feb 2026 66,140.404 Mar 2026 72,873.9019$3.54
long18 Feb 2026 66,140.404 Mar 2026 72,873.9014$1.96
long18 Feb 2026 66,140.409 Mar 2026 68,119.6019$0.84
long23 Feb 2026 66,140.409 Mar 2026 68,119.6014$0.59
long23 Feb 2026 66,140.4013 Mar 2026 72,981.0018$2.97
long27 Feb 2026 66,140.4013 Mar 2026 72,981.0014$2.37
long27 Feb 2026 66,140.4015 Mar 2026 73,001.1016$2.75
long2 Mar 2026 65,776.5015 Mar 2026 73,001.1013$2.55
long2 Mar 2026 65,776.5030 Mar 2026 68,120.8028$0.90
long5 Mar 2026 70,864.7030 Mar 2026 68,120.8025−$0.98
long5 Mar 2026 70,864.7031 Mar 2026 68,144.4026−$1.27
long8 Mar 2026 66,140.4031 Mar 2026 68,144.4023$0.66
long8 Mar 2026 66,140.405 Apr 2026 68,159.4028$0.80
long14 Mar 2026 70,864.705 Apr 2026 68,159.4022−$1.02
long14 Mar 2026 70,864.709 Apr 2026 72,996.9026$0.81
long18 Mar 2026 70,864.709 Apr 2026 72,996.9022$0.68
long18 Mar 2026 70,864.7013 Apr 2026 72,987.0026$0.81
long27 Mar 2026 66,140.4013 Apr 2026 72,987.0017$2.43
long27 Mar 2026 66,140.4017 Apr 2026 76,723.4021$4.04
long31 Mar 2026 66,140.4017 Apr 2026 76,723.4017$3.07
long31 Mar 2026 66,140.4019 Apr 2026 74,801.7019$4.30
long2 Apr 2026 66,140.4019 Apr 2026 74,801.7017$1.99
long2 Apr 2026 66,140.4020 Apr 2026 73,801.8018$4.15
long12 Apr 2026 70,864.7020 Apr 2026 73,801.808$0.55
long12 Apr 2026 70,864.7022 Apr 2026 78,386.6010$4.20
long19 Apr 2026 74,801.7022 Apr 2026 78,386.603$0.42
long19 Apr 2026 74,801.7022 Apr 2026 79,152.003$2.60
long20 Apr 2026 73,801.8022 Apr 2026 79,152.002$0.29
long20 Apr 2026 73,801.8023 Apr 2026 77,163.803$2.23
long23 Apr 2026 77,163.8023 Apr 2026 77,163.800−$0.01
long23 Apr 2026 77,163.8025 Apr 2026 77,163.802−$0.08
long25 Apr 2026 77,163.8025 Apr 2026 77,163.800−$0.01
long25 Apr 2026 77,163.8027 Apr 2026 77,163.802−$0.08
long27 Apr 2026 77,163.8027 Apr 2026 77,163.800−$0.01
long27 Apr 2026 77,163.8028 Apr 2026 77,163.801−$0.08
long28 Apr 2026 77,163.8028 Apr 2026 77,163.800−$0.00
long28 Apr 2026 77,163.8029 Apr 2026 76,342.801−$0.64
long29 Apr 2026 76,342.8029 Apr 2026 76,342.800−$0.01
long29 Apr 2026 76,342.8030 Apr 2026 75,780.001−$0.47
long30 Apr 2026 75,780.0030 Apr 2026 75,780.000−$0.01
long30 Apr 2026 75,780.001 May 2026 76,346.601$0.31
long1 May 2026 76,346.601 May 2026 76,346.600−$0.01
long1 May 2026 76,346.604 May 2026 80,751.103$2.95
long12 Jun 2026 63,626.0014 Jun 2026 65,559.702$1.72

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
RSI+PA+PrTP this page—v5 strategy+20.1%977.9%
HiLo Extension by Saravanan_Ragavanvaluewhen rmav4 strategyNo trades on this market
ADX + RSI Strat by tweakerIDvaluewhen rmav4 strategy−3.5%636.3%

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 setting uses the untyped input() (line 36). 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 97 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 36: input() → input.int()
⋯plotMA               = input.bool(group = "Moving Average Filter", title='Plot Moving Average', defval=false)-movingaverage_signal = ta.sma(close, input(100, group = "Moving Average Filter", title='MA Length'))+movingaverage_signal = ta.sma(close, input.int(100, group = "Moving Average Filter", title='MA Length'))plot (plotMA ? movingaverage_signal : na, color = color.new (color.green, 0))⋯

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=5+//@version=6// © A3Sh⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 59 msYes 1,000 bars in 130 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///@version=5// © A3Sh// RSI Strategy that buys the dips, uses Price Averaging and Pyramiding.// When the price drops below specified percentages of the price (8 PA layers), new entries are openend to average the price of the assets.// Open entries are closed by a specified take profit.// Entries can be reopened, after closing and consequently crossing a PA layer again.// This strategy is based on the RSI+PA+DCA strategy I created earlier. The difference is the way the Take Profit is calculated.// Instead of directly connecting the take profit limit to the decreasing average price level with an X percent above the average price, // the take profit is calculated for a part on the decreasing average price and for another part on the deduction // of the profits of the individual closed positions.// The Take Profit Limit drop less significant then the average price level and the full position only completely exits // when enough individual closed positions made up for the losses.// This makes it less risky and more conservative and great for a long term trading strategy// RSI code is adapted from the build in Relative Strength Index indicator// MA Filter and RSI concept adapted from the Optimized RSI Buy the Dips strategy, by Coinrule// https://www.tradingview.com/script/Pm1WAtyI-Optimized-RSI-Strategy-Buy-The-Dips-by-Coinrule/// Pyramiding entries code adapted from Pyramiding Entries on Early Trends startegy, by Coinrule// Pyramiding entries code adapted from Pyramiding Entries on Early Trends startegy, by Coinrule// https://www.tradingview.com/script/7NNJ0sXB-Pyramiding-Entries-On-Early-Trends-by-Coinrule/// Plot entry layers code adapted from HOWTO Plot Entry Price by vitvlkv// https://www.tradingview.com/script/bHTnipgY-HOWTO-Plot-Entry-Price/strategy(title='RSI+PA+PTP', pyramiding=16, overlay=true, initial_capital=400, default_qty_type=strategy.percent_of_equity, default_qty_value=15, commission_type=strategy.commission.percent, commission_value=0.075, close_entries_rule='FIFO')port = input.float(12, group = "Risk", title='Portfolio % Used To Open The 8 Positions', step=0.1, minval=0.1, maxval=100)q    = strategy.equity / 100 * port / open// Long position PA entry layers. Percentage from the entry price of the the first longps2 = input.float(2,  group = "Long Position Entry Layers", title='2nd Long Entry %', step=0.1)ps3 = input.float(3,  group = "Long Position Entry Layers", title='3rd Long Entry %', step=0.1)ps4 = input.float(5,  group = "Long Position Entry Layers", title='4th Long Entry %', step=0.1)ps5 = input.float(10, group = "Long Position Entry Layers", title='5th Long Entry %', step=0.1)ps6 = input.float(16, group = "Long Position Entry Layers", title='6th Long Entry %', step=0.1)ps7 = input.float(25, group = "Long Position Entry Layers" ,title='7th Long Entry %', step=0.1)ps8 = input.float(40, group = "Long Position Entry Layers", title='8th Long Entry %', step=0.1)// Calculate Moving AveragesplotMA               = input.bool(group = "Moving Average Filter", title='Plot Moving Average', defval=false)movingaverage_signal = ta.sma(close, input(100, group = "Moving Average Filter", title='MA Length'))plot (plotMA ? movingaverage_signal : na, color = color.new (color.green, 0))// RSI inputs and calculationsrsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")rsiSourceInput = input.source(close, "Source", group="RSI Settings")up   = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)rsi  = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))overSold = input.int(29, title="Oversold, Trigger to Enter First Position", group = "RSI Settings")// Long trigger (co)co = ta.crossover(rsi, overSold) and close < movingaverage_signal// Store values to create and plot the different PA layerslong1 = ta.valuewhen(co, close, 0)long2 = ta.valuewhen(co, close - close / 100 * ps2, 0)long3 = ta.valuewhen(co, close - close / 100 * ps3, 0)long4 = ta.valuewhen(co, close - close / 100 * ps4, 0)long5 = ta.valuewhen(co, close - close / 100 * ps5, 0)long6 = ta.valuewhen(co, close - close / 100 * ps6, 0)long7 = ta.valuewhen(co, close - close / 100 * ps7, 0)long8 = ta.valuewhen(co, close - close / 100 * ps8, 0)eps1 = 0.00eps1 := na(eps1[1]) ? na : eps1[1]eps2 = 0.00eps2 := na(eps2[1]) ? na : eps2[1]eps3 = 0.00eps3 := na(eps3[1]) ? na : eps3[1]eps4 = 0.00eps4 := na(eps4[1]) ? na : eps4[1]eps5 = 0.00eps5 := na(eps5[1]) ? na : eps5[1]eps6 = 0.00eps6 := na(eps6[1]) ? na : eps6[1]eps7 = 0.00eps7 := na(eps7[1]) ? na : eps7[1]eps8 = 0.00eps8 := na(eps8[1]) ? na : eps8[1]plot(strategy.position_size > 0 ? eps1 : na, title='Long entry 1', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps2 : na, title='Long entry 2', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps3 : na, title='Long entry 3', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps4 : na, title='Long entry 4', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps5 : na, title='Long entry 5', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps6 : na, title='Long entry 6', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps7 : na, title='Long entry 7', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps8 : na, title='Long entry 8', style=plot.style_linebr)// Take Profit SettingsProfitTarget_Percent     = input.float(3.0,   group = "Take Profit Settings", title='Take Profit % (Per Position)')ProfitTarget_Percent_All = input.float(4.0,   group = "Take Profit Settings", title='Take Profit % (Exit All, Progressive Take Profit Limit')TakeProfitProgression    = input.float(12,    group = "Take Profit Settings", title='Take Profit Progression', tooltip = 'Progression is defined by the position size. By default 12% of the start equity (portfolio) is used to open a position, see Risk. This same % percentage is used to calculate the profit amount that will be deducted from the Take Profit Limit.')entryOn                  = input.bool (true,  group = "Take Profit Settings", title='New entries affect Take Profit limit', tooltip = 'This option changes the behaviour of the Progressive Take Profit. When switchted on, the difference between the former and current original Take Profit is deducted from the Progressive Take Profit. When switchted off, the Progressive Take Profit is only affected by the profit deduction or each closed position.')avPricePlot              = input.bool (false, group = "Take Profit Settings", title='Plot Average Price (FIFO)')// Original Take Profit LimittpLimit                  = strategy.position_avg_price + (strategy.position_avg_price / 100 * ProfitTarget_Percent_All) // Create variables to calculate the Take Profit Limit Progresssionvar endVal   = 0.0   var startVal = 0.0// The value at the the start of the loop is the value of the end of the previous loopstartVal := endVal // Set variable to the original Take Profit Limit when the first position opens.if strategy.position_size > 0 and strategy.position_size[1] ==0    endVal := tpLimit  // Everytime a specific position opens, the difference of the previous (original) Take Profit price and the current (original) Take Profit price will be deducted from the Progressive Take Profit Limit// This feature can be toggled on and off in the settings panel. By default it is toggled on.entryAmount = 0.0for i = 1 to strategy.opentrades    entryAmount := i    if entryOn  and strategy.position_size > 0 and strategy.opentrades[1] == (entryAmount) and strategy.opentrades == (entryAmount + 1)        endVal := startVal - (tpLimit[1] - tpLimit)// Everytime a specific position closes, the amount of profit from that specific position will be deducted from the Progressive Take Profit Limit.exitAmount = 0.0for id = 1 to strategy.opentrades    exitAmount := id    if strategy.opentrades[1] ==(exitAmount + 1) and strategy.opentrades == (exitAmount)        endVal := startVal - (TakeProfitProgression / 100 * strategy.opentrades.entry_price (id - 1) / 100 * ProfitTarget_Percent )// The Final Take Profit Pricetpn = (strategy.position_avg_price + (strategy.position_avg_price / 100 * ProfitTarget_Percent_All))  - (strategy.position_avg_price + (strategy.position_avg_price / 100 * ProfitTarget_Percent_All) - endVal)plot  (strategy.position_size > 0 ? tpn : na, title = "Take Profit Limit", color=color.new(color.red, 0), style = plot.style_linebr, linewidth = 1) // Plot position average price as referenceplot  (avPricePlot ? strategy.position_avg_price : na, title= "Average price", color = color.new(color.white, 0), style = plot.style_linebr, linewidth = 1) // When to trigger the Take Profit per position or the Progressive Take Profittpl1 = close < tpn ? eps1 + close * (ProfitTarget_Percent / 100) : tpntpl2 = close < tpn ? eps2 + close * (ProfitTarget_Percent / 100) : tpntpl3 = close < tpn ? eps3 + close * (ProfitTarget_Percent / 100) : tpntpl4 = close < tpn ? eps4 + close * (ProfitTarget_Percent / 100) : tpntpl5 = close < tpn ? eps5 + close * (ProfitTarget_Percent / 100) : tpntpl6 = close < tpn ? eps6 + close * (ProfitTarget_Percent / 100) : tpntpl7 = close < tpn ? eps7 + close * (ProfitTarget_Percent / 100) : tpntpl8 = close < tpn ? eps8 + close * (ProfitTarget_Percent / 100) : tpn// Submit Entry Ordersif co and strategy.opentrades == 0    eps1 := long1    eps2 := long2    eps3 := long3    eps4 := long4    eps5 := long5    eps6 := long6    eps7 := long7    eps8 := long8    strategy.entry('Long1', strategy.long, q)if strategy.opentrades == 1    strategy.entry('Long2', strategy.long, q, limit=eps2)if strategy.opentrades == 2    strategy.entry('Long3', strategy.long, q, limit=eps3)if strategy.opentrades == 3    strategy.entry('Long4', strategy.long, q, limit=eps4)if strategy.opentrades == 4    strategy.entry('Long5', strategy.long, q, limit=eps5)if strategy.opentrades == 5    strategy.entry('Long6', strategy.long, q, limit=eps6)if strategy.opentrades == 6    strategy.entry('Long7', strategy.long, q, limit=eps7)if strategy.opentrades == 7    strategy.entry('Long8', strategy.long, q, limit=eps8)// Submit Exit ordersif strategy.position_size > 0    strategy.exit(id='Exit 1', from_entry='Long1', limit=tpl1)    strategy.exit(id='Exit 2', from_entry='Long2', limit=tpl2)    strategy.exit(id='Exit 3', from_entry='Long3', limit=tpl3)    strategy.exit(id='Exit 4', from_entry='Long4', limit=tpl4)    strategy.exit(id='Exit 5', from_entry='Long5', limit=tpl5)    strategy.exit(id='Exit 6', from_entry='Long6', limit=tpl6)    strategy.exit(id='Exit 7', from_entry='Long7', limit=tpl7)    strategy.exit(id='Exit 8', from_entry='Long8', limit=tpl8)// Make sure that all open limit orders are canceled after exiting all the positions longClose = strategy.position_size[1] > 0 and strategy.position_size == 0 ? 1 : 0if longClose    strategy.cancel_all()