Pine Script v4 · Strategy
Etlers Instantenous Trendline
A Pine Script v4 strategy built on Crossover (trigger, itrend) and Crossunder (trigger, itrend). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 9 settings; defaults include Capital Settings Initial, Manual Position Size 100.3 and Leverage 1.
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 Etlers Instantenous Trendline repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 23 of 23 trades.
- How did Etlers Instantenous Trendline do on BTCUSDT 1D with default settings?
- +13.21%
- From 26 Jan 2024 to 21 Oct 2026, over 58 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Etlers Instantenous Trendline be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Etlers Instantenous Trendline use a stop loss?
- Yes
- strategy.exit sets a stop on line 47, 58.
- Does Etlers Instantenous Trendline run in Zeal Terminal?
- Yes
- It compiles in 26 ms and runs 1,000 bars in 63 ms, in the browser.
BTCUSDT · 1D · default settings
- Trigger
- ITrend
- Long Stop Loss
- Short Stop Loss
- Long Stop Loss
- Short Stop Loss
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +13.21%
- $13,211.60
- Buy and hold
- +102.5%
- same period
- Closed trades
- 58
- 31 won · 25 lost
- Profitable
- 53.4%
- of closed trades
- Profit factor
- 1.38
- gross profit ÷ gross loss
- Max drawdown
- 15.99%
- −$18,205.30
One run with the author's default settings, $100,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
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.
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 floor → math.floor, security → request.security, pow → math.pow, crossover → ta.crossover, crossunder → ta.crossunder.
v4 → v5
DiffersTrades differ: 58 before, 75 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 8: input(type = input.string) → input.string()
- Line 9: input(type = input.float) → input.float()
- Line 10: input(type = input.float) → input.float()
- Line 12: floor → math.floor
- Line 13: floor → math.floor
12 more edits
- Line 19: input(type = input.float) → input.float()
- Line 20: input(type = input.float) → input.float()
- Line 28: input(type = input.source) → input.source()
- Line 29: input(type = input.resolution) → input.timeframe()
- Line 30: security → request.security
- Line 31: input(type = input.float) → input.float()
- Line 33: pow → math.pow
- Line 33: pow → math.pow
- Line 34: pow → math.pow
- Line 34: pow → math.pow
- Line 42: crossover → ta.crossover
- Line 43: crossunder → ta.crossunder
⋯// © greenmask9, @cheatcountry-//@version=4+//@version=5strategy(title= "Etlers Instantenous Trendline", shorttitle = "Instantenous Trendline", overlay=true)⋯//Capital Management-capitaltype = input(defval="Initial", title="Capital Settings", options=["Initial", "Growing","Manual"], type=input.string)+capitaltype = input.string(defval="Initial", title="Capital Settings", options=["Initial", "Growing","Manual"])-manualcapital = input(title="Manual Position Size", defval=100.3, type=input.float)+manualcapital = input.float(title="Manual Position Size", defval=100.3)-leverage = input(title="Leverage", defval=1, type=input.float)+leverage = input.float(title="Leverage", defval=1)capitalsystem(capitaltype) =>- v1 = floor(strategy.initial_capital/close) * leverage+ v1 = math.floor(strategy.initial_capital/close) * leverage- v2 = floor((strategy.initial_capital + strategy.netprofit)/close) * leverage+ v2 = math.floor((strategy.initial_capital + strategy.netprofit)/close) * leverage v3 = manualcapital⋯percentages = input(title="Percentage stop 🎯", defval=true)-targetpercentage = input(title="Profit (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01+targetpercentage = input.float(title="Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01-stoppercentage = input(title="Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01+stoppercentage = input.float(title="Stop Loss (%)", minval=0.0, step=0.1, defval=1) * 0.01longtp = strategy.position_avg_price * (1 + targetpercentage)⋯// Ehlers Instantaneous Trendline V2 [CC] script may be freely distributed under the MIT license.-inp = input(title="Source", type=input.source, defval=hl2)+inp = input.source(title="Source", defval=hl2)-res = input(title="Resolution", type=input.resolution, defval="")+res = input.timeframe(title="Resolution", defval="")-src = security(syminfo.tickerid, res, inp[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]+src = request.security(syminfo.tickerid, res, inp[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]-alpha = input(title="Alpha", type=input.float, defval=0.07, minval=0.01, step = 0.01)+alpha = input.float(title="Alpha", defval=0.07, minval=0.01, step = 0.01)itrend = 0.0-itrend := bar_index < 7 ? (src + (2 * nz(src[1])) + nz(src[2])) / 4 : ((alpha - (pow(alpha, 2) / 4)) * src) + (0.5 * pow(alpha, 2) * nz(src[1])) - +itrend := bar_index < 7 ? (src + (2 * nz(src[1])) + nz(src[2])) / 4 : ((alpha - (math.pow(alpha, 2) / 4)) * src) + (0.5 * math.pow(alpha, 2) * nz(src[1])) - - ((alpha - (0.75 * pow(alpha, 2))) * nz(src[2])) + (2 * (1 - alpha) * nz(itrend[1])) - (pow(1 - alpha, 2) * nz(itrend[2]))+ ((alpha - (0.75 * math.pow(alpha, 2))) * nz(src[2])) + (2 * (1 - alpha) * nz(itrend[1])) - (math.pow(1 - alpha, 2) * nz(itrend[2]))trigger = (2 * itrend) - nz(itrend[2])⋯//Things-buy = crossover(trigger, itrend)+buy = ta.crossover(trigger, itrend)-sell = crossunder(trigger, itrend)+sell = ta.crossunder(trigger, itrend)if (buy)⋯Clean v5
VerifiedSame 75 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 18: input() → input.bool()
⋯//Targets, Stops-percentages = input(title="Percentage stop 🎯", defval=true)+percentages = input.bool(title="Percentage stop 🎯", defval=true)targetpercentage = input.float(title="Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01⋯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: 75 before, 58 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.
⋯// © greenmask9, @cheatcountry-//@version=5+//@version=6strategy(title= "Etlers Instantenous Trendline", shorttitle = "Instantenous Trendline", overlay=true)⋯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 |
|---|---|---|---|
| Capital Settings | Initial | string · options ["Initial", "Growing","Manual"] | ordersize line 15 |
| Manual Position Size | 100.3 | float | v3 |
| Leverage | 1 | float | v1 v2 |
| Percentage stop 🎯 | true | bool | exit Buy exit Short line 46 line 57 |
| Profit (%) | 1 | float · min 0.0 · step 0.1 | longtp shorttp |
| Stop Loss (%) | 1 | float · min 0.0 · step 0.1 | longStopPrice shortStopPrice |
| Source | hl2 | source | src |
| Resolution | | timeframe (written input.resolution) | src |
| Alpha | 0.07 | float · min 0.01 · step 0.01 | itrend |
What it calculates
- Crossover (
crossover,ta.crossoverin v5)trigger, itrendbuy · line 42 - Crossunder (
crossunder,ta.crossunderin v5)trigger, itrendsell · line 43
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 | (buy) | On | 45 |
| Exit Buy stop and limit | (percentages) | On | 47 |
| Open Short short | (sell) | On | 56 |
| Exit Short stop and limit | (percentages) | On | 58 |
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 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.
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 | +13.2% | +102.5% | 58 | 53% | 1.38 | 16.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +5.7% | +5.5% | 78 | 55% | 1.24 | 4.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −14.3% | +9.8% | 87 | 39% | 0.87 | 38.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +18.6% | +8.4% | 100 | 57% | 1.50 | 5.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −59.1% | +16.7% | 83 | 39% | 0.62 | 67.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +25.5% | +21.5% | 74 | 61% | 1.90 | 4.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.3% | +148.3% | 83 | 46% | 1.00 | 24.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −2.8% | +17.1% | 80 | 48% | 0.93 | 8.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 | 18 | 72% | $17,149.10 |
| Sideways market | 18 | 56% | $3,489.49 |
| Falling market | 22 | 36% | −$7,427.01 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
13.4%
The 95th percentile of the worst drawdown when the same 58 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 6.3% to 13.4%; the tick is what actually happened, 13.9%. Order luck alone moves it this much.
All 58 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 21 Mar 2024 67,840.50 | 22 Mar 2024 65,501.30 | 1 | $2,339.23 |
| long | 28 Mar 2024 69,470.00 | 29 Mar 2024 70,780.60 | 1 | $1,310.61 |
| short | 5 Apr 2024 68,487.80 | 6 Apr 2024 67,802.90 | 1 | $684.88 |
| long | 10 Apr 2024 69,146.00 | 11 Apr 2024 70,631.10 | 1 | $1,485.08 |
| short | 15 Apr 2024 65,661.90 | 16 Apr 2024 63,420.00 | 1 | $2,241.86 |
| long | 26 Apr 2024 64,498.30 | 27 Apr 2024 63,770.00 | 1 | −$728.33 |
| short | 27 Apr 2024 63,770.00 | 27 Apr 2024 63,770.00 | 0 | $0.00 |
| long | 8 May 2024 62,312.10 | 9 May 2024 61,193.00 | 1 | −$1,119.04 |
| short | 10 May 2024 63,074.00 | 11 May 2024 60,800.00 | 1 | $2,274.01 |
| long | 17 May 2024 65,235.20 | 18 May 2024 67,024.00 | 1 | $1,788.79 |
| short | 14 Jun 2024 66,773.00 | 15 Jun 2024 66,044.00 | 1 | $729.02 |
| long | 17 Jul 2024 65,044.00 | 18 Jul 2024 64,088.00 | 1 | −$956.01 |
| short | 4 Aug 2024 60,698.00 | 5 Aug 2024 58,161.00 | 1 | $2,536.99 |
| long | 24 Aug 2024 64,037.20 | 25 Aug 2024 64,677.60 | 1 | $640.38 |
| short | 30 Aug 2024 59,359.00 | 31 Aug 2024 58,765.40 | 1 | $593.59 |
| long | 15 Sep 2024 59,993.00 | 16 Sep 2024 59,132.00 | 1 | −$861.02 |
| short | 4 Oct 2024 60,752.70 | 5 Oct 2024 62,086.00 | 1 | −$1,333.28 |
| long | 9 Oct 2024 62,160.50 | 10 Oct 2024 60,636.00 | 1 | −$1,524.49 |
| short | 11 Oct 2024 60,326.40 | 12 Oct 2024 62,540.00 | 1 | −$2,213.59 |
| long | 15 Oct 2024 66,084.00 | 16 Oct 2024 67,074.10 | 1 | $990.14 |
| short | 6 Nov 2024 69,372.00 | 7 Nov 2024 75,572.00 | 1 | −$6,199.98 |
| long | 8 Nov 2024 75,857.90 | 9 Nov 2024 76,616.50 | 1 | $758.58 |
| short | 22 Dec 2024 97,292.00 | 23 Dec 2024 95,186.30 | 1 | $2,105.72 |
| long | 6 Jan 2025 98,363.60 | 7 Jan 2025 102,236.00 | 1 | $3,871.99 |
| short | 11 Jan 2025 94,726.10 | 12 Jan 2025 93,778.80 | 1 | $947.27 |
| long | 23 Mar 2025 83,840.60 | 24 Mar 2025 86,082.50 | 1 | $2,241.91 |
| short | 1 Apr 2025 82,550.00 | 2 Apr 2025 85,158.40 | 1 | −$2,608.35 |
| long | 5 Apr 2025 83,889.90 | 6 Apr 2025 83,538.00 | 1 | −$351.88 |
| short | 6 Apr 2025 83,538.00 | 6 Apr 2025 83,051.00 | 0 | $487.02 |
| long | 14 Apr 2025 83,760.00 | 15 Apr 2025 84,597.60 | 1 | $837.60 |
| long | 6 Dec 2025 89,330.00 | 7 Dec 2025 88,436.70 | 1 | −$893.31 |
| short | 9 Dec 2025 90,634.40 | 10 Dec 2025 92,678.80 | 1 | −$2,044.46 |
| long | 11 Dec 2025 92,015.40 | 12 Dec 2025 91,095.20 | 1 | −$920.16 |
| short | 16 Dec 2025 86,432.10 | 17 Dec 2025 87,863.40 | 1 | −$1,431.35 |
| long | 24 Dec 2025 87,486.00 | 25 Dec 2025 88,360.90 | 1 | $874.86 |
| short | 26 Dec 2025 87,225.30 | 29 Dec 2025 88,097.50 | 3 | −$872.26 |
| long | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,600.60 | 1 | −$884.86 |
| short | 23 Jan 2026 89,559.70 | 25 Jan 2026 88,664.10 | 2 | $895.60 |
| long | 5 Mar 2026 72,666.80 | 6 Mar 2026 70,891.00 | 1 | −$1,775.75 |
| short | 11 Mar 2026 69,948.60 | 12 Mar 2026 70,191.90 | 1 | −$243.22 |
| long | 12 Mar 2026 70,191.90 | 12 Mar 2026 70,648.10 | 0 | $456.27 |
| short | 24 Mar 2026 70,906.40 | 25 Mar 2026 71,615.50 | 1 | −$709.07 |
| long | 27 Mar 2026 68,820.30 | 28 Mar 2026 66,407.30 | 1 | −$2,413.03 |
| short | 29 Mar 2026 66,377.00 | 30 Mar 2026 67,040.80 | 1 | −$663.78 |
| long | 8 Apr 2026 71,924.20 | 9 Apr 2026 71,069.90 | 1 | −$854.29 |
| short | 18 May 2026 77,457.70 | 19 May 2026 76,683.10 | 1 | $774.58 |
| long | 18 Jun 2026 64,509.40 | 19 Jun 2026 62,958.00 | 1 | −$1,551.39 |
| short | 20 Jun 2026 63,543.90 | 21 Jun 2026 64,298.00 | 1 | −$754.11 |
| long | 6 Jul 2026 63,650.00 | 7 Jul 2026 64,286.50 | 1 | $636.51 |
| short | 31 Jul 2026 64,780.00 | 1 Aug 2026 62,887.90 | 1 | $1,892.15 |
| long | 2 Aug 2026 62,823.70 | 3 Aug 2026 63,570.00 | 1 | $746.36 |
| short | 3 Aug 2026 63,570.00 | 3 Aug 2026 63,570.00 | 0 | $0.00 |
| long | 7 Aug 2026 64,323.60 | 8 Aug 2026 64,966.80 | 1 | $643.24 |
| short | 14 Aug 2026 63,490.90 | 16 Aug 2026 62,855.90 | 2 | $634.91 |
| long | 21 Aug 2026 73,027.00 | 22 Aug 2026 78,338.00 | 1 | $5,311.01 |
| short | 13 Sep 2026 77,278.70 | 14 Sep 2026 76,505.90 | 1 | $772.79 |
| long | 21 Sep 2026 81,178.00 | 22 Sep 2026 86,620.00 | 1 | $5,442.00 |
| short | 10 Oct 2026 82,635.60 | 11 Oct 2026 83,461.90 | 1 | −$826.36 |
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 | Yes 26 ms | Yes 1,000 bars in 63 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/// © greenmask9, @cheatcountry//@version=4strategy(title= "Etlers Instantenous Trendline", shorttitle = "Instantenous Trendline", overlay=true)//commission_type=strategy.commission.percent, commission_value=.5////Capital Managementcapitaltype = input(defval="Initial", title="Capital Settings", options=["Initial", "Growing","Manual"], type=input.string)manualcapital = input(title="Manual Position Size", defval=100.3, type=input.float)leverage = input(title="Leverage", defval=1, type=input.float)capitalsystem(capitaltype) => v1 = floor(strategy.initial_capital/close) * leverage v2 = floor((strategy.initial_capital + strategy.netprofit)/close) * leverage v3 = manualcapital capitaltype== "Initial"? v1 : capitaltype == "Growing" ? v2 : v3ordersize=capitalsystem(capitaltype)//Targets, Stopspercentages = input(title="Percentage stop 🎯", defval=true)targetpercentage = input(title="Profit (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01stoppercentage = input(title="Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01longtp = strategy.position_avg_price * (1 + targetpercentage)shorttp = strategy.position_avg_price * (1 - targetpercentage)longStopPrice = strategy.position_avg_price * (1 - stoppercentage)shortStopPrice = strategy.position_avg_price * (1 + stoppercentage)//Cheatcountry's part// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)// Ehlers Instantaneous Trendline V2 [CC] script may be freely distributed under the MIT license.inp = input(title="Source", type=input.source, defval=hl2)res = input(title="Resolution", type=input.resolution, defval="")src = security(syminfo.tickerid, res, inp[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]alpha = input(title="Alpha", type=input.float, defval=0.07, minval=0.01, step = 0.01)itrend = 0.0itrend := bar_index < 7 ? (src + (2 * nz(src[1])) + nz(src[2])) / 4 : ((alpha - (pow(alpha, 2) / 4)) * src) + (0.5 * pow(alpha, 2) * nz(src[1])) - ((alpha - (0.75 * pow(alpha, 2))) * nz(src[2])) + (2 * (1 - alpha) * nz(itrend[1])) - (pow(1 - alpha, 2) * nz(itrend[2]))trigger = (2 * itrend) - nz(itrend[2])sig = trigger > itrend ? 1 : trigger < itrend ? -1 : 0itColor = sig > 0 ? color.green : sig < 0 ? color.red : color.blackplot(trigger, title="Trigger", color=itColor, linewidth=2)plot(itrend, title="ITrend", color=color.black, linewidth=1)//End Cheatcountry's part//Thingsbuy = crossover(trigger, itrend)sell = crossunder(trigger, itrend)if (buy) strategy.entry("Buy", strategy.long, ordersize)if (percentages) strategy.exit( "Buy", from_entry="Buy", stop=longStopPrice, limit= longtp)// if (target and stop)// strategy.exit( "Set Value tp/sl", from_entry="Buy", profit=targetticks, loss=stopnumberticks)// if (target and not stop)// strategy.exit( "Set Value tp/sl", from_entry="Buy", profit=targetticks)// if (stop and not target)// strategy.exit( "Set Value tp/sl", from_entry="Buy", loss=stopnumberticks)//strategy.close("Buy", buyend)if (sell) strategy.entry("Short", strategy.short, ordersize)if (percentages) strategy.exit( "Short", from_entry="Short", stop=shortStopPrice, limit = shorttp)plot(series=(strategy.position_size > 0) ? longStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="Long Stop Loss")plot(series=(strategy.position_size < 0) ? shortStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="Short Stop Loss")plot(series=(strategy.position_size > 0) ? longtp : na, color=color.lime, style=plot.style_linebr, linewidth=2, title="Long Stop Loss")plot(series=(strategy.position_size < 0) ? shorttp : na, color=color.lime, style=plot.style_linebr, linewidth=2, title="Short Stop Loss")