Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Buy&Sell Bullish Engulfing - The Quant Science

A Pine Script v5 strategy built on SMA (close, 50), EMA (C_Body, C_Len) and ATR (30). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a profit target and no stop loss. Each trade commits 100% of equity and pays 0.07% commission. 11 settings; defaults include D: 1, M: 1 and Y: 2022.

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 Buy&Sell Bullish Engulfing - The Quant Science repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Buy&Sell Bullish Engulfing - The Quant Science 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.
Does Buy&Sell Bullish Engulfing - The Quant Science 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 Buy&Sell Bullish Engulfing - The Quant Science use a stop loss?
No
Its exits set a profit target but no stop.
Does Buy&Sell Bullish Engulfing - The Quant Science run in Zeal Terminal?
Yes
It compiles in 33 ms and runs 1,000 bars in 61 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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 (10)
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBE40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,000$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep. Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 95) so the engine trades the way the script says.
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, $10,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.

  • Check

    No stop loss

    strategy.exit is used without a stop, loss or trailing stop.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • 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 DATE BACKTESTING
D: D is Day, M is Month, Y is Year.1int · min 1 · max 31inDateRange
M: D is Day, M is Month, Y is Year.1int · min 1 · max 12inDateRange
Y: D is Day, M is Month, Y is Year.2022int · min 1800 · max 2100inDateRange
END DATE BACKTESTING
D: D is Day, M is Month, Y is Year.31int · min 1 · max 31inDateRange
M: D is Day, M is Month, Y is Year.12int · min 1 · max 12inDateRange
Y: D is Day, M is Month, Y is Year.2023int · min 1800 · max 2100inDateRange
TAKE PROFIT-STOP LOSS
Target profit (%): 1float · min 0 · step 0.10c_exit
Stop Loss (%): 1float · min 0 · step 0.10c_stopl
RISK MANAGEMENT
Orders size (%): Percentage size of each new order. With 'Reinvestment Profit' activate, the size will be calculate on the equity, with 'Reinvestment Profit' deactivate the size will be calculate on the initial capital.2float · min 0.10 · max 100 · step 0.10qty_order
BULLISH ENGULFING
Detect Trend Based OntrendRule1string · options [trendRule1, trendRule2, "No detection"]line 45 line 49
Label Color Bullishcolor.rgb(43, 255, 0)colorline 84

What it calculates

  • SMAclose, 50priceAvg · line 46
  • SMAclose, 200sma200 · line 50
  • SMAclose, 50sma50 · line 51
  • EMAC_Body, C_LenC_BodyAvg · line 62
  • ATR30patternLabelPosLow · line 77
  • ATR30patternLabelPosHigh · line 78

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 datahigh · low · closehigh · low · closeprice datalowlowprice datahighhighprice dataorders_sizeOrders size (%): setting · 2openopenprice dataPROFITTarget profit (%): setting · 1STOPLOSSStop Loss (%): setting · 1timetimeprice datastartYearY: setting · 2022startMonthM: setting · 1startDateD: setting · 1endYearY: setting · 2023endMonthM: setting · 12endDateD: setting · 31priceAvgSMA→ priceAvgsma200SMA→ sma200sma50SMA→ sma50C_BodyAvgEMA→ C_BodyAvgpatternLabelPosLowATR→ patternLabelPosLowpatternLabelPosHighATR→ patternLabelPosHighequity_trades, cequity_trades · c2 valuesqty_orderqty_ordervalueC_BodyHi, C_BodyLoC_BodyHi · C_BodyLo2 valuesC_BodyC_BodyvalueC_UpShadowC_UpShadowvalueC_DnShadowC_DnShadowvalueC_RangeC_RangevalueC_BodyMiddleC_BodyMiddlevalueoovaluec_exitc_exitvaluec_stoplc_stoplvalueinDateRangeinDateRangeconditionC_EngulfingBullishC_EngulfingBullishconditionC_DownTrend, C_UpTrendC_DownTrend · C_UpTrend2 conditionsC_SmallBody, C_LongBodyC_SmallBody · C_LongBody2 conditionsC_HasUpShadowC_HasUpShadowconditionC_HasDnShadowC_HasDnShadowconditionC_WhiteBody, C_BlackBodyC_WhiteBody · C_BlackBo…2 conditionsC_IsInsideBarC_IsInsideBarconditionC_ShadowEqualsC_ShadowEqualsconditionC_IsDojiBodyC_IsDojiBodyconditionC_DojiC_Dojiconditionentry:LONGOpen LONGstrategy.entryexit:CLOSE-LONGexit CLOSE-LONGstrategy.exitbgcolor:85bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open LONG longC_EngulfingBullish and strategy.opentrades==0 and inDateRangeOn95
Exit CLOSE-LONG limitta.crossover(strategy.equity, c_exit)On97
Exit CLOSE-LONG limitta.crossunder(strategy.equity, c_stopl)On99

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%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.

ScriptSharesTypeNetTradesMax drawdown
Buy&Sell Bullish Engulfing - The Quant Science this page—v5 strategy0.0%00.0%
ATR with EOM and VORTEX by SoftKill21atr ema smav4 strategy+66.2%2229.9%
cATRpillar Strategy by Obi-wanClintobeatr sma emav4 strategy+1.02827e+24%2788,097.2%
Optimized Zhaocaijinbao strategy by fzj20020403sma ema atrv5 strategy+15.6%129.8%
EMA & Supertrend by bhavikmotaema sma atrv4 strategy+2,123.6%13980.9%
Koala System EURUSD 15min by SoftKill21sma ema atrv4 strategyNo trades on this market

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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

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.

⋯                                                                                                                                  -//@version=5+//@version=6strategy(⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 33 msWith a workaround 1,000 bars in 61 msNot measured
PineTSNot testedNot testedNot measured

Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 95) so the engine trades the way the script says.

“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/// © thequantscience// ██████╗ ██╗   ██╗██╗     ██╗     ██╗███████╗██╗  ██╗    ███████╗███╗   ██╗ ██████╗ ██╗   ██╗██╗     ███████╗██╗███╗   ██╗ ██████╗ // ██╔══██╗██║   ██║██║     ██║     ██║██╔════╝██║  ██║    ██╔════╝████╗  ██║██╔════╝ ██║   ██║██║     ██╔════╝██║████╗  ██║██╔════╝ // ██████╔╝██║   ██║██║     ██║     ██║███████╗███████║    █████╗  ██╔██╗ ██║██║  ███╗██║   ██║██║     █████╗  ██║██╔██╗ ██║██║  ███╗// ██╔══██╗██║   ██║██║     ██║     ██║╚════██║██╔══██║    ██╔══╝  ██║╚██╗██║██║   ██║██║   ██║██║     ██╔══╝  ██║██║╚██╗██║██║   ██║// ██████╔╝╚██████╔╝███████╗███████╗██║███████║██║  ██║    ███████╗██║ ╚████║╚██████╔╝╚██████╔╝███████╗██║     ██║██║ ╚████║╚██████╔╝// ╚═════╝  ╚═════╝ ╚══════╝╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚══════╝╚═╝  ╚═══╝ ╚═════╝  ╚═════╝ ╚══════╝╚═╝     ╚═╝╚═╝  ╚═══╝ ╚═════╝                                                                                                                                   //@version=5strategy(     "Buy&Sell Bullish Engulfing - The Quant Science",     overlay = true,     default_qty_type = strategy.percent_of_equity,      default_qty_value = 100,     pyramiding = 1,     currency = currency.EUR,     initial_capital = 10000,     commission_type = strategy.commission.percent,     commission_value = 0.07,     process_orders_on_close = true,      close_entries_rule = "ANY"     )startDate  = input.int(title="D: ", defval=1,    minval=1,    maxval=31,   inline = 'Start', group = "START DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")startMonth = input.int(title="M: ", defval=1,    minval=1,    maxval=12,   inline = 'Start', group = "START DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")startYear  = input.int(title="Y: ", defval=2022, minval=1800, maxval=2100, inline = 'Start', group = "START DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")endDate    = input.int(title="D: ", defval=31,   minval=1,    maxval=31,   inline = 'End',   group = "END DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")endMonth   = input.int(title="M: ", defval=12,   minval=1,    maxval=12,   inline = 'End',   group = "END DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")endYear    = input.int(title="Y: ", defval=2023, minval=1800, maxval=2100, inline = 'End',   group = "END DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))PROFIT   = input.float(defval = 1, minval = 0, title = "Target profit (%): ", step = 0.10, group = "TAKE PROFIT-STOP LOSS")STOPLOSS = input.float(defval = 1, minval = 0, title = "Stop Loss (%): ",     step = 0.10, group = "TAKE PROFIT-STOP LOSS")var float equity_trades = 0equity_trades := strategy.initial_capitalvar float equity   = 0var float qty_order   = 0t_ordersize = "Percentage size of each new order. With 'Reinvestment Profit' activate, the size will be calculate on the equity, with 'Reinvestment Profit' deactivate the size will be calculate on the initial capital."orders_size = input.float(defval = 2, title = "Orders size (%): ", minval = 0.10, step = 0.10,  maxval = 100, group = "RISK MANAGEMENT", tooltip = t_ordersize)qty_order := ((equity_trades * orders_size) / 100 ) / close C_DownTrend = trueC_UpTrend   = truevar trendRule1 = "SMA50"var trendRule2 = "SMA50, SMA200"var trendRule = input.string(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"], group = "BULLISH ENGULFING")if trendRule == trendRule1    priceAvg = ta.sma(close, 50)    C_DownTrend := close < priceAvg    C_UpTrend := close > priceAvgif trendRule == trendRule2    sma200 = ta.sma(close, 200)    sma50  = ta.sma(close, 50)    C_DownTrend := close < sma50 and sma50 < sma200    C_UpTrend := close > sma50 and sma50 > sma200C_Len = 14C_ShadowPercent = 5.0 C_ShadowEqualsPercent = 100.0C_DojiBodyPercent = 5.0C_Factor = 2.0 C_BodyHi = math.max(close, open)C_BodyLo = math.min(close, open)C_Body = C_BodyHi - C_BodyLoC_BodyAvg = ta.ema(C_Body, C_Len)C_SmallBody = C_Body < C_BodyAvgC_LongBody = C_Body > C_BodyAvgC_UpShadow = high - C_BodyHiC_DnShadow = C_BodyLo - lowC_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_BodyC_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_BodyC_WhiteBody = open < closeC_BlackBody = open > closeC_Range = high-lowC_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLoC_BodyMiddle = C_Body / 2 + C_BodyLoC_ShadowEquals = C_UpShadow == C_DnShadow or (math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercentC_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100C_Doji = C_IsDojiBody and C_ShadowEqualspatternLabelPosLow  = low  - (ta.atr(30) * 0.6)patternLabelPosHigh = high + (ta.atr(30) * 0.6)label_color_bullish = input.color(color.rgb(43, 255, 0), title = "Label Color Bullish", group = "BULLISH ENGULFING")C_EngulfingBullishNumberOfCandles = 2C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] )if C_EngulfingBullish    var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close."    label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, color = label_color_bullish, textcolor=color.white, tooltip = ttBullishEngulfing)bgcolor(ta.highest(C_EngulfingBullish?1:0, C_EngulfingBullishNumberOfCandles)!=0 ? color.new(#21f321, 90) : na, offset=-(C_EngulfingBullishNumberOfCandles-1))var float c       = 0var float o       = 0var float c_exit  = 0var float c_stopl = 0if C_EngulfingBullish and strategy.opentrades==0 and inDateRange     c := strategy.equity    o := close    c_exit  := c + (c * PROFIT / 100)    c_stopl := c - (c * STOPLOSS / 100)    strategy.entry(id = "LONG", direction = strategy.long, qty = qty_order, limit = o)if ta.crossover(strategy.equity, c_exit)    strategy.exit(id = "CLOSE-LONG", from_entry = "LONG", limit = close)if ta.crossunder(strategy.equity, c_stopl)    strategy.exit(id = "CLOSE-LONG", from_entry = "LONG", limit = close)