Pine Script v3 · Strategy
LegacyPyramiding Entries On Early Trends (by Coinrule)
A Pine Script v3 strategy built on SMA (close, 9) and Crossover (close, MAfast). It has 14 order rules, 7 entries among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 20% of equity and pays 0.1% commission. 12 settings; defaults include From Month 1, From Day 10 and From Year 2020.
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 Pyramiding Entries On Early Trends (by Coinrule) repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
- How did Pyramiding Entries On Early Trends (by Coinrule) do on BTCUSDT 1D with default settings?
- +2.27%
- From 26 Jan 2024 to 21 Oct 2026, over 20 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Pyramiding Entries On Early Trends (by Coinrule) be converted to Pine Script v5?
- No
- The automatic step from v3 to v4 changes the results, so no v4 download is offered; the edits are shown below.
- Does Pyramiding Entries On Early Trends (by Coinrule) use a stop loss?
- Yes
- strategy.exit sets a stop on line 67, 68, 69, 70, 71, 72, 73.
- Does Pyramiding Entries On Early Trends (by Coinrule) run in Zeal Terminal?
- Yes
- It compiles in 15 ms and runs 1,000 bars in 43 ms, in the browser.
BTCUSDT · 1D · default settings
- SMA
- SMA
- SMA
- Crossover
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2.27%
- $22.68
- Buy and hold
- +102.5%
- same period
- Closed trades
- 20
- 13 won · 7 lost
- Profitable
- 65.0%
- of closed trades
- Profit factor
- 1.50
- gross profit ÷ gross loss
- Max drawdown
- 2.22%
- −$23.17
One run with the author's default settings, $1,000 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
1 setting does nothing
“Show Date Range” is declared but never read.
-
Note
2 settings have no label
In the settings dialog ProfitTarget_Percent (line 39), LossTarget_Percent (line 44) 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 an argument v6 removed
when = on line 50, 52, 54, 56, 58, 60, 62. The upgraded version below moves each call inside an if block.
Upgrade and export
Written in Pine Script v3. The upgrade to v5 takes 2 steps, 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, crossover → ta.crossover.
- 7 strategy calls use the when = argument (line 50, 52, 54, 56, 58, 60, 62). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v3 → v4
DiffersTrades differ: 20 before, 20 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=3 → //@version=4
⋯ -//@version=3+//@version=4strategy(shorttitle='Pyramiding Entry On Early Trends',title='Pyramiding Entry On Early Trends (by Coinrule)', overlay=false, pyramiding= 7, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.1)⋯v4 → v5
VerifiedSame 20 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 28: sma → ta.sma
- Line 29: sma → ta.sma
- Line 30: sma → ta.sma
- Line 33: crossover → ta.crossover
⋯ -//@version=4+//@version=5strategy(shorttitle='Pyramiding Entry On Early Trends',title='Pyramiding Entry On Early Trends (by Coinrule)', overlay=false, pyramiding= 7, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.1)⋯ -MAfast= sma(close, inSignal)+MAfast= ta.sma(close, inSignal)-MAslow= sma(close, inlong1)+MAslow= ta.sma(close, inlong1)-MAlong= sma(close, inlong2)+MAlong= ta.sma(close, inlong2) -Bullish = crossover(close, MAfast) +Bullish = ta.crossover(close, MAfast) ⋯Clean v5
VerifiedSame 20 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
13 more edits
- Line 16: input() → input.bool()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
- Line 26: input() → input.int()
- Line 39: input() → input.int()
- Line 44: input() → input.int()
- Line 50: when = (strategy.opentrades == 0) and longsignal → if block
- Line 52: when = (strategy.opentrades == 1) and longsignal → if block
- Line 54: when = (strategy.opentrades == 2) and longsignal → if block
- Line 56: when = (strategy.opentrades == 3) and longsignal → if block
- Line 58: when = (strategy.opentrades == 4) and longsignal → if block
- Line 60: when = (strategy.opentrades == 5) and longsignal → if block
- Line 62: when = (strategy.opentrades == 6) and longsignal → if block
⋯//Backtest dates-fromMonth = input(defval = 1, title = "From Month") +fromMonth = input.int(defval = 1, title = "From Month") -fromDay = input(defval = 10, title = "From Day") +fromDay = input.int(defval = 10, title = "From Day") -fromYear = input(defval = 2020, title = "From Year") +fromYear = input.int(defval = 2020, title = "From Year") -thruMonth = input(defval = 1, title = "Thru Month") +thruMonth = input.int(defval = 1, title = "Thru Month") -thruDay = input(defval = 1, title = "Thru Day") +thruDay = input.int(defval = 1, title = "Thru Day") -thruYear = input(defval = 2112, title = "Thru Year") +thruYear = input.int(defval = 2112, title = "Thru Year") -showDate = input(defval = true, title = "Show Date Range")+showDate = input.bool(defval = true, title = "Show Date Range") ⋯//MA inputs and calculations-inSignal=input(9, title='MAfast')+inSignal=input.int(9, title='MAfast')-inlong1=input(100, title='MAslow')+inlong1=input.int(100, title='MAslow')-inlong2=input(200, title='MAlong')+inlong2=input.int(200, title='MAlong') ⋯ -ProfitTarget_Percent = input(3)+ProfitTarget_Percent = input.int(3)Profit_Ticks = (close * (ProfitTarget_Percent / 100)) / syminfo.mintick⋯ -LossTarget_Percent = input(3)+LossTarget_Percent = input.int(3)Loss_Ticks = (close * (LossTarget_Percent / 100)) / syminfo.mintick⋯ -strategy.entry("Entry 1", strategy.long, when = (strategy.opentrades == 0) and longsignal)+if (strategy.opentrades == 0) and longsignal+ strategy.entry("Entry 1", strategy.long) -strategy.entry("Entry 2", strategy.long, when = (strategy.opentrades == 1) and longsignal)+if (strategy.opentrades == 1) and longsignal+ strategy.entry("Entry 2", strategy.long) -strategy.entry("Entry 3", strategy.long, when = (strategy.opentrades == 2) and longsignal)+if (strategy.opentrades == 2) and longsignal+ strategy.entry("Entry 3", strategy.long) -strategy.entry("Entry 4", strategy.long, when = (strategy.opentrades == 3) and longsignal)+if (strategy.opentrades == 3) and longsignal+ strategy.entry("Entry 4", strategy.long) -strategy.entry("Entry 5", strategy.long, when = (strategy.opentrades == 4) and longsignal)+if (strategy.opentrades == 4) and longsignal+ strategy.entry("Entry 5", strategy.long) -strategy.entry("Entry 6", strategy.long, when = (strategy.opentrades == 5) and longsignal)+if (strategy.opentrades == 5) and longsignal+ strategy.entry("Entry 6", strategy.long) -strategy.entry("Entry 7", strategy.long, when = (strategy.opentrades == 6) and longsignal)+if (strategy.opentrades == 6) and longsignal+ strategy.entry("Entry 7", strategy.long) ⋯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: 20 before, 20 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.
⋯ -//@version=5+//@version=6strategy(shorttitle='Pyramiding Entry On Early Trends',title='Pyramiding Entry On Early Trends (by Coinrule)', overlay=false, pyramiding= 7, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.1)⋯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 |
|---|---|---|---|
| From Month | 1 | int | start |
| From Day | 10 | int | start |
| From Year | 2020 | int | start |
| Thru Month | 1 | int | finish |
| Thru Day | 1 | int | finish |
| Thru Year | 2112 | int | finish |
| Show Date Range | true | bool | unused |
| MAfast | 9 | int | MAfast |
| MAslow | 100 | int | MAslow |
| MAlong | 200 | int | MAlong |
| Profit Target Percent (no label in the script) | 3 | int | Profit_Ticks |
| Loss Target Percent (no label in the script) | 3 | int | Loss_Ticks |
What it calculates
- SMA (
sma,ta.smain v5)close, MAfast (9)MAfast · line 28 - SMA (
sma,ta.smain v5)close, MAslow (100)MAslow · line 29 - SMA (
sma,ta.smain v5)close, MAlong (200)MAlong · line 30 - Crossover (
crossover,ta.crossoverin v5)close, MAfastBullish · line 33
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 Entry 1 long | (strategy.opentrades == 0) and longsignal | On | 50 |
| Open Entry 2 long | (strategy.opentrades == 1) and longsignal | On | 52 |
| Open Entry 3 long | (strategy.opentrades == 2) and longsignal | On | 54 |
| Open Entry 4 long | (strategy.opentrades == 3) and longsignal | On | 56 |
| Open Entry 5 long | (strategy.opentrades == 4) and longsignal | On | 58 |
| Open Entry 6 long | (strategy.opentrades == 5) and longsignal | On | 60 |
| Open Entry 7 long | (strategy.opentrades == 6) and longsignal | On | 62 |
| Exit Exit 1 stop and limit | (strategy.position_size > 0) | On | 67 |
| Exit Exit 2 stop and limit | (strategy.position_size > 0) | On | 68 |
| Exit Exit 3 stop and limit | (strategy.position_size > 0) | On | 69 |
| Exit Exit 4 stop and limit | (strategy.position_size > 0) | On | 70 |
| Exit Exit 5 stop and limit | (strategy.position_size > 0) | On | 71 |
| Exit Exit 6 stop and limit | (strategy.position_size > 0) | On | 72 |
| Exit Exit 7 stop and limit | (strategy.position_size > 0) | On | 73 |
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 calc_on_every_tick. 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 | +2.3% | +102.5% | 20 | 65% | 1.50 | 2.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −2.1% | +5.5% | 16 | 44% | 0.51 | 4.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.2% | +9.8% | 19 | 53% | 1.03 | 3.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.6% | +8.4% | 14 | 43% | 0.64 | 2.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +5.5% | +16.7% | 14 | 86% | 4.34 | 1.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.8% | +21.5% | 20 | 75% | 1.56 | 5.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.9% | +148.3% | 15 | 47% | 0.82 | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −2.0% | +17.1% | 9 | 22% | 0.36 | 3.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 8 | 63% | $8.63 |
| Sideways market | 12 | 67% | $14.05 |
| Falling market | 0 | — | $0.00 |
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 20 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.2% to 2.7%; the tick is what actually happened, 2.1%. Order luck alone moves it this much.
All 20 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 7 Oct 2024 62,819.90 | 9 Oct 2024 60,955.10 | 2 | −$6.33 |
| long | 9 Oct 2024 62,160.50 | 10 Oct 2024 60,341.40 | 1 | −$6.23 |
| long | 12 Oct 2024 62,540.00 | 14 Oct 2024 64,426.10 | 2 | $5.55 |
| long | 25 Oct 2024 68,198.30 | 28 Oct 2024 70,062.40 | 3 | $5.03 |
| long | 28 Oct 2024 68,021.70 | 28 Oct 2024 70,062.40 | 0 | $0.01 |
| long | 28 Oct 2024 68,021.70 | 28 Oct 2024 70,238.90 | 0 | $6.05 |
| long | 7 Nov 2024 75,572.00 | 10 Nov 2024 77,872.30 | 3 | $5.70 |
| long | 7 May 2025 96,834.00 | 8 May 2025 99,744.90 | 1 | $5.66 |
| long | 19 May 2025 106,454.00 | 21 May 2025 109,660.00 | 2 | $5.70 |
| long | 8 Jun 2025 105,552.00 | 9 Jun 2025 108,724.00 | 1 | $5.72 |
| long | 24 Jun 2025 105,334.00 | 30 Jun 2025 108,585.00 | 6 | $5.92 |
| long | 21 Apr 2026 75,841.00 | 22 Apr 2026 78,131.10 | 1 | $5.82 |
| long | 2 May 2026 78,231.10 | 4 May 2026 80,588.20 | 2 | $5.84 |
| long | 15 May 2026 81,090.00 | 16 May 2026 78,716.60 | 1 | −$6.53 |
| long | 26 May 2026 77,322.00 | 27 May 2026 75,044.10 | 1 | −$6.52 |
| long | 1 Sep 2026 78,581.30 | 3 Sep 2026 80,901.50 | 2 | $5.67 |
| long | 4 Sep 2026 81,270.40 | 7 Sep 2026 78,860.10 | 3 | −$6.56 |
| long | 15 Sep 2026 78,189.20 | 16 Sep 2026 75,644.50 | 1 | −$7.11 |
| long | 19 Sep 2026 80,883.90 | 21 Sep 2026 83,319.20 | 2 | $5.75 |
| long | 2 Oct 2026 84,880.10 | 8 Oct 2026 82,380.40 | 6 | −$6.47 |
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 |
|---|---|---|---|---|---|
| Pyramiding Entries On Early Trends (by Coinrule) this page | — | v3 strategy | +2.3% | 20 | 2.2% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 15 ms | Yes 1,000 bars in 43 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/ // © Coinrule //@version=3strategy(shorttitle='Pyramiding Entry On Early Trends',title='Pyramiding Entry On Early Trends (by Coinrule)', overlay=false, pyramiding= 7, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.1) //Backtest datesfromMonth = input(defval = 1, title = "From Month") fromDay = input(defval = 10, title = "From Day") fromYear = input(defval = 2020, title = "From Year") thruMonth = input(defval = 1, title = "Thru Month") thruDay = input(defval = 1, title = "Thru Day") thruYear = input(defval = 2112, title = "Thru Year") showDate = input(defval = true, title = "Show Date Range") start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start windowfinish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish windowwindow() => time >= start and time <= finish ? true : false // create function "within window of time" //MA inputs and calculationsinSignal=input(9, title='MAfast')inlong1=input(100, title='MAslow')inlong2=input(200, title='MAlong') MAfast= sma(close, inSignal)MAslow= sma(close, inlong1)MAlong= sma(close, inlong2) Bullish = crossover(close, MAfast) longsignal = (Bullish and MAfast > MAslow and MAslow < MAlong and window()) //set take profit ProfitTarget_Percent = input(3)Profit_Ticks = (close * (ProfitTarget_Percent / 100)) / syminfo.mintick //set take profit LossTarget_Percent = input(3)Loss_Ticks = (close * (LossTarget_Percent / 100)) / syminfo.mintick //Order Placing strategy.entry("Entry 1", strategy.long, when = (strategy.opentrades == 0) and longsignal) strategy.entry("Entry 2", strategy.long, when = (strategy.opentrades == 1) and longsignal) strategy.entry("Entry 3", strategy.long, when = (strategy.opentrades == 2) and longsignal) strategy.entry("Entry 4", strategy.long, when = (strategy.opentrades == 3) and longsignal) strategy.entry("Entry 5", strategy.long, when = (strategy.opentrades == 4) and longsignal) strategy.entry("Entry 6", strategy.long, when = (strategy.opentrades == 5) and longsignal) strategy.entry("Entry 7", strategy.long, when = (strategy.opentrades == 6) and longsignal) if (strategy.position_size > 0) strategy.exit(id="Exit 1", from_entry = "Entry 1", profit = Profit_Ticks, loss = Loss_Ticks) strategy.exit(id="Exit 2", from_entry = "Entry 2", profit = Profit_Ticks, loss = Loss_Ticks) strategy.exit(id="Exit 3", from_entry = "Entry 3", profit = Profit_Ticks, loss = Loss_Ticks) strategy.exit(id="Exit 4", from_entry = "Entry 4", profit = Profit_Ticks, loss = Loss_Ticks) strategy.exit(id="Exit 5", from_entry = "Entry 5", profit = Profit_Ticks, loss = Loss_Ticks) strategy.exit(id="Exit 6", from_entry = "Entry 6", profit = Profit_Ticks, loss = Loss_Ticks) strategy.exit(id="Exit 7", from_entry = "Entry 7", profit = Profit_Ticks, loss = Loss_Ticks)