Pine Script v5 · Strategy
Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN]
A Pine Script v5 strategy built on SMA or EMA or WMA or VWMA or RMA or Linreg (src, 14), EMA (src, 14) and WMA (src, 14). 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 100.0% of equity and pays 0.075 commission. 26 settings; defaults include MA Type EMA, Period 1 3 and Period 2 7.
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 #2 - Braid Filter+ADX+EMA-Trend - [MYN] repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] do on BTCUSDT 1D with default settings?
- −47.18%
- From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] have?
- 2
- alertSyntaxBase + 'side:long'; alertSyntaxBase + 'side:short'.
- Does Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L217:C7: cannot use 'int' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download.
- Does Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] use a stop loss?
- No
- Its exits set a profit target but no stop.
BTCUSDT · 1D · default settings
- EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Start: long1731801600000 |
| End: long1787443200000 |
| Net Profit: -47.18% |
| Percent Per Day -0.07327% |
| Percent Profitable: 0% |
| Profit Factor: 0 |
| Total Trades: 4 |
| Max Wins In A Row: 0 |
| Max Losses In A Row: 4 |
- Net profit
- −47.18%
- −$9,436.56
- 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
- 48.63%
- −$9,725.54
One run with the author's default settings, $20,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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
5 settings have no label
In the settings dialog PipsMinSepPercent (line 30), len (line 119), th (line 120), startPeriodTime (line 153), endPeriodTime (line 155) 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 213, 214, 215. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Braid Filter | |||
| MA Type | EMA | string · options ['EMA', 'DEMA', 'TEMA', 'WMA', 'VWMA', 'SMA', 'SMMA', 'HMA', 'LSMA', 'Kijun', 'McGinley', 'RMA'] | ma01 ma02 ma03 |
| Period 1 | 3 | int | ma01 |
| Period 2 | 7 | int | ma02 |
| Period 3 | 14 | int | ma03 |
| Pips Min Sep Percent (no label in the script) | 40 | int | filter |
| Show EMA Trend is Based On? | true | bool | EMA |
| Len (no label in the script) | 14 | int | result e w kijun mg SmoothedTrueRange SmoothedDirectionalMovementPlus SmoothedDirectionalMovementMinus ADX |
| Th (no label in the script) | 20 | int | entryADXAboveThreshold |
| EMA Trend Bars | |||
| EMA UpTrend | 100 | int · min 1 · max 300 | usedEma |
| ADX and DI | |||
| ADX Slope | 3.5 | float · min 0 · max 300 · step .5 | entryADXAboveThreshold |
| Date Range | |||
| Start | true | bool | start |
| Start Period Time (no label in the script) | timestamp('1 Jan 2019') | time | start |
| End | true | bool | end |
| End Period Time (no label in the script) | timestamp('31 Dec 2030') | time | end |
| Trade Direction | |||
| Trade Direction | Long and Short | string · options ['Long and Short', 'Long Only', 'Short Only'] | entry Long entry Short line 201 line 204 |
| Take Profit | |||
| Take Profit 1 - Target % | 100 | float · min 0.0 · step 0.5 | exit TP1 |
| % Of Position | 3 | int · min 0 | exit TP1 |
| Take Profit 2 - Target % | 100 | float · min 0.0 · step 0.5 | exit TP2 |
| % Of Position | 100 | int · min 0 | exit TP2 |
| Take Profit 3 - Target % | 100 | float · min 0.0 · step 0.5 | exit TP3 |
| % Of Position | 100 | int · min 0 | exit TP3 |
| Take Profit 4 - Target % | 100 | float · min 0.0 · step 0.5 | exit TP4 |
| Stop Loss | |||
| Stop Loss (%) | 12 | float · min 0.01 | slLongClose slShortClose |
| Leverage | |||
| Leverage | 1 | float · step .5 | contracts |
| ProfitView Alert Syntax | |||
| Alert Syntax Prefix | CRYPTANEX_99FTX_Strategy-Name-Here | string | alertSyntaxBase |
| Dashboard | |||
| Show Dashboard | true | bool | line 224 |
What it calculates
- SMA / EMA / WMA / VWMA / RMA / Linregsrc, Len (14)
result · line 35 - EMAsrc, Len (14)
e · line 45 - WMAsrc, Len (14)
w · line 55 - Lowest / HighestLen (14)
kijun · line 68 - EMAsrc, Len (14)
mg · line 73 - ATR14
filter · line 84 - EMAclose, EMA UpTrend (100)
usedEma · line 101 - SMADX, Len (14)
ADX · line 133
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 74 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | longCondition and tradeDirection != 'Short Only' and isInLongPosition == false | On | 202 |
| Open Short short | shortCondition and tradeDirection != 'Long Only' and isInShortPosition == false | On | 205 |
| Exit TP1 limit | calcPeriod | On | 209 |
| Exit TP2 limit | calcPeriod | On | 210 |
| Exit TP3 limit | calcPeriod | On | 211 |
| Exit TP4 limit | calcPeriod | On | 212 |
| Close Long | slLongCloseclose < strategy.position_avg_price * (1 - stoplossPercent) | On | 213 |
| Close Short | slShortCloseclose > strategy.position_avg_price * (1 + stoplossPercent) | On | 214 |
| Close | closeLongCondition or closeShortCondition | On | 215 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | alertSyntaxBase + 'side:long' | 203 |
| (no title) | alert | alertSyntaxBase + 'side:short' | 206 |
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −47.2% | +102.5% | 4 | 0% | 0.00 | 48.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.9% | +5.5% | 1 | 0% | 0.00 | 3.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −59.9% | +9.8% | 6 | 0% | 0.00 | 60.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +32.5% | +8.4% | 3 | 67% | 3.34 | 15.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −17.8% | +16.7% | 3 | 33% | 0.30 | 26.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −8.1% | +21.5% | 4 | 25% | 0.72 | 30.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −37.1% | +148.3% | 5 | 20% | 0.06 | 39.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −12.3% | +17.1% | 1 | 0% | 0.00 | 13.8% | 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% | −$5,351.48 |
| Sideways market | 1 | 0% | −$2,243.08 |
| Falling market | 1 | 0% | −$1,834.08 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
47.1%
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, 47.1% to 47.1%; the tick is what actually happened, 47.1%. Order luck alone moves it this much.
All 4 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 Nov 2024 90,588.00 | 11 Mar 2025 78,595.90 | 114 | −$2,675.66 |
| long | 15 Jul 2025 119,841.00 | 5 Nov 2025 101,497.00 | 113 | −$2,675.81 |
| short | 5 Feb 2026 73,165.80 | 11 May 2026 82,210.10 | 95 | −$1,834.08 |
| short | 3 Jun 2026 66,760.80 | 22 Aug 2026 78,338.00 | 80 | −$2,243.08 |
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 |
|---|---|---|---|---|---|
| Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] this page | — | v5 strategy | −47.2% | 4 | 48.6% |
| Multi MA Trend Following Strategy Template by TradeAutomation | ema linreg rma sma vwma wma atr highest lowest | v5 strategy | +12.3% | 3 | 26.9% |
| Ultra Moving Average Rating Trend Strategy by exlux99 | ema wma highest lowest sma rma linreg vwma | v5 strategy | +2.8% | 5 | 2.4% |
| VCP pivot buy by perrycc007 | sma ema rma vwma wma lowest highest | v4 strategy | does not run in Zeal Terminal | ||
| MACD Willy Strategy by PtGambler | rma sma ema highest lowest wma | v5 strategy | No trades on this market | ||
| Multi Trend Cross Strategy Template by TradeAutomation | ema linreg rma sma vwma wma highest lowest | v5 strategy | +33.0% | 3 | 7.3% |
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 213, 214, 215). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 7 settings use the untyped input() (line 27, 28, 29, 30, 100, 119, 120). 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.
Same 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 27: input() → input.int()
- Line 28: input() → input.int()
- Line 29: input() → input.int()
- Line 30: input() → input.int()
- Line 100: input() → input.bool()
- Line 119: input() → input.int()
4 more edits
- Line 120: input() → input.int()
- Line 213: when = slLongClose → if block
- Line 214: when = slShortClose → if block
- Line 215: when = closeLongCondition or closeShortCondition → if block
⋯maType = input.string('EMA', 'MA Type', options=['EMA', 'DEMA', 'TEMA', 'WMA', 'VWMA', 'SMA', 'SMMA', 'HMA', 'LSMA', 'Kijun', 'McGinley', 'RMA'], group="Braid Filter")-Period1 = input(3, 'Period 1')+Period1 = input.int(3, 'Period 1')-Period2 = input(7, 'Period 2')+Period2 = input.int(7, 'Period 2')-Period3 = input(14, 'Period 3')+Period3 = input.int(14, 'Period 3')-PipsMinSepPercent = input(40)+PipsMinSepPercent = input.int(40)//-- Moving Average⋯ema1 = input.int(100, minval=1, maxval=300, title='EMA UpTrend', group="EMA Trend Bars")-shema = input(true, title='Show EMA Trend is Based On?')+shema = input.bool(true, title='Show EMA Trend is Based On?')usedEma = ta.ema(close, ema1)⋯//indicator('ADX and DI for v4')-len = input(14)+len = input.int(14)-th = input(20)+th = input.int(20)TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))⋯ 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 does not run in Zeal Terminal's engine: Pine Script v6 Error at @L217:C7: cannot use 'int' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © myn-//@version=5+//@version=6strategy('Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=20000, currency='USD', default_qty_type=strategy.percent_of_equity, default_qty_value=100.0, commission_value=0.075, use_bar_magnifier = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 139 ms | Yes 1,000 bars in 155 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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/// © myn//@version=5strategy('Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=20000, currency='USD', default_qty_type=strategy.percent_of_equity, default_qty_value=100.0, commission_value=0.075, use_bar_magnifier = true)// Trading Rules// 15 min / BTCUSD// 1) Buy Price action above moving average. (bars are green)// 2) Braid filter must issue a new green bar// 3) ADX must be above the 20 level and be pointed up, If flat or downwards, don't enter trade// 4) Stop loss at the moving average or recent swing low.// Target 1.5x the risk// Indicator changes per strategy recommendation// Keep Braid Filter default// CMA EMA TrendBars Change Uptrend to 100// ADX and DI for V4 (uncheck DI+ and DI- in style) and make ADX line thicker///////////////////////////////////////* Put your strategy logic below *///////////////////////////////////////// 3a1mQJ26TOE// Braid Filter by Robert Hill// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// Copyright © Robert Hill, 2006//@version=5//indicator('Braid Filter')//-- InputsmaType = input.string('EMA', 'MA Type', options=['EMA', 'DEMA', 'TEMA', 'WMA', 'VWMA', 'SMA', 'SMMA', 'HMA', 'LSMA', 'Kijun', 'McGinley', 'RMA'], group="Braid Filter")Period1 = input(3, 'Period 1')Period2 = input(7, 'Period 2')Period3 = input(14, 'Period 3')PipsMinSepPercent = input(40)//-- Moving Averagema(type, src, len) => float result = 0 if type == 'SMA' // Simple result := ta.sma(src, len) result if type == 'EMA' // Exponential result := ta.ema(src, len) result if type == 'DEMA' // Double Exponential e = ta.ema(src, len) result := 2 * e - ta.ema(e, len) result if type == 'TEMA' // Triple Exponential e = ta.ema(src, len) result := 3 * (e - ta.ema(e, len)) + ta.ema(ta.ema(e, len), len) result if type == 'WMA' // Weighted result := ta.wma(src, len) result if type == 'VWMA' // Volume Weighted result := ta.vwma(src, len) result if type == 'SMMA' // Smoothed w = ta.wma(src, len) result := na(w[1]) ? ta.sma(src, len) : (w[1] * (len - 1) + src) / len result if type == 'RMA' result := ta.rma(src, len) result if type == 'HMA' // Hull result := ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len))) result if type == 'LSMA' // Least Squares result := ta.linreg(src, len, 0) result if type == 'Kijun' //Kijun-sen kijun = math.avg(ta.lowest(len), ta.highest(len)) result := kijun result if type == 'McGinley' mg = 0.0 mg := na(mg[1]) ? ta.ema(src, len) : mg[1] + (src - mg[1]) / (len * math.pow(src / mg[1], 4)) result := mg result result//-- Braid Filter ma01 = ma(maType, close, Period1)ma02 = ma(maType, open, Period2)ma03 = ma(maType, close, Period3)max = math.max(math.max(ma01, ma02), ma03)min = math.min(math.min(ma01, ma02), ma03)dif = max - minfilter = ta.atr(14) * PipsMinSepPercent / 100//-- PlotsBraidColor = ma01 > ma02 and dif > filter ? color.green : ma02 > ma01 and dif > filter ? color.red : color.gray//plot(dif, 'Braid', BraidColor, 5, plot.style_columns)//plot(filter, 'Filter', color.new(color.blue, 0), 2, plot.style_line)//bgcolor(BraidColor, transp=90)//2) Braid filter must issue a new green/red barentryBbraidFilterGreenBar = BraidColor == color.greenentryBraidFilterRedBar = BraidColor == color.red// CM_EMA Trend Bars by Chris Moody// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░//@version=5//Created by ChrisMoody on 11/1/2014//Bar Color Based on Above/Below EMA...// indicator(title='CM_EMA Trend Bars', shorttitle='CM_EMA TrendBars', overlay=true)ema1 = input.int(100, minval=1, maxval=300, title='EMA UpTrend', group="EMA Trend Bars")shema = input(true, title='Show EMA Trend is Based On?')usedEma = ta.ema(close, ema1)emaUpColor() => hlc3 >= usedEmaemaDownColor() => hlc3 < usedEmacol = hlc3 >= usedEma ? color.lime : hlc3 < usedEma ? color.red : color.whiteemaDownColor_1 = emaDownColor()barcolor(emaUpColor() ? color.lime : emaDownColor_1 ? color.red : na)plot(shema and usedEma ? usedEma : na, title='EMA', style=plot.style_line, linewidth=3, color=col)// 1) Buy Price action above moving average. (bars are green)entryPriceActionAboveEMATrend = emaUpColor()entryPriceActionBelowEMATrend = emaDownColor() // ADX and DI for V4 by Trend Bars by BeikabuOyaji// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © BeikabuOyaji//@version=5//indicator('ADX and DI for v4')len = input(14)th = input(20)TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0SmoothedTrueRange = 0.0SmoothedTrueRange := nz(SmoothedTrueRange[1]) - nz(SmoothedTrueRange[1]) / len + TrueRangeSmoothedDirectionalMovementPlus = 0.0SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - nz(SmoothedDirectionalMovementPlus[1]) / len + DirectionalMovementPlusSmoothedDirectionalMovementMinus = 0.0SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - nz(SmoothedDirectionalMovementMinus[1]) / len + DirectionalMovementMinusDIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100DX = math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100ADX = ta.sma(DX, len)//plot(DIPlus, color=color.new(color.green, 0), title='DI+')//plot(DIMinus, color=color.new(color.red, 0), title='DI-')//plot(ADX, color=color.new(color.navy, 0), title='ADX')//hline(th, color=color.black)// 3) ADX must be above the 20 level and be pointed up. If flat or downwards, don't enter tradeiADXSlope = input.float(3.5, minval=0, maxval=300, title='ADX Slope', step=.5, group="ADX and DI")entryADXAboveThreshold = ADX > th and (ADX[2] + iADXSlope < ADX[1]) and (ADX[1] + iADXSlope < ADX)//entryADXAboveThreshold = ADX > th and (ADX[2] < ADX[1]) and (ADX[1] < ADX)////////////////////////////////////////* Put your strategy rules below *///////////////////////////////////////longCondition = entryPriceActionAboveEMATrend and entryBbraidFilterGreenBar and entryADXAboveThresholdshortCondition = entryPriceActionBelowEMATrend and entryBraidFilterRedBar and entryADXAboveThreshold//define as 0 if do not want to usecloseLongCondition = 0closeShortCondition = 0//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=100, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 1')q1 = input.int(title='% Of Position', defval=3, minval=0, group='Take Profit', inline='Take Profit 1')// Take profit 2// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tp2 = input.float(title='Take Profit 2 - Target %', defval=100, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 2')q2 = input.int(title='% Of Position', defval=100, minval=0, group='Take Profit', inline='Take Profit 2')// Take profit 3// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tp3 = input.float(title='Take Profit 3 - Target %', defval=100, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 3')q3 = input.int(title='% Of Position', defval=100, minval=0, group='Take Profit', inline='Take Profit 3')// Take profit 4// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░tp4 = input.float(title='Take Profit 4 - Target %', defval=100, minval=0.0, step=0.5, group='Take Profit')/// Stop Loss// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░stoplossPercent = input.float(title='Stop Loss (%)', defval=12, minval=0.01, 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// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░if calcPeriod if longCondition 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 shortCondition 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)