Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Strategy Backtesting Template [MYN]

A Pine Script v5 strategy built on RSI (close, 10), Crossover (rsiEntry, 80) and Crossunder (rsiEntry, 20). It has 10 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. 30 settings; defaults include EMA Length 200, EMA Source close and ADX Variant ORIGINAL.

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

BTCUSDT · 1D · default settings

  • 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 (30)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$16,350$40,505Equity from $20,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Table drawn by the script, as it stood on the last bar
JanFebMarAprMayJunJulAugSepOctNovDecYear
202429.6214.26-12.915.73-14.83-311.57-9.54-15.89-5.8-3.72-1.13
20258.3-16.544.27-10.83-8.431.439.56-4.474.41-7.59-27.58-1.62-45.16
202612.4210.73-2.4-8.074.9612.95-2.66.348-2.1848.32
Net profit
−33.10%
−$6,620.34
Buy and hold
+102.5%
same period
Closed trades
6
3 won · 3 lost
Profitable
50.0%
of closed trades
Profit factor
0.56
gross profit ÷ gross loss
Max drawdown
62.44%
−$15,953.40

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

    2 settings have no label

    In the settings dialog i_startPeriodTime (line 60), i_endPeriodTime (line 62) 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 133, 134, 136, 137. 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 Filter
Enable EMA FilterEnable if you would like to conditionally have entries incorporate EMA as a filter where source is above/below the EMA linefalseboolemaValue isEMAFilterEnabledAndCloseAboveMA isEMAFilterEnabledAndCloseBelowMA
EMA Length200int · min 1emaValue
EMA SourceclosesourceemaValue isEMAFilterEnabledAndCloseAboveMA isEMAFilterEnabledAndCloseBelowMA
ADX Filter
Enable ADX FilterEnable if you would like to conditionally have entries incorporate ADX as a filterfalsebooladx isADXFilterEnabledAndAboveThreshold
ADX VariantORIGINALstring · options ['ORIGINAL', 'MASANAKAMURA']adx
ADX Smoothing14intDIPlusO DIMinusO ADXO
DI Length14intDIPlusO DIMinusO ADXO DIPlusM DIMinusM ADXM
ADX Threshold25float · step .5isADXFilterEnabledAndAboveThreshold
Date Range
StarttrueboolisStartPeriodEnabledAndInRange
I start Period Time (no label in the script)timestamp('1 Jan 2019')timeisStartPeriodEnabledAndInRange
EndtrueboolisEndPeriodEnabledAndInRange
I end Period Time (no label in the script)timestamp('31 Dec 2030')timeisEndPeriodEnabledAndInRange
Time Window
Enable Time-Of-Day WindowLimit the time of day for trade executionfalseboolisTimeFilterEnabledAndInRange
Select Local Time ZoneGMT-5string · options ["GMT-8","GMT-7", "GMT-6", "GMT-5", "GMT-4", "GMT-3", "GMT-2", "GMT-1", "GMT", "GMT+1", "GMT+2", "GMT+3","GMT+4","GMT+5","GMT+6","GMT+7","GMT+8","GMT+9","GMT+10","GMT+11","GMT+12","GMT+13"]currentTimeIsWithinWindowOfTime
Time Filter0700-0900sessionisTimeFilterEnabledAndInRange
Trade Direction
Trade DirectionLong and Shortstring · options ['Long and Short', 'Long Only', 'Short Only']entry Long entry Short line 120 line 123
Take Profit
Take Profit 1 - Target %100float · min 0.0 · step 0.5exit TP1
% Of Position100int · min 0exit TP1
Take Profit 2 - Target %100float · min 0.0 · step 0.5exit TP2
% Of Position100int · min 0exit TP2
Take Profit 3 - Target %100float · min 0.0 · step 0.5exit TP3
% Of Position100int · min 0exit TP3
Take Profit 4 - Target %100float · min 0.0 · step 0.5exit i_takeProfitTargetPercent4
Stop Loss
Stop Loss (%)999float · min 0.01 · step 0.5slLongClose slShortClose
Leverage
Leverage1float · step .5contracts
% of Equity to Stake Per Trade100float · min 0.01 · max 100 · step 5contracts
ProfitView Alert Syntax
Alert Syntax PrefixCRYPTANEX_99FTX_Strategy-Name-HerestringalertSyntaxBase
Dashboards
Dashboard SizeSmallstring · options ["Auto", "Huge", "Large", "Normal", "Small", "Tiny"]tableTextSize
Performance Summarytrueboolline 159
Monthly Performancetrueboolline 202

What it calculates

  • RSIclose, 10rsiEntry · line 9
  • RSIclose, 100rsiExit · line 10
  • CrossoverrsiEntry, 80longConditionEntry · line 11
  • CrossunderrsiEntry, 20shortConditionEntry · line 12
  • CrossunderrsiExit, 40longConditionExit · line 13
  • CrossoverrsiExit, 60shortConditionExit · line 14
  • EMAEMA Source (close), EMA Length (200)emaValue · line 28
  • DMIDI Length (14), ADX Smoothing (14)DIPlusO · line 53
  • DMIDI Length (14), ADX Smoothing (14)DIMinusO · line 53
  • DMIDI Length (14), ADX Smoothing (14)ADXO · line 53

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 82 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 i_tradeDirection != 'Short Only' and isInLongPosition == falseOn121
Open Short shortshortConditionCalc and i_tradeDirection != 'Long Only' and isInShortPosition == falseOn124
Exit TP1 limitisStartEndPeriodsAndTimeInRangeOn128
Exit TP2 limitisStartEndPeriodsAndTimeInRangeOn129
Exit TP3 limitisStartEndPeriodsAndTimeInRangeOn130
Exit i_takeProfitTargetPercent4 limitisStartEndPeriodsAndTimeInRangeOn131
Close LongslLongCloseclose < strategy.position_avg_price * (1 - i_stopLossPercent)On133
Close ShortslShortCloseclose > strategy.position_avg_price * (1 + i_stopLossPercent)On134
Close LongcloseLongConditionOn136
Close ShortcloseShortConditionOn137

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'122
(no title)alertalertSyntaxBase + 'side:short'125

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−33.1%+102.5%650%0.5662.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+24.6%+5.5%367%3.2112.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−80.0%+9.8%743%0.2683.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+7.5%+8.4%540%1.2028.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−56.0%+16.7%520%0.6478.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+15.9%+21.5%333%1.6934.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+48.1%+148.3%560%1.2671.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+11.7%+17.1%367%2.2014.7%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 market1100%$795.39
Sideways market425%−$9,489.52
Falling market1100%$2,083.84

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

How bad could the drawdown be?

57.7%

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

0%66%
All 6 trades
SideEntryExitBarsP&L
long10 Feb 2024 47,132.8025 Jun 2024 60,293.30136$5,550.26
short25 Jun 2024 60,293.3011 Nov 2024 80,370.00139−$8,558.96
long11 Nov 2024 80,370.0027 Feb 2025 84,250.10108$795.39
short27 Feb 2025 84,250.109 May 2025 103,262.0071−$4,046.40
long9 May 2025 103,262.0022 Nov 2025 85,129.40197−$2,434.42
short22 Nov 2025 85,129.4020 Aug 2026 69,334.80271$2,083.84

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 Backtesting Template [MYN] this page—v5 strategy−33.1%662.4%
RSI Cross [xaurr] by livetrendrsi emav4 strategy+24.4%5335.3%
Bitpanda Coinrule Template by joshuajcoop01rsi emav5 strategy−2.8%44.6%
RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrulersi emav5 strategy−2.8%44.6%
RSI of VWAP by mohaneersi emav4 strategyNo trades on this market
EMA SCALPEUR + RSi - SHORT by YukalMoonrsi emav5 strategyNo 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.

  • 4 strategy calls use the when = argument (line 133, 134, 136, 137). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 133: when = slLongClose → if block
  • Line 134: when = slShortClose → if block
  • Line 136: when = closeLongCondition → if block
  • Line 137: when = closeShortCondition → if block
⋯    // Stop Loss-    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')    // Conditional Closes-    strategy.close('Long', qty_percent=100, comment='Close Long', when=closeLongCondition)+    if closeLongCondition+        strategy.close('Long', qty_percent=100, comment='Close Long')-    strategy.close('Short', qty_percent=100, comment='Close Short', when=closeShortCondition)+    if closeShortCondition+        strategy.close('Short', qty_percent=100, comment='Close Short')// Global Dashboard Variables⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 6 before, 8 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.

⋯// © myn-//@version=5+//@version=6strategy('Strategy Backtesting Template [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=20000, currency='NONE', default_qty_type=strategy.percent_of_equity, default_qty_value=100.0, commission_value=0.075, use_bar_magnifier = false)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 177 msWith a workaround 1,000 bars in 174 msNot measured
PineTSNot testedNot testedNot measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

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 Backtesting Template [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=20000, currency='NONE', default_qty_type=strategy.percent_of_equity, default_qty_value=100.0, commission_value=0.075, use_bar_magnifier = false)///////////////////////////////////////* Put your strategy logic below *///////////////////////////////////////// Below is a very simple example to demonstrate the trading templatersiEntry = ta.rsi(close, 10)rsiExit = ta.rsi(close,100)longConditionEntry = ta.crossover(rsiEntry, 80)shortConditionEntry = ta.crossunder(rsiEntry, 20) longConditionExit = ta.crossunder(rsiExit,40) shortConditionExit = ta.crossover(rsiExit, 60)////////////////////////////////////////* Put your strategy rules below *///////////////////////////////////////longCondition =  longConditionEntry         // default: falseshortCondition = shortConditionEntry         // default: false//define as 0 if do not want to have a conditional closecloseLongCondition = longConditionExit      // default: 0closeShortCondition = shortConditionExit    // default: 0// EMA Filter//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_emaFilterEnabled = input.bool(defval = false , title = "Enable EMA Filter", tooltip = "Enable if you would like to conditionally have entries incorporate EMA as a filter where source is above/below the EMA line", group ="EMA Filter" ) i_emaLength = input.int(200, title="EMA Length", minval=1, group ="EMA Filter")i_emaSource = input.source(close,"EMA Source" , group ="EMA Filter")emaValue = i_emaFilterEnabled ? ta.ema(i_emaSource, i_emaLength) : nabool isEMAFilterEnabledAndCloseAboveMA = i_emaFilterEnabled ? i_emaSource > emaValue : truebool isEMAFilterEnabledAndCloseBelowMA = i_emaFilterEnabled ? i_emaSource < emaValue : true// ADX Filter//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_adxFilterEnabled = input.bool(defval = false , title = "Enable ADX Filter", tooltip = "Enable if you would like to conditionally have entries incorporate ADX as a filter", group ="ADX Filter" ) i_adxVariant = input.string('ORIGINAL', title='ADX Variant', options=['ORIGINAL', 'MASANAKAMURA'], group ="ADX Filter" )i_adxSmoothing = input.int(14, title="ADX Smoothing", group="ADX Filter")i_adxDILength = input.int(14, title="DI Length", group="ADX Filter")i_adxLowerThreshold = input.float(25, title="ADX Threshold", step=.5, group="ADX Filter")calcADX_Masanakamura(int _len) =>    _smoothedTrueRange = 0.0    _smoothedDirectionalMovementPlus = 0.0    _smoothed_directionalMovementMinus = 0.0    _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) : 0    _directionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0    _smoothedTrueRange := nz(_smoothedTrueRange[1]) - nz(_smoothedTrueRange[1]) / _len + _trueRange    _smoothedDirectionalMovementPlus := nz(_smoothedDirectionalMovementPlus[1]) - nz(_smoothedDirectionalMovementPlus[1]) / _len + _directionalMovementPlus    _smoothed_directionalMovementMinus := nz(_smoothed_directionalMovementMinus[1]) - nz(_smoothed_directionalMovementMinus[1]) / _len + _directionalMovementMinus    DIP = _smoothedDirectionalMovementPlus / _smoothedTrueRange * 100    DIM = _smoothed_directionalMovementMinus / _smoothedTrueRange * 100    _DX = math.abs(DIP - DIM) / (DIP + DIM) * 100    adx = ta.sma(_DX, _len)    [DIP, DIM, adx][DIPlusO, DIMinusO, ADXO] = ta.dmi(i_adxDILength, i_adxSmoothing)[DIPlusM, DIMinusM, ADXM] = calcADX_Masanakamura(i_adxDILength)adx = i_adxFilterEnabled and i_adxVariant == "ORIGINAL" ? ADXO : ADXMbool isADXFilterEnabledAndAboveThreshold = i_adxFilterEnabled ? adx > i_adxLowerThreshold : true///Start / End Time Periods//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_startPeriodEnabled = input.bool(true, 'Start', group='Date Range', inline='Start Period')i_startPeriodTime = input.time(timestamp('1 Jan 2019'), '', group='Date Range', inline='Start Period')i_endPeriodEnabled = input.bool(true, 'End', group='Date Range', inline='End Period')i_endPeriodTime = input.time(timestamp('31 Dec 2030'), '', group='Date Range', inline='End Period')isStartPeriodEnabledAndInRange = i_startPeriodEnabled ? i_startPeriodTime <= time : trueisEndPeriodEnabledAndInRange = i_endPeriodEnabled ? i_endPeriodTime >= time : true// Time-Of-Day Window// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// Inspired from https://www.tradingview.com/script/3BmID7aW-Highlight-Trading-Window-Simple-Hours-Time-of-Day-Filter/i_timeFilterEnabled = input.bool(defval = false , title = "Enable Time-Of-Day Window", tooltip = "Limit the time of day for trade execution", group ="Time Window" ) i_timeZone = input.string(title="Select Local Time Zone", defval="GMT-5", options=["GMT-8","GMT-7", "GMT-6", "GMT-5", "GMT-4", "GMT-3", "GMT-2", "GMT-1", "GMT", "GMT+1", "GMT+2",  "GMT+3","GMT+4","GMT+5","GMT+6","GMT+7","GMT+8","GMT+9","GMT+10","GMT+11","GMT+12","GMT+13"], group="Time Window")i_betweenTime = input.session('0700-0900',  title = "Time Filter", group="Time Window")   // '0000-0000' is anytime to enterisWithinWindowOfTime(_position) =>                                                          currentTimeIsWithinWindowOfTime = not na(time(timeframe.period, _position + ':1234567', i_timeZone))bool isTimeFilterEnabledAndInRange = i_timeFilterEnabled ? isWithinWindowOfTime(i_betweenTime) : trueisStartEndPeriodsAndTimeInRange = isStartPeriodEnabledAndInRange and isEndPeriodEnabledAndInRange and isTimeFilterEnabledAndInRange// Trade Direction // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_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// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_takeProfitTargetPercent1 = input.float(title='Take Profit 1 - Target %', defval=100, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 1')i_takeProfitQuantityPercent1 = input.int(title='% Of Position', defval=100, minval=0, group='Take Profit', inline='Take Profit 1')// Take profit 2// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_takeProfitTargetPercent2 = input.float(title='Take Profit 2 - Target %', defval=100, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 2')i_takeProfitQuantityPercent2 = input.int(title='% Of Position', defval=100, minval=0, group='Take Profit', inline='Take Profit 2')// Take profit 3// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_takeProfitTargetPercent3 = input.float(title='Take Profit 3 - Target %', defval=100, minval=0.0, step=0.5, group='Take Profit', inline='Take Profit 3')i_takeProfitQuantityPercent3 = input.int(title='% Of Position', defval=100, minval=0, group='Take Profit', inline='Take Profit 3')// Take profit 4// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_takeProfitTargetPercent4 = input.float(title='Take Profit 4 - Target %', defval=100, minval=0.0, step=0.5, group='Take Profit')/// Stop Loss// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_stopLossPercent = input.float(title='Stop Loss (%)', defval=999, minval=0.01, step=0.5, group='Stop Loss') * 0.01slLongClose = close < strategy.position_avg_price * (1 - i_stopLossPercent)slShortClose = close > strategy.position_avg_price * (1 + i_stopLossPercent)/// Leverage// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_leverage = input.float(1, 'Leverage', step=.5, group='Leverage')i_percentOfEquityToTrade = input.float(100, "% of Equity to Stake Per Trade", minval=0.01, maxval=100, step=5, group='Leverage') * .01contracts = (i_percentOfEquityToTrade * strategy.equity / close * i_leverage)/// Trade State Management// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░isInLongPosition = strategy.position_size > 0isInShortPosition = strategy.position_size < 0/// ProfitView Alert Syntax String Generation// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_alertSyntaxPrefix = input.string(defval='CRYPTANEX_99FTX_Strategy-Name-Here', title='Alert Syntax Prefix', group='ProfitView Alert Syntax')alertSyntaxBase = i_alertSyntaxPrefix + '\n#' + str.tostring(open) + ',' + str.tostring(high) + ',' + str.tostring(low) + ',' + str.tostring(close) + ',' + str.tostring(volume) + ','/// Trade Execution// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░longConditionCalc = (longCondition and isADXFilterEnabledAndAboveThreshold and isEMAFilterEnabledAndCloseAboveMA)shortConditionCalc = (shortCondition and isADXFilterEnabledAndAboveThreshold and isEMAFilterEnabledAndCloseBelowMA)if isStartEndPeriodsAndTimeInRange    if longConditionCalc and i_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 i_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=i_takeProfitQuantityPercent1, profit=per(i_takeProfitTargetPercent1))    strategy.exit('TP2', qty_percent=i_takeProfitQuantityPercent2, profit=per(i_takeProfitTargetPercent2))    strategy.exit('TP3', qty_percent=i_takeProfitQuantityPercent3, profit=per(i_takeProfitTargetPercent3))    strategy.exit('i_takeProfitTargetPercent4', profit=per(i_takeProfitTargetPercent4))    // Stop Loss    strategy.close('Long', qty_percent=100, comment='SL Long', when=slLongClose)    strategy.close('Short', qty_percent=100, comment='SL Short', when=slShortClose)    // Conditional Closes    strategy.close('Long', qty_percent=100, comment='Close Long', when=closeLongCondition)    strategy.close('Short', qty_percent=100, comment='Close Short', when=closeShortCondition)// Global Dashboard Variables// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// Dashboard Table Text Sizei_tableTextSize = input.string(title="Dashboard Size", defval="Small", options=["Auto",  "Huge",  "Large", "Normal", "Small", "Tiny"], group="Dashboards")table_text_size(s) =>    switch s        "Auto"   => size.auto           "Huge"   => size.huge           "Large"  => size.large          "Normal" => size.normal         "Small"  => size.small        => size.tinytableTextSize = table_text_size(i_tableTextSize)/// Performance Summary Dashboard// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// Inspired by https://www.tradingview.com/script/uWqKX6A2/ - Thanks VertMTi_showDashboard = input.bool(title="Performance Summary", defval=true, group="Dashboards", inline="Show Dashboards")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=tableTextSize)// Draw dashboard tableif i_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.top_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.teal : color.maroon, 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.teal : color.maroon, color.white)        _winRate = ( strategy.wintrades / strategy.closedtrades ) * 100        f_fillCell(dashTable, 0, 4, "Percent Profitable:", str.tostring(_winRate, '##.##') + "%", _winRate < 50 ? color.maroon : _winRate < 75 ? #999900 : color.teal, color.white)        f_fillCell(dashTable, 0, 5, "Profit Factor:", str.tostring(strategy.grossprofit / strategy.grossloss,  '##.###'), strategy.grossprofit > strategy.grossloss ? color.teal : color.maroon, 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)// Monthly Table Performance Dashboard By @QuantNomad// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_showMonthlyPerformance = input.bool(true, 'Monthly Performance', group='Dashboards', inline="Show Dashboards")i_monthlyReturnPercision = 2if i_showMonthlyPerformance    new_month = month(time) != month(time[1])    new_year  = year(time)  != year(time[1])        eq = strategy.equity        bar_pnl = eq / eq[1] - 1        cur_month_pnl = 0.0    cur_year_pnl  = 0.0        // Current Monthly P&L    cur_month_pnl := new_month ? 0.0 :                      (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1         // Current Yearly P&L    cur_year_pnl := new_year ? 0.0 :                      (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1          // Arrays to store Yearly and Monthly P&Ls    var month_pnl  = array.new_float(0)    var month_time = array.new_int(0)        var year_pnl  = array.new_float(0)    var year_time = array.new_int(0)        last_computed = false        if (not na(cur_month_pnl[1]) and (new_month or barstate.islastconfirmedhistory))        if (last_computed[1])            array.pop(month_pnl)            array.pop(month_time)                    array.push(month_pnl , cur_month_pnl[1])        array.push(month_time, time[1])        if (not na(cur_year_pnl[1]) and (new_year or barstate.islastconfirmedhistory))        if (last_computed[1])            array.pop(year_pnl)            array.pop(year_time)                    array.push(year_pnl , cur_year_pnl[1])        array.push(year_time, time[1])        last_computed := barstate.islastconfirmedhistory ? true : nz(last_computed[1])        // Monthly P&L Table        var monthly_table = table(na)        if (barstate.islastconfirmedhistory)        monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, border_width = 1)            table.cell(monthly_table, 0,  0, "",     bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 1,  0, "Jan",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 2,  0, "Feb",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 3,  0, "Mar",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 4,  0, "Apr",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 5,  0, "May",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 6,  0, "Jun",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 7,  0, "Jul",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 8,  0, "Aug",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 9,  0, "Sep",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 10, 0, "Oct",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 11, 0, "Nov",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 12, 0, "Dec",  bgcolor = #cccccc, text_size=tableTextSize)        table.cell(monthly_table, 13, 0, "Year", bgcolor = #999999, text_size=tableTextSize)            for yi = 0 to array.size(year_pnl) - 1            table.cell(monthly_table, 0,  yi + 1, str.tostring(year(array.get(year_time, yi))), bgcolor = #cccccc, text_size=tableTextSize)                        y_color = array.get(year_pnl, yi) > 0 ? color.new(color.teal, transp = 40) : color.new(color.gray, transp = 40)            table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100, i_monthlyReturnPercision)), bgcolor = y_color, text_color=color.new(color.white, 0),text_size=tableTextSize)                    for mi = 0 to array.size(month_time) - 1            m_row   = year(array.get(month_time, mi))  - year(array.get(year_time, 0)) + 1            m_col   = month(array.get(month_time, mi))             m_color = array.get(month_pnl, mi) > 0 ? color.new(color.teal, transp = 40) : color.new(color.maroon, transp = 40)                        table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100, i_monthlyReturnPercision)), bgcolor = m_color, text_color=color.new(color.white, 0), text_size=tableTextSize)