Pine Script v4 · Strategy
ETF trader
A Pine Script v4 strategy built on ATR (14), Lowest (close, 4) and Highest (close, 4). It has 23 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays no commission. 9 settings; defaults include HH LL lookback 20, ATR period 14 and ATR SL multiplier 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 ETF trader repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
- How did ETF trader do on BTCUSDT 1D with default settings?
- +78.30%
- From 26 Jan 2024 to 21 Oct 2026, over 17 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can ETF trader 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 ETF trader use a stop loss?
- Yes
- strategy.exit sets a stop on line 56, 60.
- Does ETF trader run in Zeal Terminal?
- Yes
- It compiles in 37 ms and runs 1,000 bars in 44 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +78.30%
- $78,302.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 17
- 6 won · 11 lost
- Profitable
- 35.3%
- of closed trades
- Profit factor
- 1.59
- gross profit ÷ gross loss
- Max drawdown
- 32.74%
- −$70,577.10
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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 crossover → ta.crossover, highest → ta.highest, crossunder → ta.crossunder, lowest → ta.lowest, atr → ta.atr, tostring → str.tostring.
v4 → v5
DiffersTrades differ: 17 before, 17 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.integer) → input.int()
- Line 7: input(type = input.integer) → input.int()
- Line 8: input(type = input.float) → input.float()
- Line 9: input(type = input.float) → input.float()
- Line 10: input(type = input.float) → input.float()
40 more edits
- Line 11: input(type = input.integer) → input.int()
- Line 12: input(type = input.float) → input.float()
- Line 13: input(type = input.bool) → input.bool()
- Line 14: input(type = input.bool) → input.bool()
- Line 16: crossover → ta.crossover
- Line 16: highest → ta.highest
- Line 17: crossunder → ta.crossunder
- Line 17: lowest → ta.lowest
- Line 38: atr → ta.atr
- Line 39: atr → ta.atr
- Line 40: atr → ta.atr
- Line 43: lowest → ta.lowest
- Line 44: highest → ta.highest
- Line 45: crossover → ta.crossover
- Line 46: crossunder → ta.crossunder
- Line 55: tostring → str.tostring
- Line 56: tostring → str.tostring
- Line 57: tostring → str.tostring
- Line 59: tostring → str.tostring
- Line 60: tostring → str.tostring
- Line 61: tostring → str.tostring
- Line 65: tostring → str.tostring
- Line 66: tostring → str.tostring
- Line 67: tostring → str.tostring
- Line 68: tostring → str.tostring
- Line 69: tostring → str.tostring
- Line 70: tostring → str.tostring
- Line 71: tostring → str.tostring
- Line 72: tostring → str.tostring
- Line 73: tostring → str.tostring
- Line 76: tostring → str.tostring
- Line 77: tostring → str.tostring
- Line 78: tostring → str.tostring
- Line 79: tostring → str.tostring
- Line 80: tostring → str.tostring
- Line 81: tostring → str.tostring
- Line 82: tostring → str.tostring
- Line 83: tostring → str.tostring
- Line 84: tostring → str.tostring
- Line 85: tostring → str.tostring
⋯// © FX_minds-//@version=4+//@version=5strategy("ETF trader", overlay=true, pyramiding=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100)//------------------------------ get user input-lookback = input(title="HH LL lookback", type=input.integer, defval=20)+lookback = input.int(title="HH LL lookback", defval=20)-ATR_periode = input(title="ATR period", type=input.integer, defval=14)+ATR_periode = input.int(title="ATR period", defval=14)-ATR_SL_multiplier = input(title="ATR SL multiplier", type=input.float, defval=2)+ATR_SL_multiplier = input.float(title="ATR SL multiplier", defval=2)-ATR_TP_multiplier = input(title="ATR TP multiplier", type=input.float, defval=1)+ATR_TP_multiplier = input.float(title="ATR TP multiplier", defval=1)-trailing_SL_ATR_multiplier = input(title="ATR trailing SL multiplier", type=input.float, defval=3.5)+trailing_SL_ATR_multiplier = input.float(title="ATR trailing SL multiplier", defval=3.5)-lookback_trailing_SL = input(title="trailing SL lookback", type=input.integer, defval=4)+lookback_trailing_SL = input.int(title="trailing SL lookback", defval=4)-max_sequel_trades = input(title="max sequel trades", type=input.float, defval=1)+max_sequel_trades = input.float(title="max sequel trades", defval=1)-trade_long = input(title= "trade long ?", type=input.bool, defval=true)+trade_long = input.bool(title= "trade long ?", defval=true)-trade_short = input(title= "trade short ?", type=input.bool, defval=false)+trade_short = input.bool(title= "trade short ?", defval=false)//------------------------------ determine entry conditions-long_condition = barstate.isconfirmed and crossover(high, highest(high, lookback)[1])+long_condition = barstate.isconfirmed and ta.crossover(high, ta.highest(high, lookback)[1])-short_condition = barstate.isconfirmed and crossunder(low, lowest(low, lookback)[1])+short_condition = barstate.isconfirmed and ta.crossunder(low, ta.lowest(low, lookback)[1])//------------------------------ count open long trades⋯//------------------------------ calculate SL & TP-SL_distance = atr(ATR_periode) * ATR_SL_multiplier+SL_distance = ta.atr(ATR_periode) * ATR_SL_multiplier-TP_distance = atr(ATR_periode) * ATR_TP_multiplier+TP_distance = ta.atr(ATR_periode) * ATR_TP_multiplier-trailing_SL_distance = atr(ATR_periode) * trailing_SL_ATR_multiplier+trailing_SL_distance = ta.atr(ATR_periode) * trailing_SL_ATR_multiplierSL_long = entryprice_long - SL_distanceSL_short = entryprice_short + SL_distance-trailing_SL_short = lowest(close, lookback_trailing_SL) + trailing_SL_distance+trailing_SL_short = ta.lowest(close, lookback_trailing_SL) + trailing_SL_distance-trailing_SL_long = highest(close, lookback_trailing_SL) - trailing_SL_distance+trailing_SL_long = ta.highest(close, lookback_trailing_SL) - trailing_SL_distance-trailing_SL_short_signal = crossover(high, trailing_SL_short[1])+trailing_SL_short_signal = ta.crossover(high, trailing_SL_short[1])-trailing_SL_long_signal = crossunder(low, trailing_SL_long[1])+trailing_SL_long_signal = ta.crossunder(low, trailing_SL_long[1])//------------------------------ plot entry price & SL ⋯if (long_condition) and (count_open_longs <= max_sequel_trades) and (trade_long == true)- strategy.entry("Long" + tostring(count_open_longs, "#"), strategy.long)+ strategy.entry("Long" + str.tostring(count_open_longs, "#"), strategy.long)- strategy.exit("SL Long"+ tostring(count_open_longs, "#"), + strategy.exit("SL Long"+ str.tostring(count_open_longs, "#"), - from_entry="Long" + tostring(count_open_longs, "#"), stop=SL_long)+ from_entry="Long" + str.tostring(count_open_longs, "#"), stop=SL_long)if (short_condition) and (count_open_shorts <= max_sequel_trades) and (trade_short == true)- strategy.entry("Short" + tostring(count_open_shorts, "#"), strategy.short)+ strategy.entry("Short" + str.tostring(count_open_shorts, "#"), strategy.short)- strategy.exit("SL Short" + tostring(count_open_shorts, "#"), + strategy.exit("SL Short" + str.tostring(count_open_shorts, "#"), - from_entry="Short" + tostring(count_open_shorts, "#"), stop=SL_short)+ from_entry="Short" + str.tostring(count_open_shorts, "#"), stop=SL_short) ⋯if (trailing_SL_long_signal)- strategy.close("Long" + tostring(count_open_longs, "#"))+ strategy.close("Long" + str.tostring(count_open_longs, "#"))- strategy.close("Long" + tostring(count_open_longs-1, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-1, "#"))- strategy.close("Long" + tostring(count_open_longs-2, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-2, "#"))- strategy.close("Long" + tostring(count_open_longs-4, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-4, "#"))- strategy.close("Long" + tostring(count_open_longs-5, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-5, "#"))- strategy.close("Long" + tostring(count_open_longs-6, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-6, "#"))- strategy.close("Long" + tostring(count_open_longs-7, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-7, "#"))- strategy.close("Long" + tostring(count_open_longs-8, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-8, "#"))- strategy.close("Long" + tostring(count_open_longs-9, "#"))+ strategy.close("Long" + str.tostring(count_open_longs-9, "#")) if (trailing_SL_short_signal)- strategy.close("Short" + tostring(count_open_shorts, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts, "#"))- strategy.close("Short" + tostring(count_open_shorts-1, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-1, "#"))- strategy.close("Short" + tostring(count_open_shorts-2, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-2, "#"))- strategy.close("Short" + tostring(count_open_shorts-3, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-3, "#"))- strategy.close("Short" + tostring(count_open_shorts-4, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-4, "#"))- strategy.close("Short" + tostring(count_open_shorts-5, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-5, "#"))- strategy.close("Short" + tostring(count_open_shorts-6, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-6, "#"))- strategy.close("Short" + tostring(count_open_shorts-7, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-7, "#"))- strategy.close("Short" + tostring(count_open_shorts-8, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-8, "#"))- strategy.close("Short" + tostring(count_open_shorts-9, "#"))+ strategy.close("Short" + str.tostring(count_open_shorts-9, "#"))Clean v5
VerifiedNothing to change.
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: 17 before, 9 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.
⋯// © FX_minds-//@version=5+//@version=6strategy("ETF trader", overlay=true, pyramiding=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯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 |
|---|---|---|---|
| HH LL lookback | 20 | int (written input.integer) | long_condition short_condition |
| ATR period | 14 | int (written input.integer) | SL_distance TP_distance trailing_SL_distance |
| ATR SL multiplier | 2 | float | SL_distance |
| ATR TP multiplier | 1 | float | TP_distance |
| ATR trailing SL multiplier | 3.5 | float | trailing_SL_distance |
| trailing SL lookback | 4 | int (written input.integer) | trailing_SL_short trailing_SL_long |
| max sequel trades | 1 | float | entry "Long" + tostring(count_open_longs, "#") exit "SL Long"+ tostring(count_open_longs, "#") entry "Short" + tostring(count_open_shorts, "#") exit "SL Short" + tostring(count_open_shorts, "#") line 54 line 58 |
| trade long ? | true | bool | entry "Long" + tostring(count_open_longs, "#") exit "SL Long"+ tostring(count_open_longs, "#") line 54 |
| trade short ? | false | bool | entry "Short" + tostring(count_open_shorts, "#") exit "SL Short" + tostring(count_open_shorts, "#") line 58 |
What it calculates
- ATR (
atr,ta.atrin v5)ATR period (14)SL_distance · line 38 - ATR (
atr,ta.atrin v5)ATR period (14)TP_distance · line 39 - ATR (
atr,ta.atrin v5)ATR period (14)trailing_SL_distance · line 40 - Lowest (
lowest,ta.lowestin v5)close, trailing SL lookback (4)trailing_SL_short · line 43 - Highest (
highest,ta.highestin v5)close, trailing SL lookback (4)trailing_SL_long · line 44 - Crossover (
crossover,ta.crossoverin v5)high, trailing_SL_short[1]trailing_SL_short_signal · line 45 - Crossunder (
crossunder,ta.crossunderin v5)low, trailing_SL_long[1]trailing_SL_long_signal · line 46
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" + tostring(count_open_longs, "#") long | (long_condition) and (count_open_longs <= max_sequel_trades) and (trade_long == true) | On | 55 |
| Exit "SL Long"+ tostring(count_open_longs, "#") stop | (long_condition) and (count_open_longs <= max_sequel_trades) and (trade_long == true) | On | 56 |
| Open "Short" + tostring(count_open_shorts, "#") short | (short_condition) and (count_open_shorts <= max_sequel_trades) and (trade_short == true) | On | 59 |
| Exit "SL Short" + tostring(count_open_shorts, "#") stop | (short_condition) and (count_open_shorts <= max_sequel_trades) and (trade_short == true) | On | 60 |
| Close "Long" + tostring(count_open_longs, "#") | (trailing_SL_long_signal) | On | 65 |
| Close "Long" + tostring(count_open_longs-1, "#") | (trailing_SL_long_signal) | On | 66 |
| Close "Long" + tostring(count_open_longs-2, "#") | (trailing_SL_long_signal) | On | 67 |
| Close "Long" + tostring(count_open_longs-4, "#") | (trailing_SL_long_signal) | On | 68 |
| Close "Long" + tostring(count_open_longs-5, "#") | (trailing_SL_long_signal) | On | 69 |
| Close "Long" + tostring(count_open_longs-6, "#") | (trailing_SL_long_signal) | On | 70 |
| Close "Long" + tostring(count_open_longs-7, "#") | (trailing_SL_long_signal) | On | 71 |
| Close "Long" + tostring(count_open_longs-8, "#") | (trailing_SL_long_signal) | On | 72 |
| Close "Long" + tostring(count_open_longs-9, "#") | (trailing_SL_long_signal) | On | 73 |
| Close "Short" + tostring(count_open_shorts, "#") | (trailing_SL_short_signal) | On | 76 |
| Close "Short" + tostring(count_open_shorts-1, "#") | (trailing_SL_short_signal) | On | 77 |
| Close "Short" + tostring(count_open_shorts-2, "#") | (trailing_SL_short_signal) | On | 78 |
| Close "Short" + tostring(count_open_shorts-3, "#") | (trailing_SL_short_signal) | On | 79 |
| Close "Short" + tostring(count_open_shorts-4, "#") | (trailing_SL_short_signal) | On | 80 |
| Close "Short" + tostring(count_open_shorts-5, "#") | (trailing_SL_short_signal) | On | 81 |
| Close "Short" + tostring(count_open_shorts-6, "#") | (trailing_SL_short_signal) | On | 82 |
| Close "Short" + tostring(count_open_shorts-7, "#") | (trailing_SL_short_signal) | On | 83 |
| Close "Short" + tostring(count_open_shorts-8, "#") | (trailing_SL_short_signal) | On | 84 |
| Close "Short" + tostring(count_open_shorts-9, "#") | (trailing_SL_short_signal) | On | 85 |
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.
- 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 | +78.3% | +102.5% | 17 | 35% | 1.59 | 32.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +5.8% | +5.5% | 15 | 20% | 1.23 | 12.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +56.1% | +9.8% | 11 | 27% | 1.50 | 34.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.1% | +8.4% | 13 | 15% | 1.04 | 16.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −32.7% | +16.7% | 12 | 25% | 0.70 | 44.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +3.2% | +21.5% | 15 | 27% | 1.09 | 14.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +33.3% | +148.3% | 16 | 44% | 1.28 | 29.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +27.6% | +17.1% | 16 | 31% | 2.18 | 20.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 | 6 | 33% | −$19,226.60 |
| Sideways market | 8 | 50% | $143,749.00 |
| Falling market | 3 | 0% | −$46,219.70 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
43.9%
The 95th percentile of the worst drawdown when the same 17 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 20.8% to 43.9%; the tick is what actually happened, 33.0%. Order luck alone moves it this much.
All 17 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 21 Feb 2024 52,258.80 | 6 Mar 2024 63,724.00 | 14 | $21,939.20 |
| long | 16 May 2024 66,206.50 | 24 Jun 2024 60,554.80 | 39 | −$10,409.30 |
| long | 16 Jul 2024 64,724.10 | 4 Aug 2024 59,789.30 | 19 | −$8,503.43 |
| long | 24 Aug 2024 64,037.20 | 27 Aug 2024 58,112.50 | 3 | −$9,532.06 |
| long | 18 Sep 2024 60,314.00 | 2 Feb 2025 96,400.70 | 137 | $55,939.00 |
| long | 15 Oct 2024 66,084.00 | 2 Feb 2025 96,400.70 | 110 | $46,994.80 |
| long | 18 Jan 2025 104,077.00 | 2 Feb 2025 96,400.70 | 15 | −$16,244.10 |
| long | 23 Apr 2025 93,443.00 | 19 Aug 2025 113,261.00 | 118 | $38,214.00 |
| long | 3 Jul 2025 108,850.00 | 19 Aug 2025 113,261.00 | 47 | $8,505.74 |
| long | 12 Aug 2025 118,686.00 | 19 Aug 2025 113,261.00 | 7 | −$11,328.60 |
| long | 16 Sep 2025 115,350.00 | 25 Sep 2025 110,472.00 | 9 | −$9,116.16 |
| long | 2 Oct 2025 118,595.00 | 10 Oct 2025 113,543.00 | 8 | −$8,794.07 |
| long | 10 Dec 2025 92,678.80 | 18 Dec 2025 85,128.70 | 8 | −$16,102.80 |
| long | 5 Mar 2026 72,666.80 | 29 Mar 2026 65,348.50 | 24 | −$18,285.00 |
| long | 9 Apr 2026 71,069.90 | 3 Jun 2026 65,919.80 | 55 | −$11,831.90 |
| long | 15 Jul 2026 65,044.00 | 8 Oct 2026 81,599.50 | 85 | $38,547.00 |
| long | 22 Sep 2026 86,620.00 | 8 Oct 2026 81,599.50 | 16 | −$11,689.60 |
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 |
|---|---|---|---|---|---|
| ETF trader this page | — | v4 strategy | +78.3% | 17 | 32.7% |
| Aggresive Scalper-Swing Crypto Strategy by exlux99 | lowest highest atr | v4 strategy | −7.4% | 3 | 16.0% |
| Donchian Channels Strategy by KrisWaters by kriswaters | highest lowest atr | v4 strategy | +55.8% | 21 | 23.3% |
| Chandelier Exit - Strategy by melihtuna | atr highest lowest | v4 strategy | −34.8% | 11 | 43.2% |
| Chandelier Exit by Zeal Terminal | atr highest lowest | v5 indicator | indicator | ||
| DC Breakout Strategy - This is simplicity at its finest. by Robrecht99 | highest lowest atr | v5 strategy | +10.8% | 57 | 8.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 37 ms | With a workaround 1,000 bars in 44 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © FX_minds//@version=4strategy("ETF trader", overlay=true, pyramiding=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100)//------------------------------ get user inputlookback = input(title="HH LL lookback", type=input.integer, defval=20)ATR_periode = input(title="ATR period", type=input.integer, defval=14)ATR_SL_multiplier = input(title="ATR SL multiplier", type=input.float, defval=2)ATR_TP_multiplier = input(title="ATR TP multiplier", type=input.float, defval=1)trailing_SL_ATR_multiplier = input(title="ATR trailing SL multiplier", type=input.float, defval=3.5)lookback_trailing_SL = input(title="trailing SL lookback", type=input.integer, defval=4)max_sequel_trades = input(title="max sequel trades", type=input.float, defval=1)trade_long = input(title= "trade long ?", type=input.bool, defval=true)trade_short = input(title= "trade short ?", type=input.bool, defval=false)//------------------------------ determine entry conditionslong_condition = barstate.isconfirmed and crossover(high, highest(high, lookback)[1])short_condition = barstate.isconfirmed and crossunder(low, lowest(low, lookback)[1])//------------------------------ count open long tradescount_open_longs = 0count_open_longs := nz(count_open_longs[1])if (long_condition) count_open_longs := count_open_longs +1 //label.new(bar_index, low, tostring(count_open_longs, "#"), xloc.bar_index, yloc.belowbar, color.green, label.style_none, color.green, size.large)if (short_condition) count_open_longs := 0//------------------------------ count open short tradescount_open_shorts = 0count_open_shorts := nz(count_open_shorts[1])if (short_condition) count_open_shorts := count_open_shorts +1 //label.new(bar_index, low, tostring(count_open_shorts, "#"), xloc.bar_index, yloc.belowbar, color.red, label.style_none, color.red, size.large)if (long_condition) count_open_shorts := 0//------------------------------ calculate entrypriceentryprice_long = long_condition ? close : naentryprice_short = short_condition ? close : na//------------------------------ calculate SL & TPSL_distance = atr(ATR_periode) * ATR_SL_multiplierTP_distance = atr(ATR_periode) * ATR_TP_multipliertrailing_SL_distance = atr(ATR_periode) * trailing_SL_ATR_multiplierSL_long = entryprice_long - SL_distanceSL_short = entryprice_short + SL_distancetrailing_SL_short = lowest(close, lookback_trailing_SL) + trailing_SL_distancetrailing_SL_long = highest(close, lookback_trailing_SL) - trailing_SL_distancetrailing_SL_short_signal = crossover(high, trailing_SL_short[1])trailing_SL_long_signal = crossunder(low, trailing_SL_long[1])//------------------------------ plot entry price & SL plot(entryprice_long, style=plot.style_linebr, color=color.white)plot(SL_long, style=plot.style_linebr, color=color.red)plot(SL_short, style=plot.style_linebr, color=color.green)plot(trailing_SL_short, style=plot.style_linebr, color=color.red)plot(trailing_SL_long, style=plot.style_linebr, color=color.green)//------------------------------ submit entry ordersif (long_condition) and (count_open_longs <= max_sequel_trades) and (trade_long == true) strategy.entry("Long" + tostring(count_open_longs, "#"), strategy.long) strategy.exit("SL Long"+ tostring(count_open_longs, "#"), from_entry="Long" + tostring(count_open_longs, "#"), stop=SL_long)if (short_condition) and (count_open_shorts <= max_sequel_trades) and (trade_short == true) strategy.entry("Short" + tostring(count_open_shorts, "#"), strategy.short) strategy.exit("SL Short" + tostring(count_open_shorts, "#"), from_entry="Short" + tostring(count_open_shorts, "#"), stop=SL_short) //------------------------------ submit exit conditionsif (trailing_SL_long_signal) strategy.close("Long" + tostring(count_open_longs, "#")) strategy.close("Long" + tostring(count_open_longs-1, "#")) strategy.close("Long" + tostring(count_open_longs-2, "#")) strategy.close("Long" + tostring(count_open_longs-4, "#")) strategy.close("Long" + tostring(count_open_longs-5, "#")) strategy.close("Long" + tostring(count_open_longs-6, "#")) strategy.close("Long" + tostring(count_open_longs-7, "#")) strategy.close("Long" + tostring(count_open_longs-8, "#")) strategy.close("Long" + tostring(count_open_longs-9, "#")) if (trailing_SL_short_signal) strategy.close("Short" + tostring(count_open_shorts, "#")) strategy.close("Short" + tostring(count_open_shorts-1, "#")) strategy.close("Short" + tostring(count_open_shorts-2, "#")) strategy.close("Short" + tostring(count_open_shorts-3, "#")) strategy.close("Short" + tostring(count_open_shorts-4, "#")) strategy.close("Short" + tostring(count_open_shorts-5, "#")) strategy.close("Short" + tostring(count_open_shorts-6, "#")) strategy.close("Short" + tostring(count_open_shorts-7, "#")) strategy.close("Short" + tostring(count_open_shorts-8, "#")) strategy.close("Short" + tostring(count_open_shorts-9, "#"))