Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (6)
50,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$661$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%
−$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.

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 29
  • EMAclose, 200ema200 · line 30
  • EMAemacd, 20emacd_signal · line 33
  • RMAhigh - low, 200bhd_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.

closecloseprice datalowlowprice datahighhighprice datastart_yearStart yearsetting · 2017start_monthStart monthsetting · 1start_dayStart daysetting · 1end_yearend yearsetting · 2050end_monthend monthsetting · 1end_dayend daysetting · 1timetimeprice dataema50EMA→ ema50ema200EMA→ ema200emacd_signalEMA→ emacd_signalbhd_unitRMA→ bhd_unitstart_timestart_timevalueend_timeend_timevalueemacdemacdvaluehisthistvaluebhd_upper, bhd_upper2, bhd_upper3, bhd_upper4, bhd_upper5, bhd_lower, bhd_lower2, bhd_lower3, bhd_lower4, bhd_lower5bhd_upper · bhd_upper2 …10 valuesnPastCandlesnPastCandlesvalueentryNumber, entryIdentryNumber · entryId2 valuesENTRY_CONDITIONSENTRY_CONDITIONSconditionCLOSE_CONDITIONSCLOSE_CONDITIONSconditionh1_last_barh1_last_barconditionentry_condition1entry_condition1conditionentry_condition2entry_condition2conditionentry:entryIdOpen entryIdstrategy.entryclose_all:close_all strategy.close_allplot:94plotplotplot:95plotplotplot:96plotplotplot:97plotplotplot:98plotplotplot:99plotplotplot:100plotplotplot:101plotplotplot:102plotplotplot:103plotplotplot:105plotplotplot:106plotplotplot:107plotplotplot:108plotplot

Order rules

OrderFires whenBy defaultLine
Open entryId longENTRY_CONDITIONSOn61
Close CLOSE_CONDITIONSOn68

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 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.

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 v2 (by BHD_Trade_Bot) this page—v5 strategy0.0%00.0%
Williams Fractals Strategy by B_L_A_C_K_S_C_O_R_P_I_O_Nema rmav4 strategyNo trades on this market
Strategy Myth-Busting #10 - InsideBar+EMA - [MYN] by myncryptoema rmav5 strategyNo trades on this market
Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10kema rmav4 strategy−19.4%3670.0%
Take Profit On Trend v2 (by BHD_Trade_Bot) by BHD_Trade_Botema rmav5 strategy+9.4%624.0%
Daytrade strategy RSI CCI EMA 4-8 by SoftKill21ema rmav4 strategy+0.0%260.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 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 24 msYes 1,000 bars in 56 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 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)