Pine Script v4 · Strategy
BTC Good Signal
A Pine Script v4 strategy built on EMA (series, length), Crossover (leadLine1, leadLine2) and Crossunder (leadLine1, leadLine2). It has 4 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 100% of equity and pays 0.1% commission. 19 settings; defaults include What trades should be taken : LONG, First Trend Line : TEMA and First Trend Line : LSMA.
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 BTC Good Signal repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did BTC Good Signal do on BTCUSDT 1D with default settings?
- −32.54%
- From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can BTC Good Signal be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does BTC Good Signal use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does BTC Good Signal run in Zeal Terminal?
- Yes
- It compiles in 22 ms and runs 1,000 bars in 85 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- SMA
- 1st Long Take Profit
- 2nd Long Take Profit
- Long Stop Loss
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −32.54%
- −$1,626.86
- Buy and hold
- +102.5%
- same period
- Closed trades
- 6
- 0 won · 6 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- 0.00
- gross profit ÷ gross loss
- Max drawdown
- 38.92%
- −$1,946.07
One run with the author's default settings, $5,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 stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
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.
-
Note
Uses an argument v6 removed
when = on line 87, 90. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 68
iff() on line 68, 68. v5 writes it as the ternary c ? a : b.
-
Note
Uses transp =, which v5 removed line 44
transp = on line 44, 45, 46. 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 max → math.max, abs → math.abs, ema → ta.ema, linreg → ta.linreg, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder, min → math.min, highest → ta.highest.
- 2 strategy calls use the when = argument (line 87, 90). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 8: max → math.max
- Line 8: max → math.max
- Line 8: abs → math.abs
- Line 8: abs → math.abs
- Line 13: ema → ta.ema
20 more edits
- Line 14: ema → ta.ema
- Line 15: ema → ta.ema
- Line 29: linreg → ta.linreg
- Line 33: ema → ta.ema
- Line 35: sma → ta.sma
- Line 37: linreg → ta.linreg
- Line 41: ema → ta.ema
- Line 43: sma → ta.sma
- Line 44: transp = 50 → color.new(#53b987, 50)
- Line 45: transp = 50 → color.new(#eb4d5c, 50)
- Line 46: transp = 60 → color.new(leadLine1 > leadLine2 ? #53b987 : #eb4d5c, 60)
- Line 48: crossover → ta.crossover
- Line 49: crossunder → ta.crossunder
- Line 65: input(type = input.source) → input.source()
- Line 68: iff(c, a, b) → (c ? a : b)
- Line 68: min → math.min
- Line 68: iff(c, a, b) → (c ? a : b)
- Line 69: highest → ta.highest
- Line 71: crossover → ta.crossover
- Line 72: crossover → ta.crossover
⋯// © Wunderbit Trading-//@version=4+//@version=5strategy("Automated Bitcoin (BTC) Investment Strategy", overlay=true, initial_capital=5000,pyramiding = 0, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent,commission_value=0.1)⋯ atr = 0.- Tr = max(high - low, max(abs(high - close[1]), abs(low - close[1])))+ Tr = math.max(high - low, math.max(math.abs(high - close[1]), math.abs(low - close[1]))) atr := nz(atr[1] + (Tr - atr[1])/p,Tr)⋯ if (length > 0)- ema1 = ema(series, length)+ ema1 = ta.ema(series, length)- ema2 = ema(ema1, length)+ ema2 = ta.ema(ema1, length)- ema3 = ema(ema2, length)+ ema3 = ta.ema(ema2, length) (3 * ema1) - (3 * ema2) + ema3⋯leadLine1 = if trend_type1=="LSMA"- linreg(close, trend_type1_length, 0)+ ta.linreg(close, trend_type1_length, 0)else if trend_type1=="TEMA"⋯else if trend_type1 =="EMA"- ema(close,trend_type1_length)+ ta.ema(close,trend_type1_length)else- sma(close,trend_type1_length)+ ta.sma(close,trend_type1_length)leadLine2 = if trend_type2=="LSMA"- linreg(close, trend_type2_length, 0)+ ta.linreg(close, trend_type2_length, 0)else if trend_type2=="TEMA"⋯else if trend_type2 =="EMA"- ema(close,trend_type2_length)+ ta.ema(close,trend_type2_length)else- sma(close,trend_type2_length)+ ta.sma(close,trend_type2_length)-p3 = plot(leadLine1, color= #53b987, title="EMA", transp = 50, linewidth = 1)+p3 = plot(leadLine1, color= color.new(#53b987, 50), title="EMA", linewidth = 1)-p4 = plot(leadLine2, color= #eb4d5c, title="SMA", transp = 50, linewidth = 1)+p4 = plot(leadLine2, color= color.new(#eb4d5c, 50), title="SMA", linewidth = 1)-fill(p3, p4, transp = 60, color = leadLine1 > leadLine2 ? #53b987 : #eb4d5c)+fill(p3, p4, color = color.new(leadLine1 > leadLine2 ? #53b987 : #eb4d5c, 60))//Upward Trend-UT=crossover(leadLine1,leadLine2)+UT=ta.crossover(leadLine1,leadLine2)-DT=crossunder(leadLine1,leadLine2)+DT=ta.crossunder(leadLine1,leadLine2)// TP/ SL/ FOR LONG⋯//LONG STRATEGY CONDITION-SC = input(close, "Source", input.source)+SC = input.source(close, "Source")SL1 = multiplier * Atr(ATR_period) // Stop LossTrail1 = 0.0-Trail1 := iff(SC < nz(Trail1[1], 0) and SC[1] < nz(Trail1[1], 0), min(nz(Trail1[1], 0), SC + SL1), iff(SC > nz(Trail1[1], 0), SC - SL1, SC + SL1))+Trail1 := (SC < nz(Trail1[1], 0) and SC[1] < nz(Trail1[1], 0) ? math.min(nz(Trail1[1], 0), SC + SL1) : (SC > nz(Trail1[1], 0) ? SC - SL1 : SC + SL1))-Trail1_high=highest(Trail1,50)+Trail1_high=ta.highest(Trail1,50)// iff(SC > nz(Trail1[1], 0) and SC[1] > nz(Trail1[1], 0), max(nz(Trail1[1], 0), SC - SL1),-entry_long=crossover(leadLine1,leadLine2) and Trail1_high < close+entry_long=ta.crossover(leadLine1,leadLine2) and Trail1_high < close-exit_long = close < Trail1_high or crossover(leadLine2,leadLine1) or close < long_sl_input_level+exit_long = close < Trail1_high or ta.crossover(leadLine2,leadLine1) or close < long_sl_input_level///// BACKTEST PERIOD ///////⋯Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 19: input() → input.string()
- Line 24: input() → input.string()
- Line 25: input() → input.string()
- Line 26: input() → input.int()
- Line 27: input() → input.int()
- Line 52: input() → input.int()
14 more edits
- Line 53: input() → input.int()
- Line 54: input() → input.int()
- Line 55: input() → input.int()
- Line 58: input() → input.int()
- Line 61: input() → input.float()
- Line 62: input() → input.int()
- Line 74: input() → input.int()
- Line 75: input() → input.int()
- Line 76: input() → input.int()
- Line 78: input() → input.int()
- Line 79: input() → input.int()
- Line 80: input() → input.int()
- Line 87: when = entry_long → if block
- Line 90: when = exit_long → if block
⋯ na-tradeType = input("LONG", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"])+tradeType = input.string("LONG", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"])///////////////////////////////////////////////////⋯/// TREND-trend_type1 = input("TEMA", title ="First Trend Line : ", options=["LSMA", "TEMA","EMA","SMA"])+trend_type1 = input.string("TEMA", title ="First Trend Line : ", options=["LSMA", "TEMA","EMA","SMA"])-trend_type2 = input("LSMA", title ="First Trend Line : ", options=["LSMA", "TEMA","EMA","SMA"])+trend_type2 = input.string("LSMA", title ="First Trend Line : ", options=["LSMA", "TEMA","EMA","SMA"])-trend_type1_length=input(25, "Length of the First Trend Line")+trend_type1_length=input.int(25, "Length of the First Trend Line")-trend_type2_length=input(100, "Length of the Second Trend Line")+trend_type2_length=input.int(100, "Length of the Second Trend Line")leadLine1 = if trend_type1=="LSMA"⋯// TAKE PROFIT AND STOP LOSS-long_tp1_inp = input(15, title='Long Take Profit 1 %', step=0.1)/100+long_tp1_inp = input.int(15, title='Long Take Profit 1 %', step=0.1)/100-long_tp1_qty = input(20, title="Long Take Profit 1 Qty", step=1)+long_tp1_qty = input.int(20, title="Long Take Profit 1 Qty", step=1)-long_tp2_inp = input(30, title='Long Take Profit 2%', step=0.1)/100+long_tp2_inp = input.int(30, title='Long Take Profit 2%', step=0.1)/100-long_tp2_qty = input(20, title="Long Take Profit 2 Qty", step=1)+long_tp2_qty = input.int(20, title="Long Take Profit 2 Qty", step=1)long_take_level_1 = strategy.position_avg_price * (1 + long_tp1_inp)long_take_level_2 = strategy.position_avg_price * (1 + long_tp2_inp)-long_sl_input = input(5, title='stop loss in %', step=0.1)/100+long_sl_input = input.int(5, title='stop loss in %', step=0.1)/100long_sl_input_level = strategy.position_avg_price * (1 - long_sl_input)// Stop Loss-multiplier = input(3.5, "SL Mutiplier", minval=1, step=0.1)+multiplier = input.float(3.5, "SL Mutiplier", minval=1, step=0.1)-ATR_period=input(8,"ATR period", minval=1, step=1)+ATR_period=input.int(8,"ATR period", minval=1, step=1)// Strategy⋯///// BACKTEST PERIOD ///////-testStartYear = input(2016, "Backtest Start Year")+testStartYear = input.int(2016, "Backtest Start Year")-testStartMonth = input(1, "Backtest Start Month")+testStartMonth = input.int(1, "Backtest Start Month")-testStartDay = input(1, "Backtest Start Day")+testStartDay = input.int(1, "Backtest Start Day")testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)-testStopYear = input(9999, "Backtest Stop Year")+testStopYear = input.int(9999, "Backtest Stop Year")-testStopMonth = input(12, "Backtest Stop Month")+testStopMonth = input.int(12, "Backtest Stop Month")-testStopDay = input(31, "Backtest Stop Day")+testStopDay = input.int(31, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)⋯ if strategy.position_size == 0 or strategy.position_size > 0- strategy.entry("long", strategy.long, comment="BUY", when=entry_long)+ if entry_long+ strategy.entry("long", strategy.long, comment="BUY") strategy.exit("TP1", "long", qty_percent=long_tp1_qty, limit=long_take_level_1) strategy.exit("TP2", "long", qty_percent=long_tp2_qty, limit=long_take_level_2)- strategy.close("long", when=exit_long, comment="SL" )+ if exit_long+ strategy.close("long", comment="SL" )// LONG POSITION⋯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: 6 before, 6 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.
⋯// © Wunderbit Trading-//@version=5+//@version=6strategy("Automated Bitcoin (BTC) Investment Strategy", overlay=true, initial_capital=5000,pyramiding = 0, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=100, 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 |
|---|---|---|---|
| What trades should be taken : | LONG | string · options ["LONG", "SHORT", "BOTH", "NONE"] | line 85 |
| First Trend Line : | TEMA | string · options ["LSMA", "TEMA","EMA","SMA"] | leadLine1 |
| First Trend Line : | LSMA | string · options ["LSMA", "TEMA","EMA","SMA"] | leadLine2 |
| Length of the First Trend Line | 25 | int | leadLine1 |
| Length of the Second Trend Line | 100 | int | leadLine2 |
| Long Take Profit 1 % | 15 | int · step 0.1 | long_take_level_1 |
| Long Take Profit 1 Qty | 20 | int · step 1 | exit TP1 |
| Long Take Profit 2% | 30 | int · step 0.1 | long_take_level_2 |
| Long Take Profit 2 Qty | 20 | int · step 1 | exit TP2 |
| stop loss in % | 5 | int · step 0.1 | long_sl_input_level |
| SL Mutiplier | 3.5 | float · min 1 · step 0.1 | SL1 |
| ATR period | 8 | int · min 1 · step 1 | SL1 |
| Source | close | source | Trail1 |
| Backtest Start Year | 2016 | int | testPeriodStart |
| Backtest Start Month | 1 | int | testPeriodStart |
| Backtest Start Day | 1 | int | testPeriodStart |
| Backtest Stop Year | 9999 | int | testPeriodStop |
| Backtest Stop Month | 12 | int | testPeriodStop |
| Backtest Stop Day | 31 | int | testPeriodStop |
What it calculates
- EMA (
ema,ta.emain v5)series, lengthema1 · line 13 - EMA (
ema,ta.emain v5)ema1, lengthema2 · line 14 - EMA (
ema,ta.emain v5)ema2, lengthema3 · line 15 - Crossover (
crossover,ta.crossoverin v5)leadLine1, leadLine2UT · line 48 - Crossunder (
crossunder,ta.crossunderin v5)leadLine1, leadLine2DT · line 49 - Highest (
highest,ta.highestin v5)Trail1, 50Trail1_high · line 69
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 | entry_longcrossover(leadLine1,leadLine2) and Trail1_high < close | On | 87 |
| Exit TP1 limit | strategy.position_size == 0 or strategy.position_size > 0 | On | 88 |
| Exit TP2 limit | strategy.position_size == 0 or strategy.position_size > 0 | On | 89 |
| Close long | exit_longclose < Trail1_high or crossover(leadLine2,leadLine1) or close < long_sl_input_level | On | 90 |
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 | −32.5% | +102.5% | 6 | 0% | 0.00 | 38.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +25.1% | +5.5% | 7 | 57% | 6.22 | 3.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +20.9% | +9.8% | 4 | 75% | 3.64 | 9.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +6.7% | +8.4% | 11 | 36% | 1.32 | 10.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −28.1% | +16.7% | 8 | 25% | 0.15 | 31.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +62.6% | +21.5% | 9 | 78% | 20.26 | 4.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +21.0% | +148.3% | 13 | 69% | 1.78 | 19.8% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +16.3% | +17.1% | 10 | 60% | 3.69 | 4.0% | 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 | 2 | 0% | −$465.27 |
| Sideways market | 4 | 0% | −$1,161.59 |
| 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?
32.5%
The 95th percentile of the worst drawdown when the same 6 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 32.5% to 32.5%; the tick is what actually happened, 32.5%. Order luck alone moves it this much.
All 6 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 May 2024 67,969.70 | 21 Jun 2024 64,870.00 | 28 | −$237.55 |
| long | 21 Jul 2024 67,140.00 | 3 Aug 2024 61,498.30 | 13 | −$408.89 |
| long | 24 Aug 2024 64,037.20 | 28 Aug 2024 59,415.00 | 4 | −$322.31 |
| long | 15 Jul 2025 119,841.00 | 2 Aug 2025 113,298.00 | 18 | −$227.72 |
| long | 14 Aug 2025 123,306.00 | 16 Aug 2025 117,342.00 | 2 | −$191.21 |
| long | 3 Oct 2025 120,529.00 | 11 Oct 2025 112,774.00 | 8 | −$239.17 |
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 |
|---|---|---|---|---|---|
| BTC Good Signal this page | — | v4 strategy | −32.5% | 6 | 38.9% |
| AMRS_LongOnly_PartTimer by ThePartTimeNSE | ema highest | v4 strategy | 0.0% | 11 | 0.0% |
| Automated Bitcoin (BTC) Investment Strategy from Wunderbit by Wunderbit | ema highest | v4 strategy | −32.5% | 6 | 38.9% |
| CC Trend strategy 2- Downtrend Short by CheatCode1 | ema highest | v5 strategy | No trades on this market | ||
| Slight Swing Momentum Strategy. by fzj20020403 | highest ema | v5 strategy | +3.1% | 7 | 0.6% |
| Momentum Strategy by PrattyCharts | ema highest | v4 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 22 ms | With a workaround 1,000 bars in 85 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/// © Wunderbit Trading//@version=4strategy("Automated Bitcoin (BTC) Investment Strategy", overlay=true, initial_capital=5000,pyramiding = 0, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent,commission_value=0.1)//////////// FunctionsAtr(p) => atr = 0. Tr = max(high - low, max(abs(high - close[1]), abs(low - close[1]))) atr := nz(atr[1] + (Tr - atr[1])/p,Tr)//TEMATEMA(series, length) => if (length > 0) ema1 = ema(series, length) ema2 = ema(ema1, length) ema3 = ema(ema2, length) (3 * ema1) - (3 * ema2) + ema3 else natradeType = input("LONG", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"])////////////////////////////////////////////////////// INDICATORSsource=close/// TRENDtrend_type1 = input("TEMA", title ="First Trend Line : ", options=["LSMA", "TEMA","EMA","SMA"])trend_type2 = input("LSMA", title ="First Trend Line : ", options=["LSMA", "TEMA","EMA","SMA"])trend_type1_length=input(25, "Length of the First Trend Line")trend_type2_length=input(100, "Length of the Second Trend Line")leadLine1 = if trend_type1=="LSMA" linreg(close, trend_type1_length, 0)else if trend_type1=="TEMA" TEMA(close,trend_type1_length)else if trend_type1 =="EMA" ema(close,trend_type1_length)else sma(close,trend_type1_length)leadLine2 = if trend_type2=="LSMA" linreg(close, trend_type2_length, 0)else if trend_type2=="TEMA" TEMA(close,trend_type2_length)else if trend_type2 =="EMA" ema(close,trend_type2_length)else sma(close,trend_type2_length)p3 = plot(leadLine1, color= #53b987, title="EMA", transp = 50, linewidth = 1)p4 = plot(leadLine2, color= #eb4d5c, title="SMA", transp = 50, linewidth = 1)fill(p3, p4, transp = 60, color = leadLine1 > leadLine2 ? #53b987 : #eb4d5c)//Upward TrendUT=crossover(leadLine1,leadLine2)DT=crossunder(leadLine1,leadLine2)// TP/ SL/ FOR LONG// TAKE PROFIT AND STOP LOSSlong_tp1_inp = input(15, title='Long Take Profit 1 %', step=0.1)/100long_tp1_qty = input(20, title="Long Take Profit 1 Qty", step=1)long_tp2_inp = input(30, title='Long Take Profit 2%', step=0.1)/100long_tp2_qty = input(20, title="Long Take Profit 2 Qty", step=1)long_take_level_1 = strategy.position_avg_price * (1 + long_tp1_inp)long_take_level_2 = strategy.position_avg_price * (1 + long_tp2_inp)long_sl_input = input(5, title='stop loss in %', step=0.1)/100long_sl_input_level = strategy.position_avg_price * (1 - long_sl_input)// Stop Lossmultiplier = input(3.5, "SL Mutiplier", minval=1, step=0.1)ATR_period=input(8,"ATR period", minval=1, step=1)// Strategy//LONG STRATEGY CONDITIONSC = input(close, "Source", input.source)SL1 = multiplier * Atr(ATR_period) // Stop LossTrail1 = 0.0Trail1 := iff(SC < nz(Trail1[1], 0) and SC[1] < nz(Trail1[1], 0), min(nz(Trail1[1], 0), SC + SL1), iff(SC > nz(Trail1[1], 0), SC - SL1, SC + SL1))Trail1_high=highest(Trail1,50)// iff(SC > nz(Trail1[1], 0) and SC[1] > nz(Trail1[1], 0), max(nz(Trail1[1], 0), SC - SL1),entry_long=crossover(leadLine1,leadLine2) and Trail1_high < closeexit_long = close < Trail1_high or crossover(leadLine2,leadLine1) or close < long_sl_input_level///// BACKTEST PERIOD ///////testStartYear = input(2016, "Backtest Start Year")testStartMonth = input(1, "Backtest Start Month")testStartDay = input(1, "Backtest Start Day")testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)testStopYear = input(9999, "Backtest Stop Year")testStopMonth = input(12, "Backtest Stop Month")testStopDay = input(31, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)testPeriod() => time >= testPeriodStart and time <= testPeriodStop ? true : falseif testPeriod() if tradeType=="LONG" or tradeType=="BOTH" if strategy.position_size == 0 or strategy.position_size > 0 strategy.entry("long", strategy.long, comment="BUY", when=entry_long) strategy.exit("TP1", "long", qty_percent=long_tp1_qty, limit=long_take_level_1) strategy.exit("TP2", "long", qty_percent=long_tp2_qty, limit=long_take_level_2) strategy.close("long", when=exit_long, comment="SL" )// LONG POSITIONplot(strategy.position_size > 0 ? long_take_level_1 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="1st Long Take Profit")plot(strategy.position_size > 0 ? long_take_level_2 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="2nd Long Take Profit")plot(strategy.position_size > 0 ? Trail1_high : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")