Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Lagged Donchian Channel + EMA

A Pine Script v4 strategy built on EMA (close, 200), Highest (24) and Lowest (24). It has 8 order rules and no entry of its own. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 10 settings; defaults include Channel's periods 24, EMA's periods ? 200 and Ratio TP 3.

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 Lagged Donchian Channel + EMA repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Lagged Donchian Channel + EMA do on BTCUSDT 1D with default settings?
−12.31%
From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Lagged Donchian Channel + EMA be converted to Pine Script v5?
No
The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L42:C290: 'label.style_labeldown' is not available in Pine Script v5. It was added in a later version), so no v5 download is offered; the edits are shown below.
Does Lagged Donchian Channel + EMA use a stop loss?
Yes
strategy.exit sets a stop on line 91, 96.
Does Lagged Donchian Channel + EMA run in Zeal Terminal?
Yes
It compiles in 32 ms and runs 1,000 bars in 79 ms, in the browser.

BTCUSDT · 1D · default settings

  • EMA
  • Bear
  • Bull
  • 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 (10)
LONGSHORTSHORTSHORTSHORTSHORTLONGLONGSHORTSHORTSHORTSHORTSHORTSHORTSHORTLONGLONGLONGLONGLONGSHORTSHORT40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$87,689$202,527Equity from $100,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. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep. Zeal Terminal's engine currently reads an order side written as false, true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 90, 95) so the engine trades the way the script says. 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
−12.31%
−$12,310.80
Buy and hold
+102.5%
same period
Closed trades
4
0 won · 4 lost
Profitable
0.0%
of closed trades
Profit factor
0.00
gross profit ÷ gross loss
Max drawdown
12.31%
−$12,310.80

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.

  • Likely bug

    highest(3) ignores the settings line 35

    Line 35 hard-codes 3 where line 24 uses “Channel's periods”. Changing those settings moves one band but not this one.

    highest(3)highest(period)
  • Likely bug

    lowest(3) ignores the settings line 61

    Line 61 hard-codes 3 where line 25 uses “Channel's periods”. Changing those settings moves one band but not this one.

    lowest(3)lowest(period)
  • 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 92, 93, 98, 99. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 56

    transp = on line 56, 57, 82, 83. 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 ema → ta.ema, highest → ta.highest, lowest → ta.lowest, round → math.round, tostring → str.tostring.
  • 4 strategy calls use the when = argument (line 92, 93, 98, 99). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Differs

The v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L42:C290: 'label.style_labeldown' is not available in Pine Script v5. It was added in a later version.

  • Line 3: //@version=4 → //@version=5
  • Line 11: input(type = input.float) → input.float()
  • Line 14: input(type = input.bool) → input.bool()
  • Line 15: input(type = input.bool) → input.bool()
  • Line 16: input(type = input.bool) → input.bool()
  • Line 17: input(type = input.bool) → input.bool()
26 more edits
  • Line 18: input(type = input.bool) → input.bool()
  • Line 22: ema → ta.ema
  • Line 24: highest → ta.highest
  • Line 25: lowest → ta.lowest
  • Line 35: highest → ta.highest
  • Line 39: round → math.round
  • Line 40: round → math.round
  • Line 42: tostring → str.tostring
  • Line 42: tostring → str.tostring
  • Line 42: tostring → str.tostring
  • Line 42: tostring → str.tostring
  • Line 42: tostring → str.tostring
  • Line 56: transp = 70 → color.new(color.red, 70)
  • Line 57: transp = 70 → color.new(color.green, 70)
  • Line 61: lowest → ta.lowest
  • Line 65: round → math.round
  • Line 66: round → math.round
  • Line 68: tostring → str.tostring
  • Line 68: tostring → str.tostring
  • Line 68: tostring → str.tostring
  • Line 68: tostring → str.tostring
  • Line 68: tostring → str.tostring
  • Line 82: transp = 70 → color.new(color.red, 70)
  • Line 83: transp = 70 → color.new(color.green, 70)
  • Line 90: strategy.order(…, false) → strategy.order(…, strategy.short)
  • Line 95: strategy.order(…, true) → strategy.order(…, strategy.long)
⋯// © Mysteriown-//@version=4+//@version=5strategy("Lagged Donchian Channel + EMA", overlay = true)⋯Pema = input(200, title="EMA's periods ?")-ratio = input(3, title="Ratio TP", type=input.float)+ratio = input.float(3, title="Ratio TP")loss = input(20, title="Risk Loss ($)")lev = input(5, title="Leverage *...")-chan = input(title="Plot channel ?", type=input.bool, defval=false)+chan = input.bool(title="Plot channel ?", defval=false)-Bpos = input(title="Plot Bull positions ?", type=input.bool, defval=false)+Bpos = input.bool(title="Plot Bull positions ?", defval=false)-bpos = input(title="Plot Bear positions ?", type=input.bool, defval=false)+bpos = input.bool(title="Plot Bear positions ?", defval=false)-labels = input(title="Plot labels of bets ?", type=input.bool, defval=true)+labels = input.bool(title="Plot labels of bets ?", defval=true)-supp = input(title="Delete last labels ?", type=input.bool, defval=true)+supp = input.bool(title="Delete last labels ?", defval=true)// ------------------------------------------ //⋯// ------------------------------------------ //-pema = ema(close,Pema)+pema = ta.ema(close,Pema)plot(pema, title="EMA", color=color.blue)-canalhaut = highest(period)[1]+canalhaut = ta.highest(period)[1]-canalbas = lowest(period)[1]+canalbas = ta.lowest(period)[1]bear = close[1] > canalhaut[1] and close < open and high > pema⋯// ------------------------------------------ //-SlShort = highest(3)+SlShort = ta.highest(3)BidShort = close[1]⋯deltaShort = (SlShort-BidShort)/BidShort-betShort = round(loss/(lev*deltaShort)*100)/100+betShort = math.round(loss/(lev*deltaShort)*100)/100-cryptShort = round(betShort*lev/BidShort*1000)/1000+cryptShort = math.round(betShort*lev/BidShort*1000)/1000if bear[1] and labels //and low < low[1]-    Lbear = label.new(bar_index, na, text="SHORT\n\nSL: " + tostring(SlShort) + "\n\nBid: " + tostring(BidShort) + "\n\nTP: " + tostring(TpShort) + "\n\nMise: " + tostring(betShort) + "\n\nCryptos: " + tostring(cryptShort), color=color.red, textcolor=color.white, style=label.style_labeldown, yloc=yloc.abovebar)+    Lbear = label.new(bar_index, na, text="SHORT\n\nSL: " + str.tostring(SlShort) + "\n\nBid: " + str.tostring(BidShort) + "\n\nTP: " + str.tostring(TpShort) + "\n\nMise: " + str.tostring(betShort) + "\n\nCryptos: " + str.tostring(cryptShort), color=color.red, textcolor=color.white, style=label.style_labeldown, yloc=yloc.abovebar)    label.delete(supp ? Lbear[1] : na)⋯pbtp = plot(bpos? btp:na, color=color.green)-fill(pbentry,pbsl, color.red, transp=70)+fill(pbentry,pbsl, color.new(color.red, 70))-fill(pbentry,pbtp, color.green, transp=70)+fill(pbentry,pbtp, color.new(color.green, 70))// ------------------------------------------ //⋯// ------------------------------------------ //-SlLong = lowest(3)+SlLong = ta.lowest(3)BidLong = close[1]⋯deltaBull = (BidLong - SlLong)/BidLong-betLong = round(loss/(lev*deltaBull)*100)/100+betLong = math.round(loss/(lev*deltaBull)*100)/100-cryptLong = round(betLong*lev/BidLong*1000)/1000+cryptLong = math.round(betLong*lev/BidLong*1000)/1000if bull[1] and labels //and high > high[1]-    Lbull = label.new(bar_index, na, text="LONG\n\nSL: " + tostring(SlLong) + "\n\nBid: " + tostring(BidLong) + "\n\nTP: " + tostring(TpLong) + "\n\nMise: " + tostring(betLong) + "\n\nCryptos: " + tostring(cryptLong), color=color.green, textcolor=color.white, style=label.style_labelup, yloc=yloc.belowbar)+    Lbull = label.new(bar_index, na, text="LONG\n\nSL: " + str.tostring(SlLong) + "\n\nBid: " + str.tostring(BidLong) + "\n\nTP: " + str.tostring(TpLong) + "\n\nMise: " + str.tostring(betLong) + "\n\nCryptos: " + str.tostring(cryptLong), color=color.green, textcolor=color.white, style=label.style_labelup, yloc=yloc.belowbar)    label.delete(supp ? Lbull[1] : na)⋯pBtp = plot(Bpos?Btp:na, color=color.green)-fill(pBentry,pBsl, color.red, transp=70)+fill(pBentry,pBsl, color.new(color.red, 70))-fill(pBentry,pBtp, color.green, transp=70)+fill(pBentry,pBtp, color.new(color.green, 70))// ------------------------------------------ //⋯if (Bear and strategy.opentrades==0)-    strategy.order("short", false, 1, limit=BidShort)+    strategy.order("short", strategy.short, 1, limit=BidShort)    strategy.exit("exit", "short", limit = TpShort, stop = SlShort)⋯if (Bull and strategy.opentrades==0)-    strategy.order("long", true, 1, limit=BidLong)+    strategy.order("long", strategy.long, 1, limit=BidLong)    strategy.exit("exit", "long", limit = TpLong, stop = SlLong)⋯

Clean v5

Not verified

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L42:C290: 'label.style_labeldown' is not available in Pine Script v5. It was added in a later version.), so this step could not be checked.

  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 92: when = high > SlShort or low < (BidShort+TpShort)/2 → if block
  • Line 93: when = bull → if block
  • Line 98: when = low < SlLong or high > (BidLong+TpLong)/2 → if block
  • Line 99: when = bear → if block
⋯// ------------------------------------------ //-period = input(24, title="Channel's periods")+period = input.int(24, title="Channel's periods")-Pema = input(200, title="EMA's periods ?")+Pema = input.int(200, title="EMA's periods ?")ratio = input.float(3, title="Ratio TP")-loss = input(20, title="Risk Loss ($)")+loss = input.int(20, title="Risk Loss ($)")-lev = input(5, title="Leverage *...")+lev = input.int(5, title="Leverage *...")chan = input.bool(title="Plot channel ?", defval=false)⋯    strategy.exit("exit", "short", limit = TpShort, stop = SlShort)-strategy.cancel("short", when = high > SlShort or low < (BidShort+TpShort)/2)+if high > SlShort or low < (BidShort+TpShort)/2+    strategy.cancel("short")-strategy.close("short", when=bull)+if bull+    strategy.close("short")if (Bull and strategy.opentrades==0)⋯    -strategy.cancel("long", when = low < SlLong or high > (BidLong+TpLong)/2)+if low < SlLong or high > (BidLong+TpLong)/2+    strategy.cancel("long")-strategy.close("long", when=bear)+if bear+    strategy.close("long")

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L42:C290: 'label.style_labeldown' is not available in Pine Script v5. It was added in a later version.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © Mysteriown-//@version=5+//@version=6strategy("Lagged Donchian Channel + EMA", overlay = true)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Channel's periods24intcanalhaut canalbas
EMA's periods ?200intpema
Ratio TP3floatTpShort TpLong
Risk Loss ($)20intbetShort betLong
Leverage *...5intbetShort cryptShort betLong cryptLong
Plot channel ?falseboolcanalhautplot canalbasplot plot
Plot Bull positions ?falseboolpBentry pBsl pBtp plot
Plot Bear positions ?falseboolpbentry pbsl pbtp plot
Plot labels of bets ?trueboolline 41 line 67
Delete last labels ?trueboolline 43 line 69

What it calculates

  • EMA (ema, ta.ema in v5)close, EMA's periods ? (200)pema · line 22
  • Highest (highest, ta.highest in v5)Channel's periods (24)canalhaut · line 24
  • Lowest (lowest, ta.lowest in v5)Channel's periods (24)canalbas · line 25
  • Highest (highest, ta.highest in v5)3SlShort · line 35
  • Lowest (lowest, ta.lowest in v5)3SlLong · line 61

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 dataPemaEMA's periods ?setting · 200periodChannel's periodssetting · 24ratioRatio TPsetting · 3lossRisk Loss ($)setting · 20levLeverage *...setting · 5highhighprice dataopenopenprice datalowlowprice datapemaEMA→ pemacanalhautHighest→ canalhautcanalbasLowest→ canalbasSlShortHighest→ SlShortSlLongLowest→ SlLongBidShort, BidLongBidShort · BidLong2 valuesTpShortTpShortvaluedeltaShortdeltaShortvaluebetShortbetShortvaluecryptShortcryptShortvaluebentrybentryvaluebslbslvaluebtpbtpvalueTpLongTpLongvaluedeltaBulldeltaBullvaluebetLongbetLongvaluecryptLongcryptLongvalueBentryBentryvalueBslBslvalueBtpBtpvaluebearbearconditionbullbullconditionBearBearconditionBullBullconditionLbear, LbullColourLbear · Lbullorder:shortorder shortstrategy.orderexit:exitexit exitstrategy.exitcancel:shortcancel shortstrategy.cancelclose:shortClose shortstrategy.closeorder:longorder longstrategy.ordercancel:longcancel longstrategy.cancelclose:longClose longstrategy.closeplot:23EMAplotplot:28plotplotplot:29plotplotplotshape:30Bearplotshapeplotshape:31Bullplotshapeplot:52plotplotplot:53plotplotplot:54plotplotplot:55plotplotfill:56Fillfill × 4fill:57Fillfill × 4plot:78plotplotplot:79plotplotplot:80plotplotplot:81plotplotfill:82Fillfill × 4fill:83Fillfill × 4

Order rules

OrderFires whenBy defaultLine
order short short(Bear and strategy.opentrades==0)On90
Exit exit stop and limit(Bear and strategy.opentrades==0)On91
cancel shorthigh > SlShort or low < (BidShort+TpShort)/2On92
Close shortbullclose[1] < canalbas[1] and open < close and low < pemaOn93
order long long(Bull and strategy.opentrades==0)On95
Exit exit stop and limit(Bull and strategy.opentrades==0)On96
cancel longlow < SlLong or high > (BidLong+TpLong)/2On98
Close longbearclose[1] > canalhaut[1] and close < open and high > pemaOn99

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.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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−12.3%+102.5%40%0.0012.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.8%+5.5%1136%2.911.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.5%+9.8%1040%1.490.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.2%+8.4%714%0.100.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%1513%1.170.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%933%0.580.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%1127%0.820.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%922%1.640.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 market0—$0.00
Sideways market30%−$10,038.40
Falling market10%−$2,272.36

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

12.3%

The 95th percentile of the worst drawdown when the same 4 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 12.3% to 12.3%; the tick is what actually happened, 12.3%. Order luck alone moves it this much.

0%14%
All 4 trades
SideEntryExitBarsP&L
short23 Oct 2024 67,426.0028 Oct 2024 69,519.505−$2,093.51
short17 Aug 2025 118,295.005 Oct 2025 124,474.0049−$6,178.91
long29 Jan 2026 88,347.1029 Jan 2026 86,074.700−$2,272.36
short24 Aug 2026 77,734.0024 Aug 2026 79,500.000−$1,766.00

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
Lagged Donchian Channel + EMA this page—v4 strategy−12.3%412.3%
CC Trend strategy 2- Downtrend Short by CheatCode1ema highest lowestv5 strategyNo trades on this market
TrianglePoint strategy by mohaneehighest lowest emav4 strategy+45.4%11101.9%
Backtest Custom HiLo Strategy by luyikaibrema highest lowestv4 strategyNo trades on this market
CM_SlingShotSystem+_CassicEMA+Willams21EMA13 htc1977 edition by Arivadisema highest lowestv5 strategyNo trades on this market
EMA Mean Reversion Strategy by jordanfrayema highest lowestv5 strategy+4.7%2308.9%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 32 msWith a workaround 1,000 bars in 79 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as false, true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 90, 95) so the engine trades the way the script says. 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/// © Mysteriown//@version=4strategy("Lagged Donchian Channel + EMA", overlay = true)//tradePeriod = time(timeframe.period,"0000-0000:1234567")?true:false// ------------------------------------------ //// ----------------- Inputs ----------------- //// ------------------------------------------ //period = input(24, title="Channel's periods")Pema = input(200, title="EMA's periods ?")ratio = input(3, title="Ratio TP", type=input.float)loss = input(20, title="Risk Loss ($)")lev = input(5, title="Leverage *...")chan = input(title="Plot channel ?", type=input.bool, defval=false)Bpos = input(title="Plot Bull positions ?", type=input.bool, defval=false)bpos = input(title="Plot Bear positions ?", type=input.bool, defval=false)labels = input(title="Plot labels of bets ?", type=input.bool, defval=true)supp = input(title="Delete last labels ?", type=input.bool, defval=true)// ------------------------------------------ //// ---------- Canal, EMA and arrow ---------- //// ------------------------------------------ //pema = ema(close,Pema)plot(pema, title="EMA", color=color.blue)canalhaut = highest(period)[1]canalbas = lowest(period)[1]bear = close[1] > canalhaut[1] and close < open and high > pemabull = close[1] < canalbas[1] and open < close and low < pemacanalhautplot = plot(chan? canalhaut:na, color=color.yellow)canalbasplot = plot(chan? canalbas:na, color=color.yellow)plotshape(bear, title='Bear', style=shape.triangledown, location=location.abovebar, color=color.red, offset=0)plotshape(bull, title='Bull', style=shape.triangleup, location=location.belowbar, color=color.green, offset=0)// ------------------------------------------ //// ------------- Position Short ------------- //// ------------------------------------------ //SlShort = highest(3)BidShort = close[1]TpShort = BidShort-((SlShort-BidShort)*ratio)deltaShort = (SlShort-BidShort)/BidShortbetShort = round(loss/(lev*deltaShort)*100)/100cryptShort = round(betShort*lev/BidShort*1000)/1000if bear[1] and labels //and low < low[1]    Lbear = label.new(bar_index, na, text="SHORT\n\nSL: " + tostring(SlShort) + "\n\nBid: " + tostring(BidShort) + "\n\nTP: " + tostring(TpShort) + "\n\nMise: " + tostring(betShort) + "\n\nCryptos: " + tostring(cryptShort), color=color.red, textcolor=color.white, style=label.style_labeldown, yloc=yloc.abovebar)    label.delete(supp ? Lbear[1] : na)var bentry=0.0var bsl=0.0var btp=0.0if bear[1] and low < low[1]    bentry:=BidShort    bsl:=SlShort    btp:=TpShort    pbentry = plot(bpos? bentry:na, color=color.orange)plot(bpos? (bentry+btp)/2:na, color=color.gray)pbsl = plot(bpos? bsl:na, color=color.red)pbtp = plot(bpos? btp:na, color=color.green)fill(pbentry,pbsl, color.red, transp=70)fill(pbentry,pbtp, color.green, transp=70)// ------------------------------------------ //// ------------- Position Long -------------- //// ------------------------------------------ //SlLong = lowest(3)BidLong = close[1]TpLong = BidLong + ((BidLong - SlLong) * ratio)deltaBull = (BidLong - SlLong)/BidLongbetLong = round(loss/(lev*deltaBull)*100)/100cryptLong = round(betLong*lev/BidLong*1000)/1000if bull[1] and labels //and high > high[1]    Lbull = label.new(bar_index, na, text="LONG\n\nSL: " + tostring(SlLong) + "\n\nBid: " + tostring(BidLong) + "\n\nTP: " + tostring(TpLong) + "\n\nMise: " + tostring(betLong) + "\n\nCryptos: " + tostring(cryptLong), color=color.green, textcolor=color.white, style=label.style_labelup, yloc=yloc.belowbar)    label.delete(supp ? Lbull[1] : na)var Bentry=0.0var Bsl=0.0var Btp=0.0if bull[1] and high > high[1]    Bentry:=BidLong    Bsl:=SlLong    Btp:=TpLong    pBentry = plot(Bpos?Bentry:na, color=color.orange)plot(Bpos?(Bentry+Btp)/2:na, color=color.gray)pBsl = plot(Bpos?Bsl:na, color=color.red)pBtp = plot(Bpos?Btp:na, color=color.green)fill(pBentry,pBsl, color.red, transp=70)fill(pBentry,pBtp, color.green, transp=70)// ------------------------------------------ //// --------------- Strategie ---------------- //// ------------------------------------------ //Bear = bear[1] and low < low[1]Bull = bull[1] and high > high[1]if (Bear and strategy.opentrades==0)    strategy.order("short", false, 1, limit=BidShort)    strategy.exit("exit", "short", limit = TpShort, stop = SlShort)strategy.cancel("short", when = high > SlShort or low < (BidShort+TpShort)/2)strategy.close("short", when=bull)if (Bull and strategy.opentrades==0)    strategy.order("long", true, 1, limit=BidLong)    strategy.exit("exit", "long", limit = TpLong, stop = SlLong)    strategy.cancel("long", when = low < SlLong or high > (BidLong+TpLong)/2)strategy.close("long", when=bear)