Pine Script v4 · Strategy
RSI+PA+DCA Strategy
A Pine Script v4 strategy built on RSI (price, 14), Valuewhen (co, close) and Change ("W"). It has 15 order rules, 7 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. 20 settings; defaults include Portfolio % 15, +++++ Long Positions VA Layers +++++ ++++ and 2nd Long Entry % 2.
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+DCA Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 14 of 14 trades.
- How did RSI+PA+DCA Strategy do on BTCUSDT 1D with default settings?
- +22.29%
- From 26 Jan 2024 to 21 Oct 2026, over 46 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can RSI+PA+DCA 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 RSI+PA+DCA Strategy use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does RSI+PA+DCA Strategy run in Zeal Terminal?
- Yes
- It compiles in 40 ms and runs 1,000 bars in 91 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
- Average price
- Take Profit All
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +22.29%
- $89.15
- Buy and hold
- +102.5%
- same period
- Closed trades
- 46
- 35 won · 11 lost
- Profitable
- 76.1%
- of closed trades
- Profit factor
- 11.36
- gross profit ÷ gross loss
- Max drawdown
- 5.12%
- −$20.58
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
6 settings do nothing
“+++++ Long Positions VA Layers +++++”, “+++++ Moving Average Filter +++++”, “+++++ RSI Inputs +++++”, “overbought, has no specific function”, “+++++ Take Profit +++++”, “+++++ Open DCA order once every week +++++” are declared but never read.
-
Check
No stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
Note
2 settings have no label
In the settings dialog movingaverage_signal (line 32), length (line 36) 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 transp =, which v5 removed line 90
transp = on line 90. v5 folds the transparency into the colour with color.new(c, transp).
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, rsi → ta.rsi, crossover → ta.crossover, valuewhen → ta.valuewhen, change → ta.change.
v4 → v5
VerifiedSame 46 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 2: //@version=4 → //@version=5
- Line 20: input(type = input.float) → input.float()
- Line 32: sma → ta.sma
- Line 40: rsi → ta.rsi
- Line 42: crossover → ta.crossover
- Line 48: valuewhen → ta.valuewhen
7 more edits
- Line 49: valuewhen → ta.valuewhen
- Line 50: valuewhen → ta.valuewhen
- Line 51: valuewhen → ta.valuewhen
- Line 52: valuewhen → ta.valuewhen
- Line 53: valuewhen → ta.valuewhen
- Line 85: change → ta.change
- Line 90: transp = 50 → color.new(dcatime and newWeek ? color.white : na, 50)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=4+//@version=5// © A3Sh⋯strategy(title = "RSI+PA+DCA", 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(15, title = "Portfolio %", type = input.float, step = 0.1, minval = 0.1, maxval = 100)+port = input.float(15, title = "Portfolio %", step = 0.1, minval = 0.1, maxval = 100)q = (strategy.equity / 100 * port) / open⋯plotMA = input(title = "Plot Moving Average", defval = false)-movingaverage_signal = sma(close, input(100))+movingaverage_signal = ta.sma(close, input(100))plot (plotMA ? movingaverage_signal : na, color = color.green)⋯price = close-vrsi = rsi(price, length)+vrsi = ta.rsi(price, length)// Long trigger (co)-co = crossover(vrsi, overSold) and close < movingaverage_signal+co = ta.crossover(vrsi, overSold) and close < movingaverage_signal// Take profit⋯// Store values to create and plot the different PA layers-long1 = valuewhen(co, close, 0)+long1 = ta.valuewhen(co, close, 0)-long2 = valuewhen(co, close - (close / 100 * ps2), 0)+long2 = ta.valuewhen(co, close - (close / 100 * ps2), 0)-long3 = valuewhen(co, close - (close / 100 * ps3), 0)+long3 = ta.valuewhen(co, close - (close / 100 * ps3), 0)-long4 = valuewhen(co, close - (close / 100 * ps4), 0)+long4 = ta.valuewhen(co, close - (close / 100 * ps4), 0)-long5 = valuewhen(co, close - (close / 100 * ps5), 0)+long5 = ta.valuewhen(co, close - (close / 100 * ps5), 0)-long6 = valuewhen(co, close - (close / 100 * ps6), 0)+long6 = ta.valuewhen(co, close - (close / 100 * ps6), 0)eps1 = 0.00⋯dcaWeek = input("++++", title = "+++++ Open DCA order once every week +++++")-newWeek = change(time("W"))+newWeek = ta.change(time("W"))dcatime = input(title = "Buy a fixed amount every Monday", defval = false)⋯plotchar (dcatime ? newWeek : na, "buy at Week start", "▼", location.top, size = size.tiny, color = color.white)-bgcolor (dcatime and newWeek ? color.white : na, transp = 50)+bgcolor (color.new(dcatime and newWeek ? color.white : na, 50))// Submit Entry Orders⋯Same 46 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 23: input() → input.string()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
- Line 26: input() → input.int()
- Line 27: input() → input.int()
- Line 28: input() → input.int()
13 more edits
- Line 30: input() → input.string()
- Line 31: input() → input.bool()
- Line 32: input() → input.int()
- Line 35: input() → input.string()
- Line 36: input() → input.int()
- Line 37: input() → input.int()
- Line 38: input() → input.int()
- Line 44: input() → input.string()
- Line 45: input() → input.int()
- Line 46: input() → input.int()
- Line 84: input() → input.string()
- Line 86: input() → input.bool()
- Line 87: input() → input.int()
⋯// Long position entry layers. Percentage from the entry price of the the first long-PositionInputs = input("++++", title = "+++++ Long Positions VA Layers +++++")+PositionInputs = input.string("++++", title = "+++++ Long Positions VA Layers +++++")-ps2 = input(2, title = "2nd Long Entry %", step = 0.1)+ps2 = input.int(2, title = "2nd Long Entry %", step = 0.1)-ps3 = input(3, title = "3rd Long Entry %", step = 0.1)+ps3 = input.int(3, title = "3rd Long Entry %", step = 0.1)-ps4 = input(5, title = "4th Long Entry %", step = 0.1)+ps4 = input.int(5, title = "4th Long Entry %", step = 0.1)-ps5 = input(10, title = "5th Long Entry %", step = 0.1)+ps5 = input.int(10, title = "5th Long Entry %", step = 0.1)-ps6 = input(16, title = "6th Long Entry %", step = 0.1)+ps6 = input.int(16, title = "6th Long Entry %", step = 0.1)// Calculate Moving Averages-maInput = input("++++", title = "+++++ Moving Average Filter +++++")+maInput = input.string("++++", title = "+++++ Moving Average Filter +++++")-plotMA = input(title = "Plot Moving Average", defval = false)+plotMA = input.bool(title = "Plot Moving Average", defval = false)-movingaverage_signal = ta.sma(close, input(100))+movingaverage_signal = ta.sma(close, input.int(100))plot (plotMA ? movingaverage_signal : na, color = color.green)// RSI inputs and calculations-rsiInput = input( "++++", title = "+++++ RSI Inputs +++++" )+rsiInput = input.string( "++++", title = "+++++ RSI Inputs +++++" )-length = input( 14 )+length = input.int( 14 )-overSold = input( 30, title = "oversold, entry trigger long position" )+overSold = input.int( 30, title = "oversold, entry trigger long position" )-overBought = input( 70, title = "overbought, has no specific function")+overBought = input.int( 70, title = "overbought, has no specific function")price = close⋯// Take profit-takeprofit = input("++++", title = "+++++ Take Profit +++++")+takeprofit = input.string("++++", title = "+++++ Take Profit +++++")-ProfitTarget_Percent = input(5, title = "Take Profit % (Per Position)")+ProfitTarget_Percent = input.int(5, title = "Take Profit % (Per Position)")-ProfitTarget_Percent_All = input(7, title = "Take Profit % (Exit All, above % of price average, white line)")+ProfitTarget_Percent_All = input.int(7, title = "Take Profit % (Exit All, above % of price average, white line)")// Store values to create and plot the different PA layers⋯// Open DCA order once at the start of the week-dcaWeek = input("++++", title = "+++++ Open DCA order once every week +++++")+dcaWeek = input.string("++++", title = "+++++ Open DCA order once every week +++++")newWeek = ta.change(time("W"))-dcatime = input(title = "Buy a fixed amount every Monday", defval = false)+dcatime = input.bool(title = "Buy a fixed amount every Monday", defval = false)-fixedAmount = input(40, title = "Fixed amount currency for DCA orders", step = 0.1)+fixedAmount = input.int(40, title = "Fixed amount currency for DCA orders", step = 0.1)dcaq = fixedAmount / open⋯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: 46 before, 46 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⋯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 |
|---|---|---|---|
| Portfolio % | 15 | float · min 0.1 · max 100 · step 0.1 | q |
| +++++ Long Positions VA Layers +++++ | ++++ | string | unused |
| 2nd Long Entry % | 2 | int · step 0.1 | long2 |
| 3rd Long Entry % | 3 | int · step 0.1 | long3 |
| 4th Long Entry % | 5 | int · step 0.1 | long4 |
| 5th Long Entry % | 10 | int · step 0.1 | long5 |
| 6th Long Entry % | 16 | int · step 0.1 | long6 |
| +++++ Moving Average Filter +++++ | ++++ | string | unused |
| Plot Moving Average | false | bool | plot |
| Movingaverage signal (no label in the script) | 100 | int | co plot |
| +++++ RSI Inputs +++++ | ++++ | string | unused |
| Length (no label in the script) | 14 | int | vrsi |
| oversold, entry trigger long position | 30 | int | co |
| overbought, has no specific function | 70 | int | unused |
| +++++ Take Profit +++++ | ++++ | string | unused |
| Take Profit % (Per Position) | 5 | int | tpl1 tpl2 tpl3 tpl4 tpl5 tpl6 |
| Take Profit % (Exit All, above % of price average, white line) | 7 | int | tpv |
| +++++ Open DCA order once every week +++++ | ++++ | string | unused |
| Buy a fixed amount every Monday | false | bool | entry DCA plotchar bgcolor line 112 |
| Fixed amount currency for DCA orders | 40 | int · step 0.1 | dcaq |
What it calculates
- RSI (
rsi,ta.rsiin v5)price, Length (14)vrsi · line 40 - Valuewhen (
valuewhen,ta.valuewhenin v5)co, close, 0long1 · line 48 - Valuewhen (
valuewhen,ta.valuewhenin v5)co, close - (close / 100 * ps2), 0long2 · line 49 - Valuewhen (
valuewhen,ta.valuewhenin v5)co, close - (close / 100 * ps3), 0long3 · line 50 - Valuewhen (
valuewhen,ta.valuewhenin v5)co, close - (close / 100 * ps4), 0long4 · line 51 - Valuewhen (
valuewhen,ta.valuewhenin v5)co, close - (close / 100 * ps5), 0long5 · line 52 - Valuewhen (
valuewhen,ta.valuewhenin v5)co, close - (close / 100 * ps6), 0long6 · line 53 - Change (
change,ta.changein v5)time("W")newWeek · line 85
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 66 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long1 long | (co and strategy.opentrades == 0) | On | 99 |
| Open Long2 long | (strategy.opentrades == 1) | On | 101 |
| Open Long3 long | (strategy.opentrades == 2) | On | 103 |
| Open Long4 long | (strategy.opentrades == 3) | On | 105 |
| Open Long5 long | (strategy.opentrades == 4) | On | 107 |
| Open Long6 long | (strategy.opentrades == 5) | On | 109 |
| Open DCA long | (dcatime and newWeek and strategy.position_size > 0 and close < strategy.position_avg_price) | On | 113 |
| Exit Exit 1 limit | (strategy.position_size > 0) | On | 116 |
| Exit Exit 2 limit | (strategy.position_size > 0) | On | 117 |
| Exit Exit 3 limit | (strategy.position_size > 0) | On | 118 |
| Exit Exit 4 limit | (strategy.position_size > 0) | On | 119 |
| Exit Exit 5 limit | (strategy.position_size > 0) | On | 120 |
| Exit Exit 6 limit | (strategy.position_size > 0) | On | 121 |
| Exit Exit DCA limit | (strategy.position_size > 0) | On | 122 |
| cancel_all | longClose | On | 127 |
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 | +22.3% | +102.5% | 46 | 76% | 11.36 | 5.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +5.6% | +5.5% | 19 | 63% | 2.43 | 13.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +30.5% | +9.8% | 63 | 86% | 11.90 | 28.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +3.9% | +8.4% | 19 | 42% | 1.63 | 16.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +41.2% | +16.7% | 80 | 83% | 8.10 | 26.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +9.4% | +21.5% | 32 | 69% | 2.69 | 18.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +10.1% | +148.3% | 19 | 95% | 305.27 | 2.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +6.4% | +17.1% | 16 | 75% | 39.72 | 3.5% | 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 | 0 | — | $0.00 |
| Sideways market | 12 | 67% | $21.15 |
| Falling market | 34 | 79% | $68.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
1.1%
The 95th percentile of the worst drawdown when the same 46 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.5% to 1.1%; the tick is what actually happened, 1.0%. Order luck alone moves it this much.
All 46 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 26 Jun 2024 61,806.00 | 1 Jul 2024 63,708.50 | 5 | $1.78 |
| long | 26 Jun 2024 61,806.00 | 6 Jul 2024 58,456.80 | 10 | −$0.03 |
| long | 28 Jun 2024 60,569.90 | 6 Jul 2024 58,456.80 | 8 | −$2.14 |
| long | 28 Jun 2024 60,569.90 | 10 Jul 2024 58,527.90 | 12 | −$0.03 |
| long | 3 Jul 2024 59,951.80 | 10 Jul 2024 58,527.90 | 7 | −$1.45 |
| long | 4 Jul 2024 58,715.70 | 10 Jul 2024 58,527.90 | 6 | −$0.01 |
| long | 4 Jul 2024 58,715.70 | 15 Jul 2024 61,755.60 | 11 | $2.75 |
| long | 5 Jul 2024 55,625.40 | 15 Jul 2024 61,755.60 | 10 | $0.22 |
| long | 5 Jul 2024 55,625.40 | 15 Jul 2024 61,755.60 | 10 | $5.71 |
| long | 8 Jul 2024 55,625.40 | 15 Jul 2024 61,755.60 | 7 | $0.56 |
| long | 8 Jul 2024 55,625.40 | 15 Jul 2024 62,854.30 | 7 | $6.57 |
| long | 11 Jul 2024 57,725.80 | 15 Jul 2024 62,854.30 | 4 | $0.21 |
| long | 11 Jul 2024 57,725.80 | 15 Jul 2024 64,637.40 | 4 | $6.79 |
| long | 7 Aug 2024 56,022.00 | 8 Aug 2024 57,658.30 | 1 | $1.74 |
| long | 7 Aug 2024 56,022.00 | 8 Aug 2024 58,778.70 | 1 | $0.12 |
| long | 8 Aug 2024 54,901.60 | 8 Aug 2024 58,778.70 | 0 | $4.26 |
| long | 2 Mar 2025 86,064.50 | 3 Mar 2025 94,270.00 | 1 | $6.13 |
| long | 19 Nov 2025 92,960.80 | 28 Nov 2025 92,879.50 | 9 | −$0.16 |
| long | 20 Nov 2025 91,101.60 | 28 Nov 2025 92,879.50 | 8 | $0.04 |
| long | 20 Nov 2025 91,101.60 | 3 Dec 2025 92,876.70 | 13 | $1.10 |
| long | 21 Nov 2025 86,637.20 | 3 Dec 2025 92,876.70 | 12 | $0.33 |
| long | 21 Nov 2025 86,637.20 | 4 Dec 2025 93,429.90 | 13 | $4.28 |
| long | 22 Nov 2025 85,129.40 | 4 Dec 2025 93,429.90 | 12 | $0.44 |
| long | 22 Nov 2025 85,129.40 | 9 Dec 2025 92,844.50 | 17 | $5.13 |
| long | 1 Dec 2025 88,312.80 | 9 Dec 2025 92,844.50 | 8 | $0.26 |
| long | 1 Dec 2025 88,312.80 | 5 Jan 2026 92,889.30 | 35 | $2.95 |
| long | 5 Dec 2025 90,172.00 | 5 Jan 2026 92,889.30 | 31 | $0.20 |
| long | 5 Dec 2025 90,172.00 | 5 Jan 2026 94,748.50 | 31 | $2.83 |
| long | 5 Dec 2025 88,312.80 | 5 Jan 2026 94,748.50 | 31 | $0.49 |
| long | 5 Dec 2025 88,312.80 | 13 Jan 2026 94,736.80 | 39 | $4.14 |
| long | 14 Dec 2025 88,312.80 | 13 Jan 2026 94,736.80 | 30 | $0.44 |
| long | 14 Dec 2025 88,312.80 | 13 Jan 2026 95,665.50 | 30 | $4.86 |
| long | 8 Jan 2026 90,172.00 | 13 Jan 2026 95,665.50 | 5 | $0.13 |
| long | 8 Jan 2026 90,172.00 | 14 Jan 2026 97,527.50 | 6 | $5.08 |
| long | 7 Feb 2026 70,580.30 | 14 Feb 2026 70,493.90 | 7 | −$0.19 |
| long | 7 Feb 2026 70,580.30 | 25 Feb 2026 66,725.10 | 18 | −$0.47 |
| long | 8 Feb 2026 69,168.60 | 25 Feb 2026 66,725.10 | 17 | −$2.26 |
| long | 8 Feb 2026 69,168.60 | 28 Feb 2026 66,815.80 | 20 | −$0.24 |
| long | 9 Feb 2026 68,462.90 | 28 Feb 2026 66,815.80 | 19 | −$1.62 |
| long | 9 Feb 2026 68,462.90 | 4 Mar 2026 71,879.80 | 23 | $0.28 |
| long | 11 Feb 2026 67,051.20 | 4 Mar 2026 71,879.80 | 21 | $4.37 |
| long | 11 Feb 2026 67,051.20 | 4 Mar 2026 72,462.30 | 21 | $0.35 |
| long | 24 Feb 2026 63,522.20 | 4 Mar 2026 72,462.30 | 8 | $8.14 |
| long | 24 Feb 2026 63,522.20 | 4 Mar 2026 73,783.20 | 8 | $0.87 |
| long | 28 Feb 2026 63,522.20 | 4 Mar 2026 73,783.20 | 4 | $10.41 |
| long | 12 Jun 2026 63,626.00 | 15 Jun 2026 66,913.30 | 3 | $3.78 |
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 |
|---|---|---|---|---|---|
| RSI+PA+DCA Strategy this page | — | v4 strategy | +22.3% | 46 | 5.1% |
| Reinforced RSI - The Quant Science by thequantscience | rsi valuewhen | v5 strategy | −3.9% | 7 | 3.9% |
| Tendency EMA + RSI [Alorse] by alorse | rsi valuewhen | v5 strategy | +4.3% | 4 | 1.9% |
| Fibonacci + RSI - Strategy by MohamedYAbdelaziz | rsi valuewhen | v4 strategy | +3.4% | 2 | 19.2% |
| Momentum Strategy (BTC-USDT; 30m) - STOCH RSI (with source code) by Drun30 | rsi valuewhen | v4 strategy | +13.3% | 12 | 13.6% |
| Impulse Strategy Signals V2 by danieljordi | rsi valuewhen | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 40 ms | Yes 1,000 bars in 91 ms | Not measured |
| PineTS | No 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///@version=4// © A3Sh// RSI Strategy that buys the dips, works with Price Averaging and has a Dollar Cost Average option.// When the price drops below specified percentages of the price (6 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.// The idea is to lower the average position price to a point that when the market rises, the current price crosses over the average position price.// When the current price crosses the average position size and reaches the specified take profit, all entries are closed at once.// In case the market drops significantly, there is an option to activate DCA to lower the average price further.// RSI code 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// 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/// Buy every week code based on the following question in Stack Overflow// https://stackoverflow.com/questions/59870411/in-pine-script-how-can-you-do-something-once-per-day-or-keep-track-if-somethinstrategy(title = "RSI+PA+DCA", 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(15, title = "Portfolio %", type = input.float, step = 0.1, minval = 0.1, maxval = 100)q = (strategy.equity / 100 * port) / open// Long position entry layers. Percentage from the entry price of the the first longPositionInputs = input("++++", title = "+++++ Long Positions VA Layers +++++")ps2 = input(2, title = "2nd Long Entry %", step = 0.1)ps3 = input(3, title = "3rd Long Entry %", step = 0.1)ps4 = input(5, title = "4th Long Entry %", step = 0.1)ps5 = input(10, title = "5th Long Entry %", step = 0.1)ps6 = input(16, title = "6th Long Entry %", step = 0.1)// Calculate Moving AveragesmaInput = input("++++", title = "+++++ Moving Average Filter +++++")plotMA = input(title = "Plot Moving Average", defval = false)movingaverage_signal = sma(close, input(100))plot (plotMA ? movingaverage_signal : na, color = color.green)// RSI inputs and calculationsrsiInput = input( "++++", title = "+++++ RSI Inputs +++++" )length = input( 14 )overSold = input( 30, title = "oversold, entry trigger long position" )overBought = input( 70, title = "overbought, has no specific function")price = closevrsi = rsi(price, length)// Long trigger (co)co = crossover(vrsi, overSold) and close < movingaverage_signal// Take profittakeprofit = input("++++", title = "+++++ Take Profit +++++")ProfitTarget_Percent = input(5, title = "Take Profit % (Per Position)")ProfitTarget_Percent_All = input(7, title = "Take Profit % (Exit All, above % of price average, white line)")// Store values to create and plot the different PA layerslong1 = valuewhen(co, close, 0)long2 = valuewhen(co, close - (close / 100 * ps2), 0)long3 = valuewhen(co, close - (close / 100 * ps3), 0)long4 = valuewhen(co, close - (close / 100 * ps4), 0)long5 = valuewhen(co, close - (close / 100 * ps5), 0)long6 = valuewhen(co, close - (close / 100 * ps6), 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]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 position average priceplot (strategy.position_avg_price, title = "Average price", style = plot.style_linebr, color = color.white, linewidth = 2)// Take profit and exit all on take profit above position average price + plot a red take profit linetpv = strategy.position_avg_price + (strategy.position_avg_price / 100 * ProfitTarget_Percent_All)plot (tpv, title = "Take Profit All", style = plot.style_linebr, color = color.red, linewidth = 1)tpl1 = close < tpv ? eps1 + close * (ProfitTarget_Percent / 100) : tpvtpl2 = close < tpv ? eps2 + close * (ProfitTarget_Percent / 100) : tpvtpl3 = close < tpv ? eps3 + close * (ProfitTarget_Percent / 100) : tpvtpl4 = close < tpv ? eps4 + close * (ProfitTarget_Percent / 100) : tpvtpl5 = close < tpv ? eps5 + close * (ProfitTarget_Percent / 100) : tpvtpl6 = close < tpv ? eps6 + close * (ProfitTarget_Percent / 100) : tpv// Open DCA order once at the start of the weekdcaWeek = input("++++", title = "+++++ Open DCA order once every week +++++")newWeek = change(time("W"))dcatime = input(title = "Buy a fixed amount every Monday", defval = false)fixedAmount = input(40, title = "Fixed amount currency for DCA orders", step = 0.1)dcaq = fixedAmount / openplotchar (dcatime ? newWeek : na, "buy at Week start", "▼", location.top, size = size.tiny, color = color.white)bgcolor (dcatime and newWeek ? color.white : na, transp = 50)// Submit Entry Ordersif (co and strategy.opentrades == 0) eps1 := long1 eps2 := long2 eps3 := long3 eps4 := long4 eps5 := long5 eps6 := long6 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) // Submit Weekly DCA order, only when price is below position average price and when a position is openif (dcatime and newWeek and strategy.position_size > 0 and close < strategy.position_avg_price) strategy.entry("DCA", strategy.long, dcaq)// 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 DCA", from_entry = "DCA", limit = tpv) // 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 : 0 if longClose strategy.cancel_all()