Pine Script v5 · Strategy
Traling.SL.Target
A Pine Script v5 strategy built on EMA (close, 20). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 17 settings; defaults include Fast len 20, Slow len 50 and Inital profit % 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 Traling.SL.Target repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did Traling.SL.Target do on BTCUSDT 1D with default settings?
- −0.14%
- From 26 Jan 2024 to 21 Oct 2026, over 19 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Traling.SL.Target 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: 19 before, 25 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Traling.SL.Target use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Traling.SL.Target run in Zeal Terminal?
- Yes
- It compiles in 229 ms and runs 1,000 bars in 207 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.14%
- −$1,412.64
- Buy and hold
- +102.5%
- same period
- Closed trades
- 19
- 8 won · 11 lost
- Profitable
- 42.1%
- of closed trades
- Profit factor
- 0.93
- gross profit ÷ gross loss
- Max drawdown
- 1.50%
- −$15,028.90
One run with the author's default settings, $1,000,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
3 settings do nothing
“━━━━━━━ ↓ Pivot parameters for trade ↓ ━━━━━━━”, “━━━━━━━ ↓ % Based Target and SL ↓ ━━━━━━━”, “━━━━━━━ ↓ Fix point Based Target and SL ↓ ━━━━━━━” are declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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 an argument v6 removed
when = on line 174, 175, 176, 177. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| ━━━━━━━ ↓ Pivot parameters for trade ↓ ━━━━━━━ | false | bool | unused |
| Fast len | 20 | int | fast_ema |
| Slow len | 50 | int | slow_ema |
| BG color for ongoing trade SL/Target label | color.white | color | line 194 line 196 |
| Method to be used for SL/Target trailing | % Based Target and SL | string · options ['% Based Target and SL','Fix point Based Target and SL'] | percent_based |
| ━━━━━━━ ↓ % Based Target and SL ↓ ━━━━━━━ | true | bool | unused |
| Inital profit % | 1 | float | initial_long_percent_target initial_short_percent_target |
| Inital SL % | 1 | float | initial_long_percent_sl initial_short_percent_sl |
| Initiate trailing %Initiate trailing of target and SL after change in price in % after taking trade | 0.5 | float | long_entry_price short_entry_price long_trailing_point short_trailing_point |
| Trail profit by % | 0.3 | float | long_target short_target |
| Trail SL by % | 0.3 | float | long_sl short_sl |
| ━━━━━━━ ↓ Fix point Based Target and SL ↓ ━━━━━━━ | false | bool | unused |
| Inital profit target points | 100 | float | initial_long_point_target initial_short_point_target |
| Inital SL points | 50 | float | initial_long_point_sl initial_short_point_sl |
| Initiate trailing pointsInitiate trailing of target and SL after change in price in points after taking trade | 60 | float | long_entry_price short_entry_price long_trailing_point short_trailing_point |
| Trail profit by points | 25 | float | long_target short_target |
| Trail SL by % | 30 | float | long_sl short_sl |
What it calculates
- EMAclose, Fast len (20)
fast_ema · line 65 - EMAclose, Slow len (50)
slow_ema · line 66
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 | (go_long) | On | 125 |
| Open Short short | (go_short) | On | 140 |
| Close Long | close <= long_sl | On | 174 |
| Close Short | close >= short_sl | On | 175 |
| Close Long | close >= long_target | On | 176 |
| Close Short | close <= short_target | On | 177 |
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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | −0.1% | +102.5% | 19 | 42% | 0.93 | 1.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.6% | +5.5% | 12 | 42% | 2.41 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 16 | 50% | 1.30 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 14 | 29% | 0.63 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 23 | 30% | 0.47 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 12 | 75% | 5.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 11 | 45% | 0.90 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 22 | 36% | 1.18 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Fast len 14, Slow len 30) made +1.8% before 26 Dec 2025 and +0.0% after it, worse than the defaults' +0.7% after. Tuning on the past did not carry forward. 66% of the 64 combinations made money in-sample and 88% out-of-sample.
| Slow len ↓ · Fast len → | 10 | 12 | 14 | 17 | 20 | 24 | 28 | 34 |
|---|---|---|---|---|---|---|---|---|
| 25 | +2% | +1% | +0% | +2% | +1% | +0% | +1% | +1% |
| 30 | +1% | +1% | +2% | +1% | +0% | −0% | −0% | +0% |
| 35 | +1% | +1% | +2% | +0% | +1% | −1% | +0% | −0% |
| 43 | +1% | +1% | +1% | +1% | −0% | −0% | +0% | −0% |
| 50 | +0% | +1% | +1% | +1% | −1% | −1% | −1% | +0% |
| 60 | +0% | −1% | −0% | +0% | +0% | +0% | +0% | −0% |
| 70 | +1% | +1% | −0% | −1% | +0% | −1% | −1% | +1% |
| 85 | +1% | +1% | +0% | −1% | −1% | −0% | −0% | −1% |
| Slow len ↓ · Fast len → | 10 | 12 | 14 | 17 | 20 | 24 | 28 | 34 |
|---|---|---|---|---|---|---|---|---|
| 25 | +1% | +0% | +0% | −0% | −0% | +0% | −0% | −1% |
| 30 | −0% | +0% | +0% | +0% | +0% | +0% | +1% | −1% |
| 35 | +1% | −0% | +1% | +0% | +1% | +1% | +1% | +1% |
| 43 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +1% |
| 50 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +0% |
| 60 | +1% | +1% | +1% | +1% | +1% | +0% | +0% | +0% |
| 70 | +1% | +1% | +1% | +1% | +1% | +0% | +0% | +0% |
| 85 | +1% | +1% | −0% | +0% | +0% | +1% | +1% | +0% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 3 | 33% | −$640.97 |
| Sideways market | 14 | 43% | −$2,006.61 |
| Falling market | 2 | 50% | $1,234.94 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
1.5%
The 95th percentile of the worst drawdown when the same 19 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.6% to 1.5%; the tick is what actually happened, 1.3%. Order luck alone moves it this much.
All 19 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 3 May 2024 62,882.00 | 4 May 2024 63,892.00 | 1 | −$1,010.03 |
| short | 7 May 2024 62,312.10 | 8 May 2024 61,193.00 | 1 | $1,119.05 |
| long | 17 May 2024 67,024.00 | 19 May 2024 66,274.00 | 2 | −$749.99 |
| short | 23 Jun 2024 63,210.00 | 24 Jun 2024 60,293.30 | 1 | $2,916.71 |
| long | 22 Jul 2024 67,532.00 | 23 Jul 2024 65,936.00 | 1 | −$1,596.00 |
| short | 5 Aug 2024 54,018.80 | 6 Aug 2024 56,022.00 | 1 | −$2,003.20 |
| long | 22 Sep 2024 63,578.80 | 26 Sep 2024 65,174.00 | 4 | $1,595.23 |
| short | 17 Feb 2025 95,780.00 | 20 Feb 2025 98,305.00 | 3 | −$2,525.00 |
| long | 24 Apr 2025 93,980.50 | 1 May 2025 96,489.90 | 7 | $2,509.44 |
| short | 29 Aug 2025 108,377.00 | 2 Sep 2025 111,240.00 | 4 | −$2,862.61 |
| long | 15 Sep 2025 115,350.00 | 22 Sep 2025 112,651.00 | 7 | −$2,698.72 |
| short | 25 Sep 2025 108,994.00 | 28 Sep 2025 112,164.00 | 3 | −$3,169.46 |
| long | 1 Oct 2025 118,595.00 | 2 Oct 2025 120,529.00 | 1 | $1,934.36 |
| short | 17 Oct 2025 106,432.00 | 19 Oct 2025 108,643.00 | 2 | −$2,211.10 |
| long | 17 Jan 2026 95,147.80 | 18 Jan 2026 93,673.10 | 1 | −$1,474.63 |
| short | 20 Jan 2026 88,427.70 | 21 Jan 2026 89,454.70 | 1 | −$1,027.07 |
| long | 15 Apr 2026 74,810.00 | 17 Apr 2026 77,072.00 | 2 | $2,262.01 |
| short | 31 May 2026 73,674.40 | 1 Jun 2026 71,408.90 | 1 | $2,265.49 |
| long | 20 Aug 2026 73,025.10 | 21 Aug 2026 78,338.00 | 1 | $5,312.88 |
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 |
|---|---|---|---|---|---|
| Traling.SL.Target this page | — | v5 strategy | −0.1% | 19 | 1.5% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 4 strategy calls use the when = argument (line 174, 175, 176, 177). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 19 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 174: when = close <= long_sl → if block
- Line 175: when = close >= short_sl → if block
- Line 176: when = close >= long_target → if block
- Line 177: when = close <= short_target → if block
⋯ -strategy.close(id = 'Long', when = close <= long_sl, comment = 'SL')+if close <= long_sl+ strategy.close(id = 'Long', comment = 'SL')-strategy.close(id = 'Short', when = close >= short_sl, comment = 'SL')+if close >= short_sl+ strategy.close(id = 'Short', comment = 'SL')-strategy.close(id = 'Long', when = close >= long_target, comment = 'Target')+if close >= long_target+ strategy.close(id = 'Long', comment = 'Target')-strategy.close(id = 'Short', when = close <= short_target, comment = 'Target')+if close <= short_target+ strategy.close(id = 'Short', comment = 'Target')no_of_labels = 1⋯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: 19 before, 25 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.
⋯// © Sharad_Gaikwad-//@version=5+//@version=6strategy("Traling.SL.Target", overlay=true, process_orders_on_close = true, max_labels_count = 500)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 229 ms | With a workaround 1,000 bars in 207 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 125, 140) so the engine trades the way the script says.
“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.
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/// © Sharad_Gaikwad//@version=5strategy("Traling.SL.Target", overlay=true, process_orders_on_close = true, max_labels_count = 500)// << Parameters section {_1 = input.bool(title = "━━━━━━━ ↓ Pivot parameters for trade ↓ ━━━━━━━", defval = false)fast_len = input.int(title = 'Fast len', defval = 20)slow_len = input.int(title = 'Slow len', defval = 50)label_bg_color = input.color(title = 'BG color for ongoing trade SL/Target label', defval=color.white)sl_target_method = input.string(title = 'Method to be used for SL/Target trailing', defval='% Based Target and SL', options = ['% Based Target and SL','Fix point Based Target and SL'])_2 = input.bool(title = "━━━━━━━ ↓ % Based Target and SL ↓ ━━━━━━━", defval = true)initial_profit_percent = input.float(title = 'Inital profit %', defval = 1) / 100initial_sl_percent = input.float(title = 'Inital SL %', defval = 1) / 100initiate_trailing_percent = input.float(title = 'Initiate trailing %', defval = 0.5, tooltip = 'Initiate trailing of target and SL after change in price in % after taking trade') / 100trail_profit_percent = input.float(title = 'Trail profit by %', defval = 0.3) / 100trail_sl_percent = input.float(title = 'Trail SL by %', defval = 0.3) / 100_3 = input.bool(title = "━━━━━━━ ↓ Fix point Based Target and SL ↓ ━━━━━━━", defval = false)initial_profit_points = input.float(title = 'Inital profit target points', defval = 100)initial_sl_points = input.float(title = 'Inital SL points', defval = 50)initiate_trailing_points = input.float(title = 'Initiate trailing points', defval = 60, tooltip = 'Initiate trailing of target and SL after change in price in points after taking trade')trail_profit_points = input.float(title = 'Trail profit by points', defval = 25)trail_sl_points = input.float(title = 'Trail SL by %', defval = 30)// } Parameters section >>// } << Common function {tab = table.new(position=position.bottom_right, columns=7, rows=200,frame_color = color.yellow, frame_width = 1)msg(int row, int col, string msg_str, clr=color.blue) => table.cell(table_id=tab, column=col, row=row, text=msg_str, text_color=clr)getVal(val) => ret_val = na(val) ? 0 : valt(val) => str.tostring(val, "0.00")timeToString(int _t) => str.tostring(dayofmonth(_t), '00') + '/' + str.tostring(month(_t), '00') + '/' + str.tostring(year(_t), '0000') + ' ' + str.tostring(hour(_t), '00') + ':' + str.tostring(minute(_t), '00') + ':' + str.tostring(second(_t), '00') // } Common functions>>// Variable declarations {percent_based = sl_target_method == '% Based Target and SL' ? true : falsevar initial_long_entry_price = float(na)var initial_short_entry_price = float(na)var long_target = float(na)var long_sl = float(na)var short_target = float(na)var short_sl = float(na)var long_entry_price = float(na)var short_entry_price = float(na)var initial_long_percent_target = float(na)var initial_long_percent_sl = float(na)var initial_long_point_target = float(na)var initial_long_point_sl = float(na)var initial_short_percent_target = float(na)var initial_short_percent_sl = float(na)var initial_short_point_target = float(na)var initial_short_point_sl = float(na)var is_long = bool(na)var is_short = bool(na)var trail_long_iteration = int(na)var trail_short_iteration = int(na)// }// derive important variable values// Strategy logicfast_ema = ta.ema(close, fast_len)slow_ema = ta.ema(close, slow_len)plot(fast_ema, color = color.red)plot(slow_ema, color = color.green)go_long = ta.crossover(fast_ema, slow_ema) and strategy.position_size == 0go_short = ta.crossunder(fast_ema, slow_ema) and strategy.position_size == 0// barcolor(ph ? color.purple : na, offset = -lb)// barcolor(pl ? color.yellow : na, offset = -lb)// barcolor(ph ? color.white : na)// barcolor(pl ? color.blue : na)// //trailing logic for longlong_trailing_point = percent_based ? (close >= long_entry_price + (long_entry_price * initiate_trailing_percent)) : (close >= long_entry_price + initiate_trailing_points)short_trailing_point = percent_based ? (close <= short_entry_price - (short_entry_price * initiate_trailing_percent)) : (close >= short_entry_price - initiate_trailing_points)if(is_long and long_trailing_point) // initial_long_percent_target = initial_long_percent_target + (initial_long_percent_target * trail_profit_percent) // initial_long_percent_sl = initial_long_percent_sl - (initial_long_percent_sl * trail_sl_percent) // initial_long_point_target = initial_long_point_target + trail_profit_points // initial_long_point_sl = initial_long_point_sl - trail_sl_points trail_long_iteration := trail_long_iteration + 1 long_target := percent_based ? (long_target + (long_target * trail_profit_percent)) : (long_target + trail_profit_points) long_sl := percent_based ? (long_sl + (long_sl * trail_sl_percent)) : (long_sl + trail_sl_points) long_entry_price := percent_based ? (long_entry_price + (long_entry_price * initiate_trailing_percent)) : (long_entry_price + initiate_trailing_points)if(is_short and short_trailing_point) // initial_short_percent_target = initial_short_percent_target - (initial_short_percent_target * trail_profit_percent) // initial_short_percent_sl = initial_short_percent_sl + (initial_short_percent_sl * trail_sl_percent) // initial_short_point_target = initial_short_point_target - trail_profit_points // initial_short_point_sl = initial_short_point_sl + trail_sl_points trail_short_iteration := trail_short_iteration + 1 short_target := percent_based ? (short_target - (short_target * trail_profit_percent)) : (short_target - trail_profit_points) short_sl := percent_based ? (short_sl - (short_sl * trail_sl_percent)) : (short_sl - trail_sl_points) short_entry_price := percent_based ? (short_entry_price - (short_entry_price * initiate_trailing_percent)) : (short_entry_price - initiate_trailing_points) if(go_long) is_long := true is_short := false trail_long_iteration := 0 trail_short_iteration := 0 initial_long_entry_price := close long_entry_price := close initial_long_percent_target := close + (close * initial_profit_percent) initial_long_percent_sl := close - (close * initial_sl_percent) initial_long_point_target := close + initial_profit_points initial_long_point_sl := close - initial_sl_points long_target := percent_based ? initial_long_percent_target : initial_long_point_target long_sl := percent_based ? initial_long_percent_sl : initial_long_point_sl strategy.entry(id = 'Long', direction = strategy.long)if(go_short) is_long := false is_short := true trail_long_iteration := 0 trail_short_iteration := 0 initial_short_entry_price := close short_entry_price := close initial_short_percent_target := close - (close * initial_profit_percent) initial_short_percent_sl := close + (close * initial_sl_percent) initial_short_point_target := close - initial_profit_points initial_short_point_sl := close + initial_sl_points short_target := percent_based ? initial_short_percent_target : initial_short_point_target short_sl := percent_based ? initial_short_percent_sl : initial_short_point_sl strategy.entry(id = 'Short', direction = strategy.short)method = percent_based ? '% Based' : 'Fixed Points'long_tooltip = 'Long @ ' + timeToString(time) + '\n' + 'Method : ' + method + '\n' + 'Initial Trade Price: ' + t(initial_long_entry_price) + '\n' + 'Inital Target : ' + t(long_target) + '\n' + 'Inital SL : ' + t(long_sl) short_tooltip = 'Short @ ' + timeToString(time) + '\n' + 'Method : ' + method + '\n' + 'Initial Trade Price: ' + t(initial_short_entry_price) + '\n' + 'Inital Target : ' + t(short_target) + '\n' + 'Inital SL : ' + t(short_sl) label.new(go_long ? bar_index : na, go_long ? bar_index : na, style = label.style_diamond, yloc = yloc.belowbar, color = color.green, size=size.tiny, tooltip = long_tooltip) label.new(go_short ? bar_index : na, go_short ? bar_index : na, style = label.style_diamond, yloc = yloc.abovebar, color = color.red, size=size.tiny, tooltip = short_tooltip) trail_long_tooltip = 'Trail @ ' + timeToString(time) + '\n' + 'Iteration no : ' + t(trail_long_iteration) + '\n' + 'New Target : ' + t(long_target) + '\n' + 'New SL : ' + t(long_sl)trail_short_tooltip = 'Trail @ ' + timeToString(time) + '\n' + 'Iteration no : ' + t(trail_short_iteration) + '\n' + 'New Target : ' + t(short_target) + '\n' + 'New SL : ' + t(short_sl) label.new(is_long and long_trailing_point and strategy.position_size > 0 ? bar_index : na, is_long and long_trailing_point and strategy.position_size > 0 ? bar_index : na, text = str.tostring(trail_long_iteration), style = label.style_circle, textcolor = color.white, yloc = yloc.belowbar, color = color.green, size=size.tiny, tooltip = trail_long_tooltip) label.new(is_short and short_trailing_point and strategy.position_size < 0 ? bar_index : na, is_short and short_trailing_point and strategy.position_size < 0 ? bar_index : na, text = str.tostring(trail_short_iteration), style = label.style_circle, textcolor = color.white, yloc = yloc.abovebar, color = color.red, size=size.tiny, tooltip = trail_short_tooltip) strategy.close(id = 'Long', when = close <= long_sl, comment = 'SL')strategy.close(id = 'Short', when = close >= short_sl, comment = 'SL')strategy.close(id = 'Long', when = close >= long_target, comment = 'Target')strategy.close(id = 'Short', when = close <= short_target, comment = 'Target')no_of_labels = 1label_q(_array, _val) => array.push(_array, _val) _return = array.shift(_array)var target_label = float(na)var sl_label = float(na)if(strategy.position_size > 0) target_label := long_target sl_label := long_slelse if(strategy.position_size < 0) target_label := short_target sl_label := short_slelse target_label := float(na) sl_label := float(na)var label[] target_array = array.new_label(no_of_labels)label.delete(label_q(target_array, label.new(bar_index, target_label, "Target:"+t(target_label), style = label.style_label_down, color = label_bg_color, size=size.small, textcolor = color.green)))var label[] sl_array = array.new_label(no_of_labels)label.delete(label_q(sl_array, label.new(bar_index, sl_label, "SL:"+t(sl_label), style = label.style_label_up, color = label_bg_color, size=size.small, textcolor = color.red)))