Pine Script v4 · Strategy
Coppock Curve Strategy
A Pine Script v4 strategy built on WMA or ROC (source, shortRoCLength, 10). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a profit target and no stop loss. Each trade commits 10000 in cash and pays no commission. 10 settings; defaults include Take Profit % (How much stock has to rise from entry to trigger take profit) Using tighter % will have higher win rates (try 5% as an example). Using looser will produce bigger winners w/ lower win rates. 50, Take Profit % QTY (How much profit you want to take after take profit target is triggered) 25 and Change this if you want to see Copp Curve calculated for current ticker. All Copp Curve calculations are base on NYSE Composite NYA.
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 Coppock Curve Strategy repaint?
- No
- No repainting patterns were found in the source.
- Can Coppock Curve Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but the original does not run in Zeal Terminal's engine, so they could not be checked.
- Does Coppock Curve Strategy use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does Coppock Curve Strategy run in Zeal Terminal?
- No
- Not yet: [Context.call] Execution error for ID "security@L12:C9": The provided reference is not a function. Check if the function exists in the stdlib.
Review
What a careful reader of this script would point out, found by checking the source.
-
Check
1 setting does nothing
“Standard Copp settings are (10, 14, 11) however, DOUBLE these lengths as alternate settings to (20,28,22) and you will find it may produce better results, but less trades” is declared but never read.
-
Check
No stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
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.
-
Note
Uses transp =, which v5 removed line 24
transp = on line 24, 25. 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 security → request.security, wma → ta.wma, roc → ta.roc.
v4 → v5
Not verifiedThe v4 script does not run in Zeal Terminal's engine ([Context.call] Execution error for ID "security@L12:C9": The provided reference is not a function. Check if the function exists in the stdlib.), so this step could not be checked.
- Line 3: //@version=4 → //@version=5
- Line 12: security → request.security
- Line 15: input(type = input.integer) → input.int()
- Line 16: input(type = input.integer) → input.int()
- Line 17: input(type = input.integer) → input.int()
- Line 19: wma → ta.wma
4 more edits
- Line 19: roc → ta.roc
- Line 19: roc → ta.roc
- Line 24: transp = 90 → color.new(color.green, 90)
- Line 25: transp = 90 → color.new(color.red, 90)
⋯// © RolandoSantos-//@version=4+//@version=5strategy(title = "Coppock Curve", shorttitle = "Copp Curve Strat", default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000)⋯security = input("NYA", title="Change this if you want to see Copp Curve calculated for current ticker. All Copp Curve calculations are base on NYSE Composite")-ticker = security(security,"", close)+ticker = request.security(security,"", close)///Copp Curve////instructions =input(title="Standard Copp settings are (10, 14, 11) however, DOUBLE these lengths as alternate settings to (20,28,22) and you will find it may produce better results, but less trades", defval="-")-wmaLength = input(title="WMA Length (Experiment changing this to longer lengths for less trades, but higher win %)", type=input.integer, defval=10)+wmaLength = input.int(title="WMA Length (Experiment changing this to longer lengths for less trades, but higher win %)", defval=10)-longRoCLength = input(title="Long RoC Length", type=input.integer, defval=14)+longRoCLength = input.int(title="Long RoC Length", defval=14)-shortRoCLength = input(title="Short RoC Length", type=input.integer, defval=11)+shortRoCLength = input.int(title="Short RoC Length", defval=11)source = ticker-curve = wma(roc(source, longRoCLength) + roc(source, shortRoCLength), wmaLength)+curve = ta.wma(ta.roc(source, longRoCLength) + ta.roc(source, shortRoCLength), wmaLength)///Lower Band Plot///⋯band2 = hline(-100)-fill(band1, band0, color=color.green, transp=90)+fill(band1, band0, color=color.new(color.green, 90))-fill(band2, band1, color=color.red, transp=90)+fill(band2, band1, color=color.new(color.red, 90))copp_color = curve[1] < curve[0] ? curve[0] >= 0 ? #00ffff : #ffb74d : curve[0] >= 0 ? #009b9b : #f57c00⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 11: input() → input.string()
- Line 14: input() → input.string()
- Line 32: input() → input.int()
- Line 33: input() → input.int()
- Line 34: input() → input.int()
⋯//Make inputs that set the take profit % -longProfitPerc = input(title="Take Profit % (How much stock has to rise from entry to trigger take profit) Using tighter % will have higher win rates (try 5% as an example). Using looser will produce bigger winners w/ lower win rates.", minval=0.0, step=0.1, defval=50) / 100+longProfitPerc = input.int(title="Take Profit % (How much stock has to rise from entry to trigger take profit) Using tighter % will have higher win rates (try 5% as an example). Using looser will produce bigger winners w/ lower win rates.", minval=0.0, step=0.1, defval=50) / 100-tp = input(25, "Take Profit % QTY (How much profit you want to take after take profit target is triggered)")+tp = input.int(25, "Take Profit % QTY (How much profit you want to take after take profit target is triggered)")// Figure out take profit price⋯//Use NYSE for Copp Curve entries and exits//-security = input("NYA", title="Change this if you want to see Copp Curve calculated for current ticker. All Copp Curve calculations are base on NYSE Composite")+security = input.string("NYA", title="Change this if you want to see Copp Curve calculated for current ticker. All Copp Curve calculations are base on NYSE Composite")ticker = request.security(security,"", close)///Copp Curve////-instructions =input(title="Standard Copp settings are (10, 14, 11) however, DOUBLE these lengths as alternate settings to (20,28,22) and you will find it may produce better results, but less trades", defval="-")+instructions =input.string(title="Standard Copp settings are (10, 14, 11) however, DOUBLE these lengths as alternate settings to (20,28,22) and you will find it may produce better results, but less trades", defval="-")wmaLength = input.int(title="WMA Length (Experiment changing this to longer lengths for less trades, but higher win %)", defval=10)⋯/// Start date-startDate = input(title="Start Date", defval=1, minval=1, maxval=31)+startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31)-startMonth = input(title="Start Month", defval=1, minval=1, maxval=12)+startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)-startYear = input(title="Start Year", defval=1970, minval=1800, maxval=2100)+startYear = input.int(title="Start Year", defval=1970, minval=1800, maxval=2100)// See if this bar's time happened on/after start date⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © RolandoSantos-//@version=5+//@version=6strategy(title = "Coppock Curve", shorttitle = "Copp Curve Strat", default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000)⋯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 |
|---|---|---|---|
| Take Profit % (How much stock has to rise from entry to trigger take profit) Using tighter % will have higher win rates (try 5% as an example). Using looser will produce bigger winners w/ lower win rates. | 50 | int · min 0.0 · step 0.1 | longExitPrice |
| Take Profit % QTY (How much profit you want to take after take profit target is triggered) | 25 | int | exit Long Take Profit |
| Change this if you want to see Copp Curve calculated for current ticker. All Copp Curve calculations are base on NYSE Composite | NYA | string | ticker |
| Standard Copp settings are (10, 14, 11) however, DOUBLE these lengths as alternate settings to (20,28,22) and you will find it may produce better results, but less trades | - | string | unused |
| WMA Length (Experiment changing this to longer lengths for less trades, but higher win %) | 10 | int (written input.integer) | curve |
| Long RoC Length | 14 | int (written input.integer) | curve |
| Short RoC Length | 11 | int (written input.integer) | curve |
| Start Date | 1 | int · min 1 · max 31 | afterStartDate |
| Start Month | 1 | int · min 1 · max 12 | afterStartDate |
| Start Year | 1970 | int · min 1800 · max 2100 | afterStartDate |
What it calculates
- WMA / ROC (
wma,ta.wmain v5)roc(source, longRoCLength) + roc(source, shortRoCLength), WMA Length (Experiment changing this to longer lengths for less trades, but higher win %) (10)curve · line 19
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 Long long | (Bull and afterStartDate) | On | 39 |
| Close Long | (Bear and afterStartDate) | On | 42 |
| Exit Long Take Profit limit | (strategy.position_size > 0 and afterStartDate) | On | 45 |
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.
The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.
- ClearHigher-timeframe data1 security call(s), none with lookahead on.
- 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.
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No [Context.call] Execution error for ID "security@L12:C9": The provided reference is not a function. Check if the function exists in the stdlib. | 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/// © RolandoSantos//@version=4strategy(title = "Coppock Curve", shorttitle = "Copp Curve Strat", default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000)//Make inputs that set the take profit % longProfitPerc = input(title="Take Profit % (How much stock has to rise from entry to trigger take profit) Using tighter % will have higher win rates (try 5% as an example). Using looser will produce bigger winners w/ lower win rates.", minval=0.0, step=0.1, defval=50) / 100tp = input(25, "Take Profit % QTY (How much profit you want to take after take profit target is triggered)")// Figure out take profit pricelongExitPrice = strategy.position_avg_price * (1 + longProfitPerc)//Use NYSE for Copp Curve entries and exits//security = input("NYA", title="Change this if you want to see Copp Curve calculated for current ticker. All Copp Curve calculations are base on NYSE Composite")ticker = security(security,"", close)///Copp Curve////instructions =input(title="Standard Copp settings are (10, 14, 11) however, DOUBLE these lengths as alternate settings to (20,28,22) and you will find it may produce better results, but less trades", defval="-")wmaLength = input(title="WMA Length (Experiment changing this to longer lengths for less trades, but higher win %)", type=input.integer, defval=10)longRoCLength = input(title="Long RoC Length", type=input.integer, defval=14)shortRoCLength = input(title="Short RoC Length", type=input.integer, defval=11)source = tickercurve = wma(roc(source, longRoCLength) + roc(source, shortRoCLength), wmaLength)///Lower Band Plot///band1 = hline(0)band0 = hline(100)band2 = hline(-100)fill(band1, band0, color=color.green, transp=90)fill(band2, band1, color=color.red, transp=90)copp_color = curve[1] < curve[0] ? curve[0] >= 0 ? #00ffff : #ffb74d : curve[0] >= 0 ? #009b9b : #f57c00plot(curve, color=copp_color, style=plot.style_histogram)///Trade Conditions///Bull = curve > 0Bear = curve < 0/// Start datestartDate = input(title="Start Date", defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", defval=1, minval=1, maxval=12)startYear = input(title="Start Year", defval=1970, minval=1800, maxval=2100)// See if this bar's time happened on/after start dateafterStartDate = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))///Entries and Exits//if (Bull and afterStartDate) strategy.entry("Long", strategy.long, comment = "LE") if (Bear and afterStartDate) strategy.close("Long", qty_percent=100, comment="close")// Submit exit orders based on take profit priceif (strategy.position_size > 0 and afterStartDate) strategy.exit(id="Long Take Profit", qty_percent=tp, limit=longExitPrice)