Pine Script v5 · Strategy
Strategy Myth-Busting #4 - LSMA+HULL Crossover - [MYN]
A Pine Script v5 strategy built on Linreg (close, 25), Change (high) and RMA (ta.tr, len). 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 1.0% of equity and pays 0.075 commission. 34 settings; defaults include Length 25, Offset 0 and Source close.
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 #4 - LSMA+HULL Crossover - [MYN] repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Strategy Myth-Busting #4 - LSMA+HULL Crossover - [MYN] do on BTCUSDT 1D with default settings?
- +22.21%
- From 26 Jan 2024 to 21 Oct 2026, over 13 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does Strategy Myth-Busting #4 - LSMA+HULL Crossover - [MYN] have?
- 4
- Hull trending up.; Hull trending down.; alertSyntaxBase + 'side:long'; alertSyntaxBase + 'side:short'.
- Does Strategy Myth-Busting #4 - LSMA+HULL Crossover - [MYN] run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L75:C76: 'plot' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
- Does Strategy Myth-Busting #4 - LSMA+HULL Crossover - [MYN] use a stop loss?
- No
- Its exits set a profit target but no stop.
BTCUSDT · 1D · default settings
- Plot
- MHULL
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Start: long1712793600000 |
| End: long1785283200000 |
| Net Profit: 22.21% |
| Percent Per Day 0.02647% |
| Percent Profitable: 76.92% |
| Profit Factor: 1.352 |
| Total Trades: 13 |
| Max Wins In A Row: 4 |
| Max Losses In A Row: 1 |
- Net profit
- +22.21%
- $222.07
- Buy and hold
- +102.5%
- same period
- Closed trades
- 13
- 10 won · 3 lost
- Profitable
- 76.9%
- of closed trades
- Profit factor
- 1.35
- gross profit ÷ gross loss
- Max drawdown
- 74.58%
- −$846.52
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A short 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.
-
Note
2 settings have no label
In the settings dialog startPeriodTime (line 124), endPeriodTime (line 126) 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 186, 187, 188. 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 |
|---|---|---|---|
| LSMA | |||
| Length | 25 | int | lsma |
| Offset | 0 | int | lsma |
| Source | close | source | lsma |
| Hull Variation | Hma | string · options ['Hma', 'Thma', 'Ehma'] | _hull line 65 |
| Length(180-200 for floating S/R , 55 for swing entry) | 55 | int | _hull |
| Length multiplier (Used to view higher timeframes with straight band) | 1.0 | float | _hull |
| Show Hull MA from X timeframe? (good for scalping) | false | bool | HULL |
| Higher timeframe | 240 | timeframe | HULL |
| Color Hull according to trend? | true | bool | hullColor barcolor |
| Color candles based on Hull\'s Trend? | false | bool | barcolor |
| Show as a Band? | false | bool | SHULL |
| Line Thickness | 4 | int | MHULL SHULL |
| Band Transparency | 40 | int · step 5 | Band Filler |
| Hull Suite | |||
| Source | close | source | _hull enterLong enterShort line 65 |
| ADX | |||
| Average Directional Index (ADX) | false | bool | adxsig isADXEnabledAndAboveThreshold |
| ADX Smoothing | 14 | int | adx adxsig |
| DI Length | 14 | int | adxplus adxminus adxsig |
| ADX Threshold | 25 | int | isADXEnabledAndAboveThreshold |
| 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 174 line 177 |
| Take Profit | |||
| Take Profit 1 - Target % | 100 | float · min 0.0 · step 0.5 | exit TP1 |
| % Of Position | 100 | 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 (%) | 999 | 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 197 |
What it calculates
- LinregSource (close), Length (25), Offset (0)
lsma · line 34 - Changehigh
adxup · line 107 - Changelow
adxdown · line 108 - RMAta.tr, len
adxtruerange · line 111 - RMAmath.abs(adxplus - adxminus) / (adxsum == 0 ? 1 : adxsum), ADX Smoothing (14)
adx · line 118
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 71 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 | longConditionCalc and tradeDirection != 'Short Only' and isInLongPosition == false | On | 175 |
| Open Short short | shortConditionCalc and tradeDirection != 'Long Only' and isInShortPosition == false | On | 178 |
| Exit TP1 limit | calcPeriod | On | 182 |
| Exit TP2 limit | calcPeriod | On | 183 |
| Exit TP3 limit | calcPeriod | On | 184 |
| Exit TP4 limit | calcPeriod | On | 185 |
| Close Long | slLongCloseclose < strategy.position_avg_price * (1 - stoplossPercent) | On | 186 |
| Close Short | slShortCloseclose > strategy.position_avg_price * (1 + stoplossPercent) | On | 187 |
| Close | closeLongCondition or closeShortCondition | On | 188 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Hull trending up. | alertcondition | Hull trending up. | 77 |
| Hull trending down. | alertcondition | Hull trending down. | 78 |
| (no title) | alert | alertSyntaxBase + 'side:long' | 176 |
| (no title) | alert | alertSyntaxBase + 'side:short' | 179 |
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationuses varip; reads realtime-only state. 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 | +22.2% | +102.5% | 13 | 77% | 1.35 | 74.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +15.6% | +5.5% | 16 | 50% | 1.62 | 23.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −70.2% | +9.8% | 11 | 55% | 0.26 | 95.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −13.8% | +8.4% | 16 | 50% | 0.70 | 35.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −53.3% | +16.7% | 17 | 47% | 0.56 | 81.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −29.5% | +21.5% | 14 | 29% | 0.47 | 37.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +50.2% | +148.3% | 16 | 56% | 2.48 | 79.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +71.5% | +17.1% | 16 | 81% | 6.03 | 10.9% | 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 | 4 | 75% | $125.59 |
| Sideways market | 6 | 67% | −$216.80 |
| Falling market | 3 | 100% | $314.20 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
47.2%
The 95th percentile of the worst drawdown when the same 13 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 31.8% to 47.2%; the tick is what actually happened, 31.8%. Order luck alone moves it this much.
All 13 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 11 Apr 2024 70,631.10 | 8 Jun 2024 69,355.60 | 58 | −$19.54 |
| short | 8 Jun 2024 69,355.60 | 15 Jul 2024 60,797.90 | 37 | $119.69 |
| long | 15 Jul 2024 60,797.90 | 7 Oct 2024 62,819.90 | 84 | $34.93 |
| short | 7 Oct 2024 62,819.90 | 19 Mar 2025 82,715.00 | 163 | −$361.72 |
| long | 19 Mar 2025 82,715.00 | 29 May 2025 107,782.00 | 71 | $233.37 |
| short | 29 May 2025 107,782.00 | 27 Jun 2025 106,947.00 | 29 | $6.30 |
| long | 27 Jun 2025 106,947.00 | 30 Jul 2025 117,951.00 | 33 | $102.71 |
| short | 30 Jul 2025 117,951.00 | 11 Sep 2025 113,960.00 | 43 | $36.13 |
| long | 11 Sep 2025 113,960.00 | 23 Jan 2026 89,559.70 | 134 | −$248.34 |
| short | 23 Jan 2026 89,559.70 | 22 Feb 2026 67,975.90 | 30 | $216.72 |
| long | 22 Feb 2026 67,975.90 | 27 Mar 2026 68,820.30 | 33 | $12.23 |
| short | 27 Mar 2026 68,820.30 | 20 Jun 2026 63,543.90 | 85 | $85.25 |
| long | 20 Jun 2026 63,543.90 | 29 Jul 2026 63,915.00 | 39 | $5.28 |
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 #4 - LSMA+HULL Crossover - [MYN] this page | — | v5 strategy | +22.2% | 13 | 74.6% |
| Strategy Myth-Busting #9 - HullSuite+LSMA - [MYN] by myncrypto | linreg rma | v5 strategy | −38.3% | 13 | 72.6% |
| 3 Candle Strike Stretegy by PtGambler | rma linreg | v5 strategy | No trades on this market | ||
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 186, 187, 188). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 14 settings use the untyped input() (line 31, 32, 33, 42, 44, 45, 46, 48, 49, 50, 51, 103, 104, 105). 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 13 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 31: input() → input.int()
- Line 32: input() → input.int()
- Line 33: input() → input.source()
- Line 42: input() → input.source()
- Line 44: input() → input.int()
- Line 45: input() → input.float()
11 more edits
- Line 46: input() → input.bool()
- Line 48: input() → input.bool()
- Line 49: input() → input.bool()
- Line 50: input() → input.bool()
- Line 51: input() → input.int()
- Line 103: input() → input.int()
- Line 104: input() → input.int()
- Line 105: input() → input.int()
- Line 186: when = slLongClose → if block
- Line 187: when = slShortClose → if block
- Line 188: when = closeLongCondition or closeShortCondition → if block
⋯//indicator(title = "Least Squares Moving Average", shorttitle="LSMA", overlay=true, timeframe="", timeframe_gaps=true)-length = input(title="Length", defval=25, group="LSMA")+length = input.int(title="Length", defval=25, group="LSMA")-offset = input(title="Offset", defval=0)+offset = input.int(title="Offset", defval=0)-src = input(close, title="Source")+src = input.source(close, title="Source")lsma = ta.linreg(src, length, offset)⋯//INPUT-srcHull = input(close, title='Source', group="Hull Suite")+srcHull = input.source(close, title='Source', group="Hull Suite")modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'])-lengthHull = input(55, title='Length(180-200 for floating S/R , 55 for swing entry)')+lengthHull = input.int(55, title='Length(180-200 for floating S/R , 55 for swing entry)')-lengthMult = input(1.0, title='Length multiplier (Used to view higher timeframes with straight band)')+lengthMult = input.float(1.0, title='Length multiplier (Used to view higher timeframes with straight band)')-useHtf = input(false, title='Show Hull MA from X timeframe? (good for scalping)')+useHtf = input.bool(false, title='Show Hull MA from X timeframe? (good for scalping)')htf = input.timeframe('240', title='Higher timeframe')-switchColor = input(true, 'Color Hull according to trend?')+switchColor = input.bool(true, 'Color Hull according to trend?')-candleCol = input(false, title='Color candles based on Hull\'s Trend?')+candleCol = input.bool(false, title='Color candles based on Hull\'s Trend?')-visualSwitch = input(false, title='Show as a Band?')+visualSwitch = input.bool(false, title='Show as a Band?')-thicknesSwitch = input(4, title='Line Thickness')+thicknesSwitch = input.int(4, title='Line Thickness')transpSwitch = input.int(40, title='Band Transparency', step=5)⋯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(25, title="ADX Threshold", group="ADX")+adxabove = input.int(25, 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 does not run in Zeal Terminal's engine: Pine Script v6 Error at @L75:C76: 'plot' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. 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 #4 - LSMA+HULL Crossover - [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=1000, currency='USD', default_qty_type=strategy.percent_of_equity, default_qty_value=1.0, commission_value=0.075, use_bar_magnifier = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 151 ms | Yes 1,000 bars in 159 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 #4 - LSMA+HULL Crossover - [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=1000, currency='USD', default_qty_type=strategy.percent_of_equity, default_qty_value=1.0, commission_value=0.075, use_bar_magnifier = true)///Derek-Multiple-Take-Profit-Strategy-Template-v5-2022-04-03.pine// 04-03-2022 Added ADX // 08-17-2022 Added Dashboardf_security(_symbol, _res, _src, _repaint) => request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]///////////////////////////////////////* Put your strategy logic below */////////////////////////////////////////LSMA - Thicken Line and change to white//Hull Suite by InSilico / Disable show as band. Make line bolder//Trading Rules// Enter Long// LSMA cross above Red Hull Suite line// Price has to be above Hull Suite Line// 1:5 Risk Ratio.// Stop Loss is recent swing low// Take Profit is 5x the risk// Enter Short// LSMA crosses under green Hull Suite Line// Price has to be below Hull Suite Line// 1:5 Risk Ratio.// Stop Loss is recent swing high// Take Profit is 5x The risk// Least Squares Moving Average//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░//@version=5//indicator(title = "Least Squares Moving Average", shorttitle="LSMA", overlay=true, timeframe="", timeframe_gaps=true)length = input(title="Length", defval=25, group="LSMA")offset = input(title="Offset", defval=0)src = input(close, title="Source")lsma = ta.linreg(src, length, offset)plot(lsma, color=color.white, linewidth=4)// Hull Suite by InSilico//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░//@version=5//Basic Hull Ma Pack tinkered by InSilico //indicator('Hull Suite by InSilico', overlay=true)//INPUTsrcHull = input(close, title='Source', group="Hull Suite")modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'])lengthHull = input(55, title='Length(180-200 for floating S/R , 55 for swing entry)')lengthMult = input(1.0, title='Length multiplier (Used to view higher timeframes with straight band)')useHtf = input(false, title='Show Hull MA from X timeframe? (good for scalping)')htf = input.timeframe('240', title='Higher timeframe')switchColor = input(true, 'Color Hull according to trend?')candleCol = input(false, title='Color candles based on Hull\'s Trend?')visualSwitch = input(false, title='Show as a Band?')thicknesSwitch = input(4, title='Line Thickness')transpSwitch = input.int(40, title='Band Transparency', step=5)//FUNCTIONS//HMAHMA(_src, _length) => ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length)))//EHMA EHMA(_src, _length) => ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length)))//THMA THMA(_src, _length) => ta.wma(ta.wma(_src, _length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)//SWITCHMode(modeSwitch, srcHull, len) => modeSwitch == 'Hma' ? HMA(srcHull, len) : modeSwitch == 'Ehma' ? EHMA(srcHull, len) : modeSwitch == 'Thma' ? THMA(srcHull, len / 2) : na//OUT_hull = Mode(modeSwitch, srcHull, int(lengthHull * lengthMult))HULL = useHtf ? f_security(syminfo.ticker, htf, _hull,false) : _hullMHULL = HULL[0]SHULL = HULL[2]//COLORhullColor = switchColor ? HULL > HULL[2] ? #00ff00 : #ff0000 : #ff9800//PLOT///< FrameFi1 = plot(MHULL, title='MHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)alertcondition(ta.crossover(MHULL, SHULL), title='Hull trending up.', message='Hull trending up.')alertcondition(ta.crossover(SHULL, MHULL), title='Hull trending down.', message='Hull trending down.')///< Ending Fillerfill(Fi1, Fi2, title='Band Filler', color=hullColor, transp=transpSwitch)///BARCOLORbarcolor(color=candleCol ? switchColor ? hullColor : na : na)////////////////////////////////////////* Put your strategy rules below */////////////////////////////////////////o0wqgXG6jgI /// Enter Long// LSMA cross above Red Hull Suite line// Price has to be above Hull Suite LineenterLong = ta.crossover(lsma, HULL) and hullColor == #ff0000 and srcHull > HULL// Enter Short// LSMA crosses under green Hull Suite Line// Price has to be below Hull Suite LineenterShort = ta.crossunder(lsma,HULL) and hullColor == #00ff00 and srcHull < HULLlongCondition = enterLongshortCondition = enterShort//define as 0 if do not want to usecloseLongCondition = 0closeShortCondition = 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(25, 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) : naisADXEnabledAndAboveThreshold = 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=100, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 1')q1 = input.int(title='% Of Position', defval=100, 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=999, 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// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░longConditionCalc = (longCondition and isADXEnabledAndAboveThreshold)shortConditionCalc = (shortCondition and isADXEnabledAndAboveThreshold)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)