Pine Script v5 · Strategy
DCA After Downtrend (by BHD_Trade_Bot)
A Pine Script v5 strategy built on EMA (close, 50) and Crossover (emacd, emacd_signal). 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 0.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 (by BHD_Trade_Bot) repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- Does DCA After Downtrend (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 (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 (by BHD_Trade_Bot) run in Zeal Terminal?
- Yes
- It compiles in 20 ms and runs 1,000 bars in 29 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- −$4.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%
- −$1,223.70
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 28 - EMAclose, 200
ema200 · line 29 - EMAemacd, 20
emacd_signal · line 32 - Crossoveremacd, emacd_signal
entry_condition2 · line 42
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 and window() | On | 47 |
| Close | CLOSE_CONDITIONS | On | 54 |
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 recalculationcalc_on_every_tick = true. 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 (by BHD_Trade_Bot) this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
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 20 ms | Yes 1,000 bars in 29 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', title = 'DCA After Downtrend (by BHD_Trade_Bot)', overlay = true, calc_on_every_tick = true, calc_on_order_fills = true, use_bar_magnifier = true, pyramiding = 100, initial_capital = 0, default_qty_type = strategy.cash, default_qty_value = 1000, commission_type = strategy.commission.percent, commission_value = 0.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 : false// EMAema50 = ta.ema(close, 50)ema200 = ta.ema(close, 200)// EMA_CDemacd = ema50 - ema200emacd_signal = ta.ema(emacd, 20)hist = emacd - emacd_signal// Count n candles after x long entriesvar int nPastCandles = 0var int entryNumber = 0nPastCandles := nPastCandles + 1// ENTRY CONDITIONS// 8 hours per day => 240 hours per monthentry_condition1 = nPastCandles > entryNumber * 240// End of downtrendentry_condition2 = ta.crossover(emacd, emacd_signal)ENTRY_CONDITIONS = entry_condition1 and entry_condition2if ENTRY_CONDITIONS and window() entryNumber := entryNumber + 1 entryId = 'Long ' + str.tostring(entryNumber) strategy.entry(entryId, strategy.long) // CLOSE CONDITIONS// Last barCLOSE_CONDITIONS = barstate.islastif CLOSE_CONDITIONS strategy.close_all() // Drawplot(ema50, color=color.orange, linewidth=3)plot(ema200, color=entry_condition1 ? color.green : color.red, linewidth=3)