Pine Script v5 · Strategy
DCA After Downtrend v2 (by BHD_Trade_Bot)
A Pine Script v5 strategy built on EMA (close, 50) and RMA (high - low, 200). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 1000 in cash and pays 1.1% commission. 6 settings; defaults include Start year 2017, Start month 1 and Start day 1.
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 DCA After Downtrend v2 (by BHD_Trade_Bot) repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- Does DCA After Downtrend v2 (by BHD_Trade_Bot) 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 DCA After Downtrend v2 (by BHD_Trade_Bot) use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does DCA After Downtrend v2 (by BHD_Trade_Bot) run in Zeal Terminal?
- Yes
- It compiles in 24 ms and runs 1,000 bars in 56 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Net profit
- 0.00%
- −$22.00
- Buy and hold
- 0.0%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- 0.00
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- −$191.34
One run with the author's default settings, $0 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
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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 |
|---|---|---|---|
| Start year | 2017 | int | start_time |
| Start month | 1 | int | start_time |
| Start day | 1 | int | start_time |
| end year | 2050 | int | end_time |
| end month | 1 | int | end_time |
| end day | 1 | int | end_time |
What it calculates
- EMAclose, 50
ema50 · line 29 - EMAclose, 200
ema200 · line 30 - EMAemacd, 20
emacd_signal · line 33 - RMAhigh - low, 200
bhd_unit · line 36
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open entryId long | ENTRY_CONDITIONS | On | 61 |
| Close | CLOSE_CONDITIONS | On | 68 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
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 recalculationreads 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 | 0.0% | 0.0% | 0 | 0% | 0.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | 0.0% | 0 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | 0.0% | 0 | 0% | 0.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | 0.0% | 0 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | 0.0% | 0 | 0% | 0.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | 0.0% | 0 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | 0.0% | 0 | 0% | 0.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | 0.0% | 0 | 0% | 0.00 | 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 |
|---|---|---|---|---|---|
| DCA After Downtrend v2 (by BHD_Trade_Bot) this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Williams Fractals Strategy by B_L_A_C_K_S_C_O_R_P_I_O_N | ema rma | v4 strategy | No trades on this market | ||
| Strategy Myth-Busting #10 - InsideBar+EMA - [MYN] by myncrypto | ema rma | v5 strategy | No trades on this market | ||
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| Take Profit On Trend v2 (by BHD_Trade_Bot) by BHD_Trade_Bot | ema rma | v5 strategy | +9.4% | 6 | 24.0% |
| Daytrade strategy RSI CCI EMA 4-8 by SoftKill21 | ema rma | v4 strategy | +0.0% | 26 | 0.0% |
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 settings use the untyped input() (line 18, 19, 20, 22, 23, 24). 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 18: input() → input.int()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 22: input() → input.int()
- Line 23: input() → input.int()
- Line 24: input() → input.int()
⋯// Backtest Time Period-start_year = input(title='Start year' ,defval=2017)+start_year = input.int(title='Start year' ,defval=2017)-start_month = input(title='Start month' ,defval=1)+start_month = input.int(title='Start month' ,defval=1)-start_day = input(title='Start day' ,defval=1)+start_day = input.int(title='Start day' ,defval=1)start_time = timestamp(start_year, start_month, start_day, 00, 00)-end_year = input(title='end year' ,defval=2050)+end_year = input.int(title='end year' ,defval=2050)-end_month = input(title='end month' ,defval=1)+end_month = input.int(title='end month' ,defval=1)-end_day = input(title='end day' ,defval=1)+end_day = input.int(title='end day' ,defval=1)end_time = timestamp(end_year, end_month, end_day, 23, 59)⋯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.
⋯// © BHD_Trade_Bot-// @version=5+// @version=6strategy(⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 24 ms | Yes 1,000 bars in 56 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/// © BHD_Trade_Bot// @version=5strategy( shorttitle = 'DCA After Downtrend v2', title = 'DCA After Downtrend v2 (by BHD_Trade_Bot)', overlay = true, calc_on_every_tick = false, calc_on_order_fills = false, use_bar_magnifier = false, pyramiding = 1000, initial_capital = 0, default_qty_type = strategy.cash, default_qty_value = 1000, commission_type = strategy.commission.percent, commission_value = 1.1)// Backtest Time Periodstart_year = input(title='Start year' ,defval=2017)start_month = input(title='Start month' ,defval=1)start_day = input(title='Start day' ,defval=1)start_time = timestamp(start_year, start_month, start_day, 00, 00)end_year = input(title='end year' ,defval=2050)end_month = input(title='end month' ,defval=1)end_day = input(title='end day' ,defval=1)end_time = timestamp(end_year, end_month, end_day, 23, 59)window() => time >= start_time and time <= end_time ? true : falseh1_last_bar = (math.min(end_time, timenow) - time)/1000/60/60 < 2// EMAema50 = ta.ema(close, 50)ema200 = ta.ema(close, 200)// EMA_CDemacd = ema50 - ema200emacd_signal = ta.ema(emacd, 20)hist = emacd - emacd_signal// BHD Unitbhd_unit = ta.rma(high - low, 200) * 2bhd_upper = ema200 + bhd_unitbhd_upper2 = ema200 + bhd_unit * 2bhd_upper3 = ema200 + bhd_unit * 3bhd_upper4 = ema200 + bhd_unit * 4bhd_upper5 = ema200 + bhd_unit * 5bhd_lower = ema200 - bhd_unitbhd_lower2 = ema200 - bhd_unit * 2bhd_lower3 = ema200 - bhd_unit * 3bhd_lower4 = ema200 - bhd_unit * 4bhd_lower5 = ema200 - bhd_unit * 5// Count n candles after x long entriesvar int nPastCandles = 0var int entryNumber = 0if window() nPastCandles := nPastCandles + 1// ENTRY CONDITIONS// 24 * 30 per monthentry_condition1 = nPastCandles > entryNumber * 24 * 30// End of downtrendentry_condition2 = emacd < 0 and hist < 0 and hist > hist[2]ENTRY_CONDITIONS = entry_condition1 and entry_condition2if ENTRY_CONDITIONS entryNumber := entryNumber + 1 entryId = 'Long ' + str.tostring(entryNumber) strategy.entry(entryId, strategy.long) // CLOSE CONDITIONS// Last barCLOSE_CONDITIONS = barstate.islast or h1_last_barif CLOSE_CONDITIONS strategy.close_all()// DrawcolorRange(src) => if src > bhd_upper5 color.rgb(255,0,0) else if src > bhd_upper4 color.rgb(255,150,0) else if src > bhd_upper3 color.rgb(255,200,0) else if src > bhd_upper2 color.rgb(100,255,0) else if src > bhd_upper color.rgb(0,255,100) else if src > ema200 color.rgb(0,255,150) else if src > bhd_lower color.rgb(0,200,255) else if src > bhd_lower2 color.rgb(0,150,255) else if src > bhd_lower3 color.rgb(0,100,255) else if src > bhd_lower4 color.rgb(0,50,255) else color.rgb(0,0,255) bhd_upper_line = plot(bhd_upper, color=color.new(color.teal, 90))bhd_upper_line2 = plot(bhd_upper2, color=color.new(color.teal, 90))bhd_upper_line3 = plot(bhd_upper3, color=color.new(color.teal, 90))bhd_upper_line4 = plot(bhd_upper4, color=color.new(color.teal, 90))bhd_upper_line5 = plot(bhd_upper5, color=color.new(color.teal, 90))bhd_lower_line = plot(bhd_lower, color=color.new(color.teal, 90))bhd_lower_line2 = plot(bhd_lower2, color=color.new(color.teal, 90))bhd_lower_line3 = plot(bhd_lower3, color=color.new(color.teal, 90))bhd_lower_line4 = plot(bhd_lower4, color=color.new(color.teal, 90))bhd_lower_line5 = plot(bhd_lower5, color=color.new(color.teal, 90))// fill(bhd_upper_line5, bhd_lower_line5, color=color.new(color.teal, 95))plot(ema50, color=color.orange, linewidth=3)plot(ema200, color=color.teal, linewidth=3)plot(close, color=color.teal, linewidth=1)plot(close, color=colorRange(close), linewidth=3, style=plot.style_circles)