Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (6)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$71$0Equity from $0
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
Start year2017intstart_time
Start month1intstart_time
Start day1intstart_time
end year2050intend_time
end month1intend_time
end day1intend_time

What it calculates

  • EMAclose, 50ema50 · line 28
  • EMAclose, 200ema200 · line 29
  • EMAemacd, 20emacd_signal · line 32
  • Crossoveremacd, emacd_signalentry_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.

closecloseprice datastart_yearStart yearsetting · 2017start_monthStart monthsetting · 1start_dayStart daysetting · 1end_yearend yearsetting · 2050end_monthend monthsetting · 1end_dayend daysetting · 1ema50EMA→ ema50ema200EMA→ ema200emacd_signalEMA→ emacd_signalentry_condition2Crossover→ entry_condition2start_timestart_timevalueend_timeend_timevalueemacdemacdvaluehisthistvaluenPastCandlesnPastCandlesvalueentryNumber, entryIdentryNumber · entryId2 valuesCLOSE_CONDITIONSCLOSE_CONDITIONSvalueENTRY_CONDITIONSENTRY_CONDITIONSconditionentry_condition1entry_condition1conditionentry:entryIdOpen entryIdstrategy.entryclose_all:close_all strategy.close_allplot:57plotplotplot:58plotplot

Order rules

OrderFires whenBy defaultLine
Open entryId longENTRY_CONDITIONS and window()On47
Close CLOSE_CONDITIONSOn54

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.

1trade only the live replay producedThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. On 0 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%0.0%00%0.000.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%0.0%00%0.000.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%0.0%00%0.000.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%0.0%00%0.000.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%0.0%00%0.000.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%0.0%00%0.000.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%0.0%00%0.000.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%0.0%00%0.000.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.

ScriptSharesTypeNetTradesMax drawdown
DCA After Downtrend (by BHD_Trade_Bot) this page—v5 strategy0.0%00.0%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,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 verified

Neither 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 20 msYes 1,000 bars in 29 msNot measured
PineTSNot testedNot testedNot 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)