Pine Script v5 · Strategy
Strategy Myth-Busting #23 - 2xEMA+DPO- [MYN]
A Pine Script v5 strategy built on EMA (close, 40), Crossover and Crossunder. It has 12 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. 50 settings; defaults include Length 40, Source close and Offset 0.
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 #23 - 2xEMA+DPO- [MYN] repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Strategy Myth-Busting #23 - 2xEMA+DPO- [MYN] do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- What alerts does Strategy Myth-Busting #23 - 2xEMA+DPO- [MYN] have?
- 2
- alertSyntaxBase + 'side:long'; alertSyntaxBase + 'side:short'.
- Does Strategy Myth-Busting #23 - 2xEMA+DPO- [MYN] run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does Strategy Myth-Busting #23 - 2xEMA+DPO- [MYN] use a stop loss?
- No
- Its exits set a profit target but no stop.
BTCUSDT · 1D · default settings
- EMA 1
- EMA 2
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Year | |
| 2024 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 2025 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2026 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Likely bug
ta.ema(dpo, 30) ignores the settings line 37
Line 37 hard-codes 30 where line 21 uses “Length”. Changing those settings moves one band but not this one.
ta.ema(dpo, 30)ta.ema(dpo, len1) -
Check
No stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
Note
3 settings have no label
In the settings dialog isCentered (line 33), i_startPeriodTime (line 89), i_endPeriodTime (line 91) 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 267, 268, 271, 272, 275, 276. 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 |
|---|---|---|---|
| EMA 1 | |||
| Length | 40 | int · min 1 | out1 |
| Source | close | source | out1 |
| Offset | 0 | int · min -500 · max 500 | EMA 1 |
| Source | close | source | out2 |
| Offset | 0 | int · min -500 · max 500 | EMA 2 |
| Is Centered (no label in the script) | false | bool | dpo |
| EMA 2 | |||
| Length | 12 | int · min 1 | out2 |
| UpTrend DPO | |||
| Period | 21 | int · min 1 | barsback ma |
| 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 line | false | bool | emaValue isEMAFilterEnabledAndCloseAboveMA isEMAFilterEnabledAndCloseBelowMA |
| EMA Length | 200 | int · min 1 | emaValue |
| EMA Source | close | source | emaValue isEMAFilterEnabledAndCloseAboveMA isEMAFilterEnabledAndCloseBelowMA |
| ADX Filter | |||
| Enable ADX FilterEnable if you would like to conditionally have entries incorporate ADX as a filter | false | bool | adx isADXFilterEnabledAndAboveThreshold |
| ADX Variant | ORIGINAL | string · options ['ORIGINAL', 'MASANAKAMURA'] | adx |
| ADX Smoothing | 14 | int | DIPlusO DIMinusO ADXO |
| DI Length | 14 | int | DIPlusO DIMinusO ADXO DIPlusM DIMinusM ADXM |
| ADX Threshold | 25 | float · step .5 | isADXFilterEnabledAndAboveThreshold |
| Date Range | |||
| Start | true | bool | isStartPeriodEnabledAndInRange |
| I start Period Time (no label in the script) | timestamp('1 Jan 2019') | time | isStartPeriodEnabledAndInRange |
| End | true | bool | isEndPeriodEnabledAndInRange |
| I end Period Time (no label in the script) | timestamp('31 Dec 2030') | time | isEndPeriodEnabledAndInRange |
| Time Window | |||
| Enable Time-Of-Day WindowLimit the time of day for trade execution | false | bool | isTimeFilterEnabledAndInRange |
| Select Local Time Zone | GMT-5 | string · 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 Filter | 0700-0900 | session | isTimeFilterEnabledAndInRange |
| Trade Direction | |||
| Trade Direction | Long and Short | string · options ['Long and Short', 'Long Only', 'Short Only'] | longConditionFinal shortConditionFinal |
| 🛑 Stop Loss | |||
| Use Stop Loss | true | bool | SL SL close Long close Short line 270 |
| Type Of Stop Loss | Last Swing High/Low | string · options ["Fixed %","Last Swing High/Low","ATR"] | slPriceLong slCommentLong slPriceShort slCommentShort |
| Fixed % | 1 | float · min 0 · step 0.5 | fixedPercentSLPriceWhenLongPositionEntered fixedPercentSLPriceWhenShortPositionEntered |
| Swing High/Low Lookback | 21 | int | swingLowPriceWhenLongPostionEntered swingHighPriceWhenShortPositionEntered |
| ATR Length | 14 | int · min 1 | ATRSLPriceWhenLongPositionEntered ATRSLPriceWhenShortPositionEntered |
| ATR Multiplier | 1 | float · min 0 · step 0.1 | ATRSLPriceWhenLongPositionEntered ATRSLPriceWhenShortPositionEntered |
| 🟢 Take Profit | |||
| Use Take Profit | true | bool | TP TP line 259 |
| Type Of Take Profit | Risk:Reward Ratio | string · options ["Single Fixed %","Multiple Fixed %","Risk:Reward Ratio","ATR"] | tpPriceLong tpCommentLong tpPriceShort tpCommentShort exit TP1 exit TP2 exit TP3 exit i_takeProfitTargetPercent4 close Long close Short line 261 |
| Single Fixed % | 1 | float · min 0 · step 0.5 | fixedPercentTPPriceWhenLongPositionEntered fixedPercentTPPriceWhenShortPositionEntered |
| 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 i_takeProfitTargetPercent4 |
| Risk:Reward Ratio 1:# | 2.5 | float · min 0 · step 0.1 | tpRRPriceWhenLongPositionEntered tpRRPriceWhenShortPositionEntered |
| ATR Length | 14 | int · min 1 | ATRTPPriceWhenLongPositionEntered ATRTPPriceWhenShortPositionEntered |
| ATR Multiplier | 1 | float · min 0 · step 0.1 | ATRTPPriceWhenLongPositionEntered ATRTPPriceWhenShortPositionEntered |
| Plotting | |||
| Plot TP and SL | true | bool | SL TP Entry SL TP Entry |
| Leverage | |||
| Leverage | 1 | float · step .5 | contracts |
| % of Equity to Stake Per Trade | 100 | float · min 0.01 · max 100 · step 5 | contracts |
| ProfitView Alert Syntax | |||
| Alert Syntax Prefix | CRYPTANEX_99FTX_Strategy-Name-Here | string | alertSyntaxBase |
| Dashboards | |||
| Dashboard Size | Small | string · options ["Auto", "Huge", "Large", "Normal", "Small", "Tiny"] | tableTextSize |
| Performance Summary | true | bool | line 298 |
| Monthly Performance | true | bool | line 342 |
What it calculates
- EMASource (close), Length (40)
out1 · line 21 - EMASource (close), Length (12)
out2 · line 26 - Crossoversource1 = out2, source2 = out1
emaLongEntry · line 28 - Crossundersource1 = out2, source2 = out1
emaShortEntry · line 29 - SMAclose, Period (21)
ma · line 35 - EMAdpo, 30
sma · line 37 - EMAEMA Source (close), EMA Length (200)
emaValue · line 57 - DMIDI Length (14), ADX Smoothing (14)
DIPlusO · line 82 - DMIDI Length (14), ADX Smoothing (14)
DIMinusO · line 82 - DMIDI Length (14), ADX Smoothing (14)
ADXO · line 82 - ValuewhenopeningAnyPosition, close, 0
closePriceWhenPositionOpened · line 119 - ValuewhenopeningLongPosition, close, 0
fixedPercentSLPriceWhenLongPositionEntered · line 131 - ValuewhenopeningShortPosition, close, 0
fixedPercentSLPriceWhenShortPositionEntered · line 132 - Valuewhen / LowestopeningLongPosition, source = ta.lowest(low, i_swingHighLowLookbackSL), occurrence = 0
swingLowPriceWhenLongPostionEntered · line 134 - Valuewhen / HighestopeningShortPosition, source = ta.highest(high, i_swingHighLowLookbackSL), occurrence = 0
swingHighPriceWhenShortPositionEntered · line 135 - Valuewhen / ATRopeningLongPosition, close - (ta.atr(i_atrLengthSL) * i_atrMultiplierSL), 0
ATRSLPriceWhenLongPositionEntered · line 145 - Valuewhen / ATRopeningShortPosition, close + (ta.atr(i_atrLengthSL) * i_atrMultiplierSL), 0
ATRSLPriceWhenShortPositionEntered · line 146 - ValuewhenopeningLongPosition, close, 0
fixedPercentTPPriceWhenLongPositionEntered · line 187 - ValuewhenopeningShortPosition, close, 0
fixedPercentTPPriceWhenShortPositionEntered · line 188 - Valuewhen / ATRopeningLongPosition, close + (ta.atr(i_atrLengthTP) * i_atrMultiplierTP), 0
ATRTPPriceWhenLongPositionEntered · line 195 - Valuewhen / ATRopeningShortPosition, close - (ta.atr(i_atrLengthTP) * i_atrMultiplierTP), 0
ATRTPPriceWhenShortPositionEntered · line 196
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 129 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 | longConditionFinal | On | 253 |
| Open Short short | shortConditionFinal | On | 256 |
| Exit TP1 limit | i_typeOfTakeProfit == "Multiple Fixed %" | On | 262 |
| Exit TP2 limit | i_typeOfTakeProfit == "Multiple Fixed %" | On | 263 |
| Exit TP3 limit | i_typeOfTakeProfit == "Multiple Fixed %" | On | 264 |
| Exit i_takeProfitTargetPercent4 limit | i_typeOfTakeProfit == "Multiple Fixed %" | On | 265 |
| Close Long | tpLongConditionclose >= tpPriceLong | On | 267 |
| Close Short | tpShortConditionclose <= tpPriceShort | On | 268 |
| Close Long | slLongConditionclose <= slPriceLong | On “Use Stop Loss” | 271 |
| Close Short | slShortConditionclose >= slPriceShort | On “Use Stop Loss” | 272 |
| Close Long | closeLongCondition | On | 275 |
| Close Short | closeShortCondition | On | 276 |
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' | 254 |
| (no title) | alert | alertSyntaxBase + 'side:short' | 257 |
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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 #23 - 2xEMA+DPO- [MYN] this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| ATR + STC + MA by Romedius | ema lowest highest atr sma | v5 strategy | −1.2% | 15 | 3.3% |
| -NoSKi Hammer-Star -w angle of ema Backtester - by noski1 | atr ema sma highest lowest | v5 strategy | does not run in Zeal Terminal | ||
| Modulo Logic + EMA Strat by tweakerID | lowest highest valuewhen atr ema | v4 strategy | −50.8% | 16 | 54.7% |
| LONG SAZB $ by stevenz17 | ema sma atr lowest highest | v4 strategy | No trades on this market | ||
| Solution Zigma - Fibonacci Impulse by ZoomerXeus | ema highest lowest dmi atr sma | v5 strategy | does not run in Zeal Terminal | ||
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.
- 6 strategy calls use the when = argument (line 267, 268, 271, 272, 275, 276). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 4 settings use the untyped input() (line 19, 24, 33, 229). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 19: input() → input.source()
- Line 24: input() → input.source()
- Line 33: input() → input.bool()
- Line 229: input() → input.bool()
- Line 267: when = tpLongCondition → if block
- Line 268: when = tpShortCondition → if block
4 more edits
- Line 271: when = slLongCondition → if block
- Line 272: when = slShortCondition → if block
- Line 275: when = closeLongCondition → if block
- Line 276: when = closeShortCondition → if block
⋯len1 = input.int(40, minval=1, title="Length", group="EMA 1")-src1 = input(close, title="Source")+src1 = input.source(close, title="Source")offset1 = input.int(title="Offset", defval=0, minval=-500, maxval=500)⋯len2 = input.int(12, minval=1, title="Length", group="EMA 2")-src2 = input(close, title="Source")+src2 = input.source(close, title="Source")offset2 = input.int(title="Offset", defval=0, minval=-500, maxval=500)⋯period_ = input.int(21, title='Period', minval=1,group="UpTrend DPO")-isCentered = input(false)+isCentered = input.bool(false)barsback = period_ / 2 + 1⋯//Plot SL and TP-i_plotTPSL=input(true, title="Plot TP and SL", group='Plotting')+i_plotTPSL=input.bool(true, title="Plot TP and SL", group='Plotting')slbp=plot(i_plotTPSL and i_useStopLoss and strategy.position_size > 0 ? slPriceLong[1] : na, color=color.red, style=plot.style_linebr, title="SL")⋯ else- strategy.close('Long', comment=tpCommentLong, when=tpLongCondition)+ if tpLongCondition+ strategy.close('Long', comment=tpCommentLong)- strategy.close('Short', comment=tpCommentShort, when=tpShortCondition)+ if tpShortCondition+ strategy.close('Short', comment=tpCommentShort) if i_useStopLoss - strategy.close('Long', comment=slCommentLong, when=slLongCondition)+ if slLongCondition+ strategy.close('Long', comment=slCommentLong)- strategy.close('Short', comment=slCommentShort, when=slShortCondition)+ if slShortCondition+ strategy.close('Short', comment=slCommentShort) // Conditional Closes- strategy.close('Long', comment='Conditional Close Long', when=closeLongCondition)+ if closeLongCondition+ strategy.close('Long', comment='Conditional Close Long')- strategy.close('Short', comment='Conditional Close Short', when=closeShortCondition)+ if closeShortCondition+ strategy.close('Short', comment='Conditional Close Short')// Global Dashboard Variables⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. 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 #23 - 2xEMA+DPO- [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=1000, currency='NONE', default_qty_type=strategy.percent_of_equity, default_qty_value=1.0, commission_value=0.075, use_bar_magnifier = false)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 223 ms | With a workaround 1,000 bars in 260 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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 Myth-Busting #23 - 2xEMA+DPO- [MYN]', max_bars_back=5000, overlay=true, pyramiding=0, initial_capital=1000, currency='NONE', default_qty_type=strategy.percent_of_equity, default_qty_value=1.0, commission_value=0.075, use_bar_magnifier = false)//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// indicators:// EMA 40// EMA 12// Untrend Price DPO indicator ( jTradeuh ), on style untick the DPOvalue// Entry rules:// Longs: EMA 12 have to cross EMA 40 and need to be above it and the Untrend price DPO indicator has to have multiple green bars,// Shorts: EMA 12 have to cross EMA 40 and need to be under it and the Untrend price DPO indicator has to have multiple reed bars,// SL recent swing high/low// TP 2.5 risk reward ratio.// Second confluence using Untrend Price DPO // 2 EMA//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░len1 = input.int(40, minval=1, title="Length", group="EMA 1")src1 = input(close, title="Source")offset1 = input.int(title="Offset", defval=0, minval=-500, maxval=500)out1 = ta.ema(src1, len1)plot(out1, title="EMA 1", color=color.white, offset=offset1, linewidth=2)len2 = input.int(12, minval=1, title="Length", group="EMA 2")src2 = input(close, title="Source")offset2 = input.int(title="Offset", defval=0, minval=-500, maxval=500)out2 = ta.ema(src2, len2)plot(out2, title="EMA 2", color=color.yellow, offset=offset2, linewidth=2)emaLongEntry = ta.crossover(source1=out2 , source2 =out1 ) emaShortEntry = ta.crossunder(source1=out2 , source2 =out1 ) // Uptrend Price DPO indicator//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░period_ = input.int(21, title='Period', minval=1,group="UpTrend DPO")isCentered = input(false)barsback = period_ / 2 + 1ma = ta.sma(close, period_)dpo = isCentered ? close[barsback] - ma : close - ma[barsback]sma = ta.ema(dpo, 30)COLOR = dpo > 0 ? color.lime : color.red//plot(sma, offset=isCentered ? -barsback : 0, title='DPO', color=COLOR, style=plot.style_histogram)//hline(0, title='Zero')// Last 2 bars at least need to be greenupTrenndDPOEntryLong = dpo > 0 and dpo[1] > 0 and dpo[2] > 0// Last 2 bars at least need to be redupTrendDPOEntryShort = dpo < 0 and dpo[1] < 0 and dpo[2] < 0// Put Your Strategy Rules Below//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░longCondition = emaLongEntry and upTrenndDPOEntryLong // default: falseshortCondition = emaShortEntry and upTrendDPOEntryShort // default: false//define as 0 if do not want to have a conditional closecloseLongCondition = false // default: 0closeShortCondition = false // 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 and State Management// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░i_tradeDirection = input.string('Long and Short', title='Trade Direction', options=['Long and Short', 'Long Only', 'Short Only'], group='Trade Direction')// Todo Add logic to reenter trade only if condition is still met only on TP//i_reenterPosition = input.bool(defval=true, title='Re-Enter Position on TP' , group='Trade Direction')//longConditionFinal = i_reenterPosition ? longCondition : longCondition and not longCondition[1]//shortConditionFinal = i_reenterPosition ? shortCondition : shortCondition and not shortCondition[1]isInLongPosition = strategy.position_size > 0isInShortPosition = strategy.position_size < 0longConditionFinal = (longCondition and isADXFilterEnabledAndAboveThreshold and isEMAFilterEnabledAndCloseAboveMA) and i_tradeDirection != 'Short Only' and isInLongPosition == falseshortConditionFinal = (shortCondition and isADXFilterEnabledAndAboveThreshold and isEMAFilterEnabledAndCloseBelowMA) and i_tradeDirection != 'Long Only' and isInShortPosition == false// Trade Entry variables (not in position yet)bool openingLongPosition = longConditionFinal and not (strategy.opentrades.size(strategy.opentrades - 1) > 0) bool openingShortPosition = shortConditionFinal and not (strategy.opentrades.size(strategy.opentrades - 1) < 0) bool openingAnyPosition = openingLongPosition or openingShortPositionfloat closePriceWhenPositionOpened = ta.valuewhen(openingAnyPosition,close,0)// Stop Loss// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░// Todo: Consider moving the strategy.entry calls above where the TP/SL close orders so that close orders can be executed on same bar.var groupStopLoss = "🛑 Stop Loss"i_useStopLoss = input.bool (title="Use Stop Loss", defval = true, group=groupStopLoss)i_typeOfStopLoss = input.string (title="Type Of Stop Loss", defval="Last Swing High/Low", options=["Fixed %","Last Swing High/Low","ATR"], group=groupStopLoss)i_fixedPercentSL = input.float(title='Fixed %', defval=1, minval=0, step=0.5, group=groupStopLoss) * 0.01i_swingHighLowLookbackSL = input.int(21, title="Swing High/Low Lookback", group=groupStopLoss)i_atrLengthSL = input.int(title="ATR Length", defval=14, minval = 1, inline="ATR SL", group=groupStopLoss)i_atrMultiplierSL = input.float(title="ATR Multiplier", defval=1, minval = 0, step=0.1, inline="ATR SL", group=groupStopLoss)// Fixed Percent Stop Lossfloat fixedPercentSLPriceWhenLongPositionEntered = ta.valuewhen(openingLongPosition,close,0) * (1 - i_fixedPercentSL)float fixedPercentSLPriceWhenShortPositionEntered = ta.valuewhen(openingShortPosition,close,0) * (1 + i_fixedPercentSL)// Swing High/Low Stop Lossfloat swingLowPriceWhenLongPostionEntered = ta.valuewhen(openingLongPosition, source = ta.lowest(low, i_swingHighLowLookbackSL), occurrence = 0)float swingHighPriceWhenShortPositionEntered = ta.valuewhen(openingShortPosition, source = ta.highest(high, i_swingHighLowLookbackSL), occurrence = 0)// Debug Start// drawLabel(_offset, _pivot, _style, _color) =>// if not na(_pivot)// label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=#131722)// drawLabel(i_swingHighLowLookbackSL, ta.pivothigh(high, i_swingHighLowLookbackSL, i_swingHighLowLookbackSL), label.style_label_down, color.red)// drawLabel(i_swingHighLowLookbackSL, ta.pivotlow(low, i_swingHighLowLookbackSL, i_swingHighLowLookbackSL), label.style_label_up, color.blue)// Debug End//ATR//todo determine if close should be source for both long/short or if high/low should be used?float ATRSLPriceWhenLongPositionEntered = ta.valuewhen(openingLongPosition, close - (ta.atr(i_atrLengthSL) * i_atrMultiplierSL) ,0)float ATRSLPriceWhenShortPositionEntered = ta.valuewhen(openingShortPosition, close + (ta.atr(i_atrLengthSL) * i_atrMultiplierSL) ,0)//plot(close + (ta.atr(i_atrLengthSL) * i_atrMultiplierSL), color=color.new(color.green, 0))//plot(close - (ta.atr(i_atrLengthSL) * i_atrMultiplierSL), color=color.new(color.red, 0))f_calculateStopLoss(string direction, string typeOfStopLoss) => // TODO init these to be 0 and "" as slPriceLong/Short is referenced by TP Risk:Reward calculation float slOrderClosePrice = na string slOrderComment = na switch typeOfStopLoss "Fixed %" => slOrderClosePrice := direction == "long" ? fixedPercentSLPriceWhenLongPositionEntered : fixedPercentSLPriceWhenShortPositionEntered slOrderComment := direction == "long" ? "SL Fixed % Long" : "SL Fixed % Short" "Last Swing High/Low" => slOrderClosePrice := direction == "long" ? swingLowPriceWhenLongPostionEntered : swingHighPriceWhenShortPositionEntered slOrderComment := direction == "long" ? "SL Swing Low Long" : "SL Swing High Short" "ATR" => slOrderClosePrice := direction == "long" ? ATRSLPriceWhenLongPositionEntered : ATRSLPriceWhenShortPositionEntered slOrderComment := direction == "long" ? "SL ATR Long" : "SL ATR Short" [slOrderClosePrice,slOrderComment] [slPriceLong, slCommentLong] = f_calculateStopLoss( "long",i_typeOfStopLoss) [slPriceShort, slCommentShort] = f_calculateStopLoss("short",i_typeOfStopLoss) slLongCondition = close <= slPriceLongslShortCondition = close >= slPriceShort// Take Profit // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░var groupTakeProfit = "🟢 Take Profit"i_useTakeProfit = input.bool (title="Use Take Profit", defval = true, group=groupTakeProfit)i_typeOfTakeProfit = input.string (title="Type Of Take Profit", defval="Risk:Reward Ratio", options=["Single Fixed %","Multiple Fixed %","Risk:Reward Ratio","ATR"], group=groupTakeProfit)i_fixedPercentTP = input.float(title='Single Fixed %', defval=1, minval=0, step=0.5, group=groupTakeProfit) * 0.01i_takeProfitTargetPercent1 = input.float(title='Take Profit 1 - Target %', defval=100, minval=0.0, step=0.5, group=groupTakeProfit, inline='Take Profit 1')i_takeProfitQuantityPercent1 = input.int(title='% Of Position', defval=100, minval=0, group=groupTakeProfit, inline='Take Profit 1')i_takeProfitTargetPercent2 = input.float(title='Take Profit 2 - Target %', defval=100, minval=0.0, step=0.5, group=groupTakeProfit, inline='Take Profit 2')i_takeProfitQuantityPercent2 = input.int(title='% Of Position', defval=100, minval=0, group=groupTakeProfit, inline='Take Profit 2')i_takeProfitTargetPercent3 = input.float(title='Take Profit 3 - Target %', defval=100, minval=0.0, step=0.5, group=groupTakeProfit, inline='Take Profit 3')i_takeProfitQuantityPercent3 = input.int(title='% Of Position', defval=100, minval=0, group=groupTakeProfit, inline='Take Profit 3')i_takeProfitTargetPercent4 = input.float(title='Take Profit 4 - Target %', defval=100, minval=0.0, step=0.5, group=groupTakeProfit)i_RiskRewardRatioTP = input.float(title="Risk:Reward Ratio 1:#", defval=2.5, minval=0 , step=0.1, group=groupTakeProfit)i_atrLengthTP = input.int(title="ATR Length", defval=14, minval = 1, inline="ATR TP", group=groupTakeProfit)i_atrMultiplierTP = input.float(title="ATR Multiplier", defval=1, minval = 0, step=0.1, inline="ATR TP", group=groupTakeProfit)// Single Fixed Percent Take Profitfloat fixedPercentTPPriceWhenLongPositionEntered = ta.valuewhen(openingLongPosition,close,0) * (1 + i_fixedPercentTP)float fixedPercentTPPriceWhenShortPositionEntered = ta.valuewhen(openingShortPosition,close,0) * (1 - i_fixedPercentTP)// Multiple// Risk:Reward Ratio Take ProfittpRRPriceWhenLongPositionEntered = closePriceWhenPositionOpened + ((closePriceWhenPositionOpened - slPriceLong) * i_RiskRewardRatioTP)tpRRPriceWhenShortPositionEntered = closePriceWhenPositionOpened + ((closePriceWhenPositionOpened - slPriceShort) * i_RiskRewardRatioTP)//ATR//todo determine if close should be source for both long/short or if high/low should be used?float ATRTPPriceWhenLongPositionEntered = ta.valuewhen(openingLongPosition, close + (ta.atr(i_atrLengthTP) * i_atrMultiplierTP) ,0)float ATRTPPriceWhenShortPositionEntered = ta.valuewhen(openingShortPosition, close - (ta.atr(i_atrLengthTP) * i_atrMultiplierTP) ,0)// plot(close + (ta.atr(i_atrLengthTP) * i_atrMultiplierTP), color=color.new(color.green, 0))// plot(close - (ta.atr(i_atrLengthTP) * i_atrMultiplierTP), color=color.new(color.red, 0))f_calculateTakeProfit(string direction, string typeOfTakeProfit) => float tpOrderClosePrice = na string tpOrderComment = na switch typeOfTakeProfit "Single Fixed %" => tpOrderClosePrice := direction == "long" ? fixedPercentTPPriceWhenLongPositionEntered : fixedPercentTPPriceWhenShortPositionEntered tpOrderComment := direction == "long" ? "TP Single Fixed % Long" : "TP Single Fixed % Short" "Multiple Fixed %" => tpOrderClosePrice := na tpOrderComment := "" "Risk:Reward Ratio" => tpOrderClosePrice := direction == "long" ? tpRRPriceWhenLongPositionEntered : tpRRPriceWhenShortPositionEntered tpOrderComment := direction == "long" ? "TP R:R Long" : "TP R:R Short" "ATR" => tpOrderClosePrice := direction == "long" ? ATRTPPriceWhenLongPositionEntered : ATRTPPriceWhenShortPositionEntered tpOrderComment := direction == "long" ? "TP ATR Long" : "TP ATR Short" [tpOrderClosePrice,tpOrderComment] [tpPriceLong, tpCommentLong] = f_calculateTakeProfit( "long",i_typeOfTakeProfit) [tpPriceShort, tpCommentShort] = f_calculateTakeProfit("short",i_typeOfTakeProfit) tpLongCondition = close >= tpPriceLongtpShortCondition = close <= tpPriceShort// Functions// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░per(pcnt) => strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)// Plotting// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░//Plot SL and TPi_plotTPSL=input(true, title="Plot TP and SL", group='Plotting')slbp=plot(i_plotTPSL and i_useStopLoss and strategy.position_size > 0 ? slPriceLong[1] : na, color=color.red, style=plot.style_linebr, title="SL")tpbp=plot(i_plotTPSL and i_useTakeProfit and strategy.position_size > 0 ? tpPriceLong[1] : na, color=color.lime, style=plot.style_linebr, title="TP")epbp=plot(i_plotTPSL and strategy.position_size > 0 ? strategy.position_avg_price : na, color=color.gray, style=plot.style_linebr, title="Entry")fill(slbp, epbp, color=color.new(color.red, 90))fill(tpbp, epbp, color=color.new(color.green, 90))slsp=plot(i_plotTPSL and i_useStopLoss and strategy.position_size < 0 ? slPriceShort[1] : na, color=color.red, style=plot.style_linebr, title="SL")tpsp=plot(i_plotTPSL and i_useTakeProfit and strategy.position_size < 0 ? tpPriceShort[1] : na, color=color.lime, style=plot.style_linebr, title="TP")epsp=plot(i_plotTPSL and strategy.position_size < 0 ? strategy.position_avg_price : na, color=color.gray, style=plot.style_linebr, title="Entry")fill(slsp, epsp, color=color.new(color.red, 90))fill(tpsp, epsp, color=color.new(color.green, 90))/// 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)/// 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// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░if isStartEndPeriodsAndTimeInRange if longConditionFinal strategy.entry('Long', strategy.long, qty=contracts) alert(message=alertSyntaxBase + 'side:long', freq=alert.freq_once_per_bar_close) if shortConditionFinal strategy.entry('Short', strategy.short, qty=contracts) alert(message=alertSyntaxBase + 'side:short', freq=alert.freq_once_per_bar_close) if i_useTakeProfit //Inspired from Multiple %% profit exits example by adolgo https://www.tradingview.com/script/kHhCik9f-Multiple-profit-exits-example/ if i_typeOfTakeProfit == "Multiple Fixed %" 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)) else strategy.close('Long', comment=tpCommentLong, when=tpLongCondition) strategy.close('Short', comment=tpCommentShort, when=tpShortCondition) if i_useStopLoss strategy.close('Long', comment=slCommentLong, when=slLongCondition) strategy.close('Short', comment=slCommentShort, when=slShortCondition) // Conditional Closes strategy.close('Long', comment='Conditional Close Long', when=closeLongCondition) strategy.close('Short', comment='Conditional 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 lastTime = strategy.position_size == 0 ? strategy.closedtrades.exit_time(strategy.closedtrades-1) : time 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}", lastTime) , 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 = (lastTime - 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)