Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN]

A Pine Script v5 strategy built on EMA (close, 21), RSI or EMA (close, short_l2, 15) and Change (high). It has 9 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade commits 10.0% of equity and pays 0.075 commission. 32 settings; defaults include Fast EMA length 21, Mid EMA length 89 and Slow EMA length 200.

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 Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] do on BTCUSDT 1D with default settings?
−0.30%
From 26 Jan 2024 to 21 Oct 2026, over 2 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] have?
2
alertSyntaxBase + 'side:long'; alertSyntaxBase + 'side:short'.
Does Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] 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: 2 before, 1 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 Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] use a stop loss?
No
Its exits set a profit target but no stop.

BTCUSDT · 1D · default settings

  • FAST EMA
  • MID EMA
  • SLOW EMA
  • Shape
  • Shape
  • 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 (32)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$997$2,025Equity from $1,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.
Table drawn by the script, as it stood on the last bar
Start: long1736985600000
End: NaN
Net Profit: -0.3%
Percent Per Day NaN%
Percent Profitable: 0%
Profit Factor: 0
Total Trades: 2
Max Wins In A Row: 0
Max Losses In A Row: 2
Net profit
−0.30%
−$3.00
Buy and hold
+102.5%
same period
Closed trades
2
0 won · 2 lost
Profitable
0.0%
of closed trades
Profit factor
0.00
gross profit ÷ gross loss
Max drawdown
0.30%
−$3.00

One run with the author's default settings, $1,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.

  • Note

    2 settings have no label

    In the settings dialog startPeriodTime (line 135), endPeriodTime (line 137) show an empty name. The labels on this page come from the variable names.

  • 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 199, 200, 201. 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.

SettingDefaultType and rangeFeeds
EMA Cloud
Fast EMA length21int · step 1fEMA
Mid EMA length89int · step 1mEMA
Slow EMA length200int · step 10sEMA
B-XTENDER INPUTS
Short - L15intshortTermXtrender
Short - L220intshortTermXtrender
Short - L315intshortTermXtrender
Long - L120intlongTermXtrender
Long - L215intlongTermXtrender
Minimum Gap Distance Between EMAs
Minimum distance between 21, 89 and 200 EMAs78intEMAUptrendWithDistance EMADowntrendWithDistance
EMA Pullback Settings
% Diff for EMA Pullback0.5float · step 0.1longPBcheck shortPBcheck
Lookback for EMA Pullback8intlongPB shortPB
Trade Direction
Use Close SignaltrueboolcloseLongCondition closeShortCondition
Trade DirectionLong and Shortstring · options ['Long and Short', 'Long Only', 'Short Only']entry Long entry Short line 187 line 190
ADX
Average Directional Index (ADX)falsebooladxsig isADX
ADX Smoothing14intadx adxsig
DI Length14intadxplus adxminus adxsig
ADX Threshold26intisADX
Date Range
Starttrueboolstart
Start Period Time (no label in the script)timestamp('1 Jan 2019')timestart
Endtrueboolend
End Period Time (no label in the script)timestamp('31 Dec 2030')timeend
Take Profit
Take Profit 1 - Target %0.5float · min 0.0 · step 0.5exit TP1
% Of Position25int · min 0exit TP1
Take Profit 2 - Target %1.5float · min 0.0 · step 0.5exit TP2
% Of Position50int · min 0exit TP2
Take Profit 3 - Target %2.5float · min 0.0 · step 0.5exit TP3
% Of Position25int · min 0exit TP3
Take Profit 4 - Target %7.5float · min 0.0 · step 0.5exit TP4
Stop Loss
Stop Loss (%)3.0float · min 0.01 · step 0.5slLongClose slShortClose
Leverage
Leverage1float · step .5contracts
ProfitView Alert Syntax
Alert Syntax PrefixCRYPTANEX_99FTX_Strategy-Name-HerestringalertSyntaxBase
Dashboard
Show Dashboardtrueboolline 210

What it calculates

  • EMAclose, Fast EMA length (21)fEMA · line 28
  • EMAclose, Mid EMA length (89)mEMA · line 29
  • EMAclose, Slow EMA length (200)sEMA · line 30
  • RSI / EMAta.ema(close, short_l1) - ta.ema(close, short_l2), Short - L3 (15)shortTermXtrender · line 43
  • RSI / EMAta.ema(close, long_l1), Long - L2 (15)longTermXtrender · line 44
  • EMAsrc, lenxe1_1 · line 48
  • EMAxe1_1, lenxe2_1 · line 49
  • EMAxe2_1, lenxe3_1 · line 50
  • EMAxe3_1, lenxe4_1 · line 51
  • EMAxe4_1, lenxe5_1 · line 52
  • EMAxe5_1, lenxe6_1 · line 53
  • Changehighadxup · line 118
  • Changelowadxdown · line 119
  • RMAta.tr, lenadxtruerange · line 122
  • RMAmath.abs(adxplus - adxminus) / (adxsum == 0 ? 1 : adxsum), ADX Smoothing (14)adx · line 129

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.

The script has 100 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long longlongConditionCalc and tradeDirection != 'Short Only' and isInLongPosition == falseOn188
Open Short shortshortConditionCalc and tradeDirection != 'Long Only' and isInShortPosition == falseOn191
Exit TP1 limitcalcPeriodOn195
Exit TP2 limitcalcPeriodOn196
Exit TP3 limitcalcPeriodOn197
Exit TP4 limitcalcPeriodOn198
Close LongslLongCloseclose < strategy.position_avg_price * (1 - stoplossPercent)On199
Close ShortslShortCloseclose > strategy.position_avg_price * (1 + stoplossPercent)On200
Close closeLongCondition or closeShortConditionOn201

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
(no title)alertalertSyntaxBase + 'side:long'189
(no title)alertalertSyntaxBase + 'side:short'192

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

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].
  • CheckIntrabar recalculationuses varip. Live values can differ from history.
  • 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−0.3%+102.5%20%0.000.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.4%+5.5%30%0.000.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.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%−$3.00
Sideways market0—$0.00
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?

0.3%

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

0%1%
All 2 trades
SideEntryExitBarsP&L
long16 Jan 2025 100,497.0016 Jan 2025 100,497.000−$1.50
long25 Jun 2025 106,083.0025 Jun 2025 106,083.000−$1.50

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
Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP-MYN] this page—v5 strategy−0.3%20.3%
PMA Strategy Idea by QuantCTema rising fallingv4 strategy+51.7%12930.8%
Take Profit On Trend v2 (by BHD_Trade_Bot) by BHD_Trade_Botema rsi rmav5 strategy+9.4%624.0%
MTF Diagonally Layered RSI - 1 minute Bitcoin Bot [wbburgin] by wbburginrsi rma emav5 strategyNo trades on this market
5min MACD scalp by Joel by Zippy111ema rsi rising fallingv5 strategydoes not run in Zeal Terminal
TEMA-DEMA-HMA Strategy by Tuned_Officialema rising fallingv4 strategy+73.8%430.6%

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.

  • 3 strategy calls use the when = argument (line 199, 200, 201). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 9 settings use the untyped input() (line 38, 39, 40, 41, 42, 76, 114, 115, 116). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 2 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 38: input() → input.int()
  • Line 39: input() → input.int()
  • Line 40: input() → input.int()
  • Line 41: input() → input.int()
  • Line 42: input() → input.int()
  • Line 76: input() → input.int()
6 more edits
  • Line 114: input() → input.int()
  • Line 115: input() → input.int()
  • Line 116: input() → input.int()
  • Line 199: when = slLongClose → if block
  • Line 200: when = slShortClose → if block
  • Line 201: when = closeLongCondition or closeShortCondition → if block
⋯var string BXTenderGroupName = 'B-XTENDER INPUTS'-short_l1 = input(5, title='Short - L1', group = BXTenderGroupName)+short_l1 = input.int(5, title='Short - L1', group = BXTenderGroupName)-short_l2 = input(20, title='Short - L2', group = BXTenderGroupName)+short_l2 = input.int(20, title='Short - L2', group = BXTenderGroupName)-short_l3 = input(15, title='Short - L3', group = BXTenderGroupName)+short_l3 = input.int(15, title='Short - L3', group = BXTenderGroupName)-long_l1 = input(20, title='Long - L1', group = BXTenderGroupName)+long_l1 = input.int(20, title='Long - L1', group = BXTenderGroupName)-long_l2 = input(15, title='Long - L2', group = BXTenderGroupName)+long_l2 = input.int(15, title='Long - L2', group = BXTenderGroupName)shortTermXtrender = ta.rsi(ta.ema(close, short_l1) - ta.ema(close, short_l2), short_l3) - 50⋯var string EMADistanceGroupName = 'Minimum Gap Distance Between EMAs'-i_minDistanceBetweenEMAs = input(78,title="Minimum distance between 21, 89 and 200 EMAs", group = EMADistanceGroupName)+i_minDistanceBetweenEMAs = input.int(78,title="Minimum distance between 21, 89 and 200 EMAs", group = EMADistanceGroupName)bool EMAUptrendWithDistance = (fEMA > (mEMA + i_minDistanceBetweenEMAs)) and (mEMA > (sEMA + i_minDistanceBetweenEMAs)) ⋯adxEnabled = input.bool(defval = false , title = "Average Directional Index (ADX)", tooltip = "", group ="ADX" ) -adxlen = input(14, title = "ADX Smoothing", group="ADX")+adxlen = input.int(14, title = "ADX Smoothing", group="ADX")-adxdilen = input(14, title = "DI Length", group="ADX")+adxdilen = input.int(14, title = "DI Length", group="ADX")-adxabove = input(26, title = "ADX Threshold", group="ADX")+adxabove = input.int(26, title = "ADX Threshold", group="ADX")adxdirmov(len) =>⋯    strategy.exit('TP4', profit=per(tp4))-    strategy.close('Long', qty_percent=100, comment='SL Long', when=slLongClose)+    if slLongClose+        strategy.close('Long', qty_percent=100, comment='SL Long')-    strategy.close('Short', qty_percent=100, comment='SL Short', when=slShortClose)+    if slShortClose+        strategy.close('Short', qty_percent=100, comment='SL Short')-    strategy.close_all(when=closeLongCondition or closeShortCondition, comment='Close Postion')+    if closeLongCondition or closeShortCondition+        strategy.close_all(comment='Close Postion')/// Dashboard⋯

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: 2 before, 1 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.

⋯// © spdoinkal / myncrypto-//@version=5+//@version=6strategy('Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP/MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=1000, currency='USD', default_qty_type=strategy.percent_of_equity, default_qty_value=10.0, commission_value=0.075, use_bar_magnifier = false)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 112 msYes 1,000 bars in 140 msNot measured
PineTSNot testedNot testedNot measured

“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/// © spdoinkal / myncrypto//@version=5strategy('Strategy Myth-Busting #13 - MultiEMA+BXTrender - [SP/MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=1000, currency='USD', default_qty_type=strategy.percent_of_equity, default_qty_value=10.0, commission_value=0.075, use_bar_magnifier = false)// Secret EMA Cloud by teddycleps// B-X Trender // Keep all default// Distance between EMA's need to be spaced, otherwise in a ranged market// 15 min candles// Stop Loss on previous swing high/low// No take profit. Exit on new red/green circle//Long//EMA Green (21) on top, White (89)in middle and red (200) on bottom and there is distance between EMA's need to be spaced, otherwise in a ranged market// Price action must pull back into 89 EMA (White line) either close or touching it.// Once pullback occurs wait for BX Trender to issue a new green circle and BX Trend line must be green and above 0// Price action must also pull up back above the (Green Line) EMA 21//Short//EMA Red (200) on top, White (89) in middle and Green (21) on bottom and there is distance between EMA's need to be spaced, otherwise in a ranged market// Price action must pull back into 89 EMA (White line) either close or touching it.// Once pullback occurs wait for BX Trender to issue a new red circle and BX Trend line must be red and below 0// Price action must also pull up back below the (green Line) EMA 21// 21/89/200 EMA Cloud//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░var string EMAGroupName = 'EMA Cloud'i_fastEMALength = input.int(21, title = 'Fast EMA length', step = 1, group = EMAGroupName)i_midEMALength = input.int(89, title = 'Mid EMA length', step = 1, group = EMAGroupName)i_slowEMALength = input.int(200, title ='Slow EMA length', step = 10, group = EMAGroupName)fEMA = ta.ema(close, i_fastEMALength)mEMA = ta.ema(close, i_midEMALength)sEMA = ta.ema(close, i_slowEMALength)plotFEMA = plot(fEMA, 'FAST EMA', color=color.new(color.green, 0), linewidth = 2, style=plot.style_line)plotMEMA = plot(mEMA, 'MID EMA', color=color.new(color.white, 0), linewidth = 2, style=plot.style_line)plotSEMA = plot(sEMA, 'SLOW EMA', color=color.new(color.red, 0), linewidth = 2, style=plot.style_line)fill(plotFEMA, plotSEMA, color=fEMA > sEMA ? color.new(color.green, 80) : color.new(color.red, 70), title='EMA Background Fill')// B-Xtrender @Puppytherapy//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░var string BXTenderGroupName = 'B-XTENDER INPUTS'short_l1 = input(5, title='Short - L1', group = BXTenderGroupName)short_l2 = input(20, title='Short - L2', group = BXTenderGroupName)short_l3 = input(15, title='Short - L3', group = BXTenderGroupName)long_l1 = input(20, title='Long - L1', group = BXTenderGroupName)long_l2 = input(15, title='Long - L2', group = BXTenderGroupName)shortTermXtrender = ta.rsi(ta.ema(close, short_l1) - ta.ema(close, short_l2), short_l3) - 50longTermXtrender = ta.rsi(ta.ema(close, long_l1), long_l2) - 50// shortXtrenderCol = shortTermXtrender > 0 ? shortTermXtrender > shortTermXtrender[1] ? color.lime : #228B22 : shortTermXtrender > shortTermXtrender[1] ? color.red : #8B0000// plot(shortTermXtrender, color=shortXtrenderCol, style=plot.style_columns, linewidth=1, title='B-Xtrender Osc. - Histogram', transp=50)t3(src, len) =>    xe1_1 = ta.ema(src, len)    xe2_1 = ta.ema(xe1_1, len)    xe3_1 = ta.ema(xe2_1, len)    xe4_1 = ta.ema(xe3_1, len)    xe5_1 = ta.ema(xe4_1, len)    xe6_1 = ta.ema(xe5_1, len)    b_1 = 0.7    c1_1 = -b_1 * b_1 * b_1    c2_1 = 3 * b_1 * b_1 + 3 * b_1 * b_1 * b_1    c3_1 = -6 * b_1 * b_1 - 3 * b_1 - 3 * b_1 * b_1 * b_1    c4_1 = 1 + 3 * b_1 + b_1 * b_1 * b_1 + 3 * b_1 * b_1    nT3Average_1 = c1_1 * xe6_1 + c2_1 * xe5_1 + c3_1 * xe4_1 + c4_1 * xe3_1    nT3Average_1maShortTermXtrender = t3(shortTermXtrender, 5)// colShortTermXtrender = maShortTermXtrender > maShortTermXtrender[1] ? color.lime : color.red// plot(maShortTermXtrender, color=color.new(#000000, 0), style=plot.style_line, linewidth=3, title='B-Xtrender Shadow')// plot(maShortTermXtrender, color=colShortTermXtrender, style=plot.style_line, linewidth=3, title='B-Xtrender Color ')BXTenderLongEntryCondition = maShortTermXtrender > maShortTermXtrender[1] and maShortTermXtrender[1] < maShortTermXtrender[2] BXTenderShortEntryCondition = maShortTermXtrender < maShortTermXtrender[1] and maShortTermXtrender[1] > maShortTermXtrender[2]plotshape(BXTenderLongEntryCondition ? maShortTermXtrender : na, location=location.belowbar, style=shape.circle, color=color.new(color.lime, 10), size=size.tiny)plotshape(BXTenderShortEntryCondition ? maShortTermXtrender : na, location=location.abovebar, style=shape.circle, color=color.new(color.red, 10), size=size.tiny)///////////////////////////////////////* Put your strategy rules below *///////////////////////////////////////uptrend = fEMA > mEMA and mEMA > sEMA  dntrend = fEMA < mEMA and mEMA < sEMA  // Checks for suitable distance between EMASvar string EMADistanceGroupName = 'Minimum Gap Distance Between EMAs'i_minDistanceBetweenEMAs = input(78,title="Minimum distance between 21, 89 and 200 EMAs", group = EMADistanceGroupName)bool EMAUptrendWithDistance = (fEMA > (mEMA + i_minDistanceBetweenEMAs)) and (mEMA > (sEMA + i_minDistanceBetweenEMAs)) bool EMADowntrendWithDistance = (fEMA < (mEMA - i_minDistanceBetweenEMAs)) and (mEMA < (sEMA - i_minDistanceBetweenEMAs)) fill(plotFEMA, plotSEMA, color = EMAUptrendWithDistance or EMADowntrendWithDistance  ? color.new(color.gray, 70) : na)// var string pullBackGroupName = 'EMA Pullback Settings'// i_marginAboveOrBelowMidEMA = input(100,title="Margin of proximity to middle EMA for pullback detection", group=pullBackGroupName)// i_lookbackForEMAPullback = input(8, title="Lookback for EMA Pullback", group=pullBackGroupName)// longMidEMAWithMargin = mEMA + i_marginAboveOrBelowMidEMA// shortMidEMAWithMargin = mEMA - i_marginAboveOrBelowMidEMA// longEMAPullBack = close < longMidEMAWithMargin// shortEMAPullBack= close > shortMidEMAWithMargin // longPB = ta.barssince(longEMAPullBack) <= i_lookbackForEMAPullback// shortPB = ta.barssince(shortEMAPullBack) <= i_lookbackForEMAPullback//Check for pullback / pushup into middle EMA calcsvar string pullBackGroupName = 'EMA Pullback Settings'PBperc = input.float(0.5, title = "% Diff for EMA Pullback", step = 0.1, group=pullBackGroupName)PBlength = input.int(8, title = "Lookback for EMA Pullback", group=pullBackGroupName)// Look for a pullback to the middle EMA (LONGS)longPercentDiff = ((low - mEMA) / low) * 100longPBcheck = longPercentDiff <= PBperclongPB = ta.barssince(longPBcheck) <= PBlength// Look for a pushup to the middle EMA (SHORTS)shortPercentDiff = ((mEMA - high) / mEMA) * 100shortPBcheck = shortPercentDiff <= PBpercshortPB = ta.barssince(shortPBcheck) <= PBlengthplotshape(longPB and not longPB[1], "", shape.labelup,   location.belowbar, color= color.green, textcolor = color.white, text = "(2) Bull Pullback")plotshape(shortPB and not shortPB[1], "", shape.labeldown,   location.abovebar, color= color.red, textcolor = color.white, text = "(2) Bear Pullback")longCondition = uptrend  and EMAUptrendWithDistance and longPB and BXTenderLongEntryCondition and longTermXtrender > 0 and ta.rising(longTermXtrender, 1) and close > fEMAshortCondition = dntrend and EMADowntrendWithDistance and shortPB and BXTenderShortEntryCondition and longTermXtrender < 0 and ta.falling(longTermXtrender, 1) and close < fEMAcloseLong = BXTenderShortEntryConditioncloseShort = BXTenderLongEntryConditionuseClose = input.bool(true, title = "Use Close Signal", group='Trade Direction')//define as 0 if do not want to usecloseLongCondition = useClose ? closeLong : 0closeShortCondition = useClose ? closeShort :  0// ADX//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░adxEnabled = input.bool(defval = false , title = "Average Directional Index (ADX)", tooltip = "", group ="ADX" ) adxlen = input(14, title = "ADX Smoothing", group="ADX")adxdilen = input(14, title = "DI Length", group="ADX")adxabove = input(26, title = "ADX Threshold", group="ADX")adxdirmov(len) =>    adxup = ta.change(high)    adxdown = -ta.change(low)    adxplusDM = na(adxup) ? na : (adxup > adxdown and adxup > 0 ? adxup : 0)    adxminusDM = na(adxdown) ? na : (adxdown > adxup and adxdown > 0 ? adxdown : 0)    adxtruerange = ta.rma(ta.tr, len)    adxplus = fixnan(100 * ta.rma(adxplusDM, len) / adxtruerange)    adxminus = fixnan(100 * ta.rma(adxminusDM, len) / adxtruerange)    [adxplus, adxminus]adx(adxdilen, adxlen) =>    [adxplus, adxminus] = adxdirmov(adxdilen)    adxsum = adxplus + adxminus    adx = 100 * ta.rma(math.abs(adxplus - adxminus) / (adxsum == 0 ? 1 : adxsum), adxlen)adxsig = adxEnabled ? adx(adxdilen, adxlen) : naisADX = adxEnabled ? (adxsig > adxabove) : true//Backtesting Time Period (Input.time not working as expected as of 03/30/2021.  Giving odd start/end dates//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░useStartPeriodTime = input.bool(true, 'Start', group='Date Range', inline='Start Period')startPeriodTime = input.time(timestamp('1 Jan 2019'), '', group='Date Range', inline='Start Period')useEndPeriodTime = input.bool(true, 'End', group='Date Range', inline='End Period')endPeriodTime = input.time(timestamp('31 Dec 2030'), '', group='Date Range', inline='End Period')start = useStartPeriodTime ? startPeriodTime >= time : falseend = useEndPeriodTime ? endPeriodTime <= time : falsecalcPeriod = not start and not end// Trade Direction // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tradeDirection = input.string('Long and Short', title = 'Trade Direction', options=['Long and Short', 'Long Only', 'Short Only'], group='Trade Direction')// Percent as Points// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░per(pcnt) =>    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)// Take profit 1// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tp1 = input.float(title = 'Take Profit 1 - Target %', defval=0.5, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 1')q1 = input.int(title = '% Of Position', defval=25, minval=0, group='Take Profit', inline='Take Profit 1')// Take profit 2// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tp2 = input.float(title = 'Take Profit 2 - Target %', defval=1.5, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 2')q2 = input.int(title = '% Of Position', defval=50, minval=0, group='Take Profit', inline='Take Profit 2')// Take profit 3// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tp3 = input.float(title = 'Take Profit 3 - Target %', defval=2.5, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 3')q3 = input.int(title = '% Of Position', defval=25, minval=0, group='Take Profit', inline='Take Profit 3')// Take profit 4// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tp4 = input.float(title = 'Take Profit 4 - Target %', defval=7.5, minval=0.0, step=0.5, group='Take Profit')/// Stop Loss// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░stoplossPercent = input.float(title = 'Stop Loss (%)', defval=3.0, minval=0.01, step = 0.5, group='Stop Loss') * 0.01slLongClose = close < strategy.position_avg_price * (1 - stoplossPercent)slShortClose = close > strategy.position_avg_price * (1 + stoplossPercent)/// Leverage// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░leverage = input.float(1, 'Leverage', step=.5, group='Leverage')contracts = math.min(math.max(.000001, strategy.equity / close * leverage), 1000000000)/// Trade State Management// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░isInLongPosition = strategy.position_size > 0isInShortPosition = strategy.position_size < 0/// ProfitView Alert Syntax String Generation// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░alertSyntaxPrefix = input.string(defval='CRYPTANEX_99FTX_Strategy-Name-Here', title = 'Alert Syntax Prefix', group='ProfitView Alert Syntax')alertSyntaxBase = alertSyntaxPrefix + '\n#' + str.tostring(open) + ',' + str.tostring(high) + ',' + str.tostring(low) + ',' + str.tostring(close) + ',' + str.tostring(volume) + ','/// Trade Execution// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░longConditionCalc = (longCondition and isADX)shortConditionCalc = (shortCondition and isADX)// plotshape(shortConditionCalc, title='Short', style=shape.labeldown, location=location.abovebar, size=size.tiny, text='Short', textcolor=color.new(color.white, 0), color=color.new(color.red, 0))// plotshape(longConditionCalc, title='Long', style=shape.labelup, location=location.belowbar, size=size.tiny, text='Long', textcolor=color.new(color.white, 0), color=color.new(color.green, 0))if calcPeriod    if longConditionCalc and tradeDirection != 'Short Only' and isInLongPosition == false        strategy.entry('Long', strategy.long, qty=contracts)        alert(message=alertSyntaxBase + 'side:long', freq=alert.freq_once_per_bar_close)    if shortConditionCalc and tradeDirection != 'Long Only' and isInShortPosition == false        strategy.entry('Short', strategy.short, qty=contracts)        alert(message=alertSyntaxBase + 'side:short', freq=alert.freq_once_per_bar_close)        //Inspired from Multiple %% profit exits example by adolgo https://www.tradingview.com/script/kHhCik9f-Multiple-profit-exits-example/    strategy.exit('TP1', qty_percent=q1, profit=per(tp1))    strategy.exit('TP2', qty_percent=q2, profit=per(tp2))    strategy.exit('TP3', qty_percent=q3, profit=per(tp3))    strategy.exit('TP4', profit=per(tp4))    strategy.close('Long', qty_percent=100, comment='SL Long', when=slLongClose)    strategy.close('Short', qty_percent=100, comment='SL Short', when=slShortClose)    strategy.close_all(when=closeLongCondition or closeShortCondition, comment='Close Postion')/// Dashboard// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// Inspired by https://www.tradingview.com/script/uWqKX6A2/ - Thanks VertMTshowDashboard = input.bool(group="Dashboard", title = "Show Dashboard", defval=true)f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) =>    _cellText = _title + "\n" + _value    table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor, text_size=size.auto)// Draw dashboard tableif showDashboard    var bgcolor = color.new(color.black,0)        // Keep track of Wins/Losses streaks    newWin  = (strategy.wintrades  > strategy.wintrades[1]) and (strategy.losstrades == strategy.losstrades[1]) and (strategy.eventrades == strategy.eventrades[1])    newLoss = (strategy.wintrades == strategy.wintrades[1]) and (strategy.losstrades  > strategy.losstrades[1]) and (strategy.eventrades == strategy.eventrades[1])    varip int winRow     = 0    varip int lossRow    = 0    varip int maxWinRow  = 0    varip int maxLossRow = 0    if newWin        lossRow := 0        winRow := winRow + 1    if winRow > maxWinRow        maxWinRow := winRow            if newLoss        winRow := 0        lossRow := lossRow + 1    if lossRow > maxLossRow        maxLossRow := lossRow    // Prepare stats table    var table dashTable = table.new(position.bottom_right, 1, 15, border_width=1)           if barstate.islastconfirmedhistory        // Update table        dollarReturn = strategy.netprofit        f_fillCell(dashTable, 0, 0, "Start:", str.format("{0,date,long}", strategy.closedtrades.entry_time(0)) , bgcolor, color.white) // + str.format(" {0,time,HH:mm}", strategy.closedtrades.entry_time(0))         f_fillCell(dashTable, 0, 1, "End:", str.format("{0,date,long}", strategy.opentrades.entry_time(0)) , bgcolor, color.white) // + str.format(" {0,time,HH:mm}", strategy.opentrades.entry_time(0))        _profit = (strategy.netprofit / strategy.initial_capital) * 100        f_fillCell(dashTable, 0, 2, "Net Profit:", str.tostring(_profit, '##.##') + "%", _profit > 0 ? color.green : color.red, color.white)        _numOfDaysInStrategy = (strategy.opentrades.entry_time(0) - strategy.closedtrades.entry_time(0)) / (1000 * 3600 * 24)        f_fillCell(dashTable, 0, 3, "Percent Per Day", str.tostring(_profit / _numOfDaysInStrategy, '#########################.#####')+"%", _profit > 0 ? color.green : color.red, color.white)        _winRate = ( strategy.wintrades / strategy.closedtrades ) * 100        f_fillCell(dashTable, 0, 4, "Percent Profitable:", str.tostring(_winRate, '##.##') + "%", _winRate < 50 ? color.red : _winRate < 75 ? #999900 : color.green, color.white)        f_fillCell(dashTable, 0, 5, "Profit Factor:", str.tostring(strategy.grossprofit / strategy.grossloss,  '##.###'), strategy.grossprofit > strategy.grossloss ? color.green : color.red, color.white)        f_fillCell(dashTable, 0, 6, "Total Trades:", str.tostring(strategy.closedtrades), bgcolor, color.white)        f_fillCell(dashTable, 0, 8, "Max Wins In A Row:", str.tostring(maxWinRow, '######') , bgcolor, color.white)        f_fillCell(dashTable, 0, 9, "Max Losses In A Row:", str.tostring(maxLossRow, '######') , bgcolor, color.white)