Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Automated Bitcoin (BTC) Investment Strategy from Wunderbit

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 Automated Bitcoin (BTC) Investment Strategy from Wunderbit repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Automated Bitcoin (BTC) Investment Strategy from Wunderbit 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 Automated Bitcoin (BTC) Investment Strategy from Wunderbit 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 Automated Bitcoin (BTC) Investment Strategy from Wunderbit use a stop loss?
No
Its exits set a profit target but no stop.
Does Automated Bitcoin (BTC) Investment Strategy from Wunderbit run in Zeal Terminal?
Yes
It compiles in 34 ms and runs 1,000 bars in 90 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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (19)
50,000100,000150,000AprJulOct2025AprJulOct2026AprJulOct$3,373$10,126Equity from $5,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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.
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

Verified

Same 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 ///////⋯

Clean v5

VerifiedDownload the v5 script

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="b8f60da7_ENTER-LONG_BINANCE_BTC/USDT_b8f60da7-BTC-Investment_4H", when=entry_long)+            if entry_long+                strategy.entry("long", strategy.long, comment="b8f60da7_ENTER-LONG_BINANCE_BTC/USDT_b8f60da7-BTC-Investment_4H")            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="b8f60da7_EXIT-LONG_BINANCE_BTC/USDT_b8f60da7-BTC-Investment_4H" )+            if exit_long+                strategy.close("long", comment="b8f60da7_EXIT-LONG_BINANCE_BTC/USDT_b8f60da7-BTC-Investment_4H" )// 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.

SettingDefaultType and rangeFeeds
What trades should be taken : LONGstring · options ["LONG", "SHORT", "BOTH", "NONE"]line 85
First Trend Line : TEMAstring · options ["LSMA", "TEMA","EMA","SMA"]leadLine1
First Trend Line : LSMAstring · options ["LSMA", "TEMA","EMA","SMA"]leadLine2
Length of the First Trend Line25intleadLine1
Length of the Second Trend Line100intleadLine2
Long Take Profit 1 %15int · step 0.1long_take_level_1
Long Take Profit 1 Qty20int · step 1exit TP1
Long Take Profit 2%30int · step 0.1long_take_level_2
Long Take Profit 2 Qty20int · step 1exit TP2
stop loss in %5int · step 0.1long_sl_input_level
SL Mutiplier3.5float · min 1 · step 0.1SL1
ATR period8int · min 1 · step 1SL1
SourceclosesourceTrail1
Backtest Start Year2016inttestPeriodStart
Backtest Start Month1inttestPeriodStart
Backtest Start Day1inttestPeriodStart
Backtest Stop Year9999inttestPeriodStop
Backtest Stop Month12inttestPeriodStop
Backtest Stop Day31inttestPeriodStop

What it calculates

  • EMA (ema, ta.ema in v5)series, lengthema1 · line 13
  • EMA (ema, ta.ema in v5)ema1, lengthema2 · line 14
  • EMA (ema, ta.ema in v5)ema2, lengthema3 · line 15
  • Crossover (crossover, ta.crossover in v5)leadLine1, leadLine2UT · line 48
  • Crossunder (crossunder, ta.crossunder in v5)leadLine1, leadLine2DT · line 49
  • Highest (highest, ta.highest in 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.

closecloseprice datalowlowprice datahighhighprice datalong_tp1_inpLong Take Profit 1 %setting · 15long_tp2_inpLong Take Profit 2%setting · 30long_sl_inputstop loss in %setting · 5multiplierSL Mutipliersetting · 3.5ATR_periodATR periodsetting · 8testStartYearBacktest Start Yearsetting · 2016testStartMonthBacktest Start Monthsetting · 1testStartDayBacktest Start Daysetting · 1testStopYearBacktest Stop Yearsetting · 9999testStopMonthBacktest Stop Monthsetting · 12testStopDayBacktest Stop Daysetting · 31trend_type1First Trend Line : setting · TEMAtrend_type1_lengthLength of the First Tre…setting · 25trend_type2First Trend Line : setting · LSMAtrend_type2_lengthLength of the Second Tr…setting · 100ema1EMA→ ema1ema2EMA→ ema2ema3EMA→ ema3UTCrossover→ UTDTCrossunder→ DTTrail1_highHighest→ Trail1_highatratrvalueTrTrvaluesourcesourcevaluelong_take_level_1long_take_level_1valuelong_take_level_2long_take_level_2valuelong_sl_input_levellong_sl_input_levelvalueSL1SL1valuetestPeriodStarttestPeriodStartvaluetestPeriodStoptestPeriodStopvalueentry_longentry_longconditionexit_longexit_longconditionleadLine1leadLine1conditionleadLine2leadLine2conditionTrail1Trail1conditionentry:longOpen longstrategy.entryexit:TP1exit TP1strategy.exitexit:TP2exit TP2strategy.exitclose:longClose longstrategy.closeplot:44EMAplotplot:45SMAplotfill:46Fillfillplot:921st Long Take Profitplotplot:932nd Long Take Profitplotplot:94Long Stop Lossplot

Order rules

OrderFires whenBy defaultLine
Open long longentry_longcrossover(leadLine1,leadLine2) and Trail1_high < closeOn87
Exit TP1 limitstrategy.position_size == 0 or strategy.position_size > 0On88
Exit TP2 limitstrategy.position_size == 0 or strategy.position_size > 0On89
Close longexit_longclose < Trail1_high or crossover(leadLine2,leadLine1) or close < long_sl_input_levelOn90

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−32.5%+102.5%60%0.0038.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+25.1%+5.5%757%6.223.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+20.9%+9.8%475%3.649.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+6.7%+8.4%1136%1.3210.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−28.1%+16.7%825%0.1531.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+62.6%+21.5%978%20.264.3%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+21.0%+148.3%1369%1.7819.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+16.3%+17.1%1060%3.694.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 barsTradesWonP&L
Rising market20%−$465.27
Sideways market40%−$1,161.59
Falling market0—$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.

0%37%
All 6 trades
SideEntryExitBarsP&L
long24 May 2024 67,969.7021 Jun 2024 64,870.0028−$237.55
long21 Jul 2024 67,140.003 Aug 2024 61,498.3013−$408.89
long24 Aug 2024 64,037.2028 Aug 2024 59,415.004−$322.31
long15 Jul 2025 119,841.002 Aug 2025 113,298.0018−$227.72
long14 Aug 2025 123,306.0016 Aug 2025 117,342.002−$191.21
long3 Oct 2025 120,529.0011 Oct 2025 112,774.008−$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.

ScriptSharesTypeNetTradesMax drawdown
Automated Bitcoin (BTC) Investment Strategy from Wunderbit this page—v4 strategy−32.5%638.9%
AMRS_LongOnly_PartTimer by ThePartTimeNSEema highestv4 strategy0.0%110.0%
BTC Good Signal by Majaztradesema highestv4 strategy−32.5%638.9%
CC Trend strategy 2- Downtrend Short by CheatCode1ema highestv5 strategyNo trades on this market
Slight Swing Momentum Strategy. by fzj20020403highest emav5 strategy+3.1%70.6%
Momentum Strategy by PrattyChartsema highestv4 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 34 msWith a workaround 1,000 bars in 90 msNot measured
PineTSNo 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="b8f60da7_ENTER-LONG_BINANCE_BTC/USDT_b8f60da7-BTC-Investment_4H", 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="b8f60da7_EXIT-LONG_BINANCE_BTC/USDT_b8f60da7-BTC-Investment_4H" )// 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")