Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Double Inside Bar & Trend Strategy - Kaspricci

A Pine Script v5 strategy built on EMA or HMA or SMA or SWMA or VWMA or WMA (close, 45) and ATR (50). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays no commission. 16 settings; defaults include MA Source close, MA Type HMA and HMA Length 45.

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 Double Inside Bar & Trend Strategy - Kaspricci repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Double Inside Bar & Trend Strategy - Kaspricci 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. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
Does Double Inside Bar & Trend Strategy - Kaspricci run in Pine Script v6?
Yes
Same 11 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does Double Inside Bar & Trend Strategy - Kaspricci use a stop loss?
Yes
strategy.exit sets a stop on line 73, 77.
Does Double Inside Bar & Trend Strategy - Kaspricci run in Zeal Terminal?
Yes
It compiles in 33 ms and runs 1,000 bars in 86 ms, in the browser.

BTCUSDT · 1D · default settings

  • Trend MA
  • 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 (16)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$202,527Equity from $100,000
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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
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, $100,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 commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    1 setting has no label

    In the settings dialog useRiskMagmt (line 35) shows an empty name. The labels on this page come from the variable names.

  • 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
Entry Seettings
MA Sourceclosesourcema
MA TypeHMAstring · options ["EMA", "HMA", "SMA", "SWMA", "VWMA", "WMA"]ma
HMA Length45int · min 1ma
Trade Seettings
Stop Loss TypeATRstring · options ["ATR", "FIX"]stopLoss takeProfit
ATR: Length 50int · min 1stopLoss
Factor multiplier for ATR value2.5float · min 0 · step 0.05stopLoss
TP RationMultiplier for Take Profit calculation2.0float · min 0 · step 0.05takeProfit
FIX: Stop Loss 10.0float · min 0 · step 0.5stopLoss
Take Profitin pips20.0float · min 0 · step 0.5takeProfit
Use Risk Magmt (no label in the script)trueboolquantity
Risk in % This will overwrite quantity from startegy settings and calculate the trade size based on stop loss and risk percent1.0float · min 0. · step 0.5quantity
Filter Setings
Filter trades by datesfalsebooldateFilter
Start Date & Timetimestamp("2022-01-01T00:00:00+0000")timedateFilter
End Date & Time timestamp("2099-12-31T23:59:00+0000")timedateFilter
Filter trades by sessionfalseboolsessionFilter
Session0045-2245sessionsessionFilter

What it calculates

  • EMA / HMA / SMA / SWMA / VWMA / WMAMA Source (close), HMA Length (45) · chosen by MA Typema · line 19
  • ATR ATR: Length (50) · chosen by Stop Loss TypestopLoss · line 50

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 datamaTypeMA Typesetting · HMAmaLengthHMA Lengthsetting · 45high · low · closehigh · low · closeprice datastopLossTypeStop Loss Typesetting · ATRatrLength ATR: Length …setting · 50atrFactorFactor setting · 2.5fixStopLoss FIX: Stop Loss …setting · 10.0takeProfitRatio TP Rationsetting · 2.0fixTakeProfitTake Profitsetting · 20.0highhighprice datalowlowprice datariskPercentRisk in % …setting · 1.0timetimeprice datastartDateTime Start Date & Timesetting · timestamp("2022-01-…endDateTime End Date & Time setting · timestamp("2099-12-…session Sessionsetting · 0045-2245maEMA / HMA / SMA / SWMA …→ ma · by MA TypestopLossATR→ stopLoss · by Stop Loss TypetakeProfittakeProfitvaluebuyStopPricebuyStopPricevaluesellStopPricesellStopPricevaluetradeID, currentTradeIDtradeID · currentTradeID2 valuesquantityquantityvaluelongComment, shortCommentlongComment · shortComm…2 valuesdateFilterdateFilterconditionsessionFiltersessionFilterconditiondoubleInsideBardoubleInsideBarconditionentry:tradeID + "L"Open tradeID + "L"strategy.entryexit:tradeID + "SL"exit tradeID + "SL"strategy.exitentry:tradeID + "S"Open tradeID + "S"strategy.entrycancel:currentTradeID + "S"cancel currentTradeID +…strategy.cancelcancel:currentTradeID + "L"cancel currentTradeID +…strategy.cancelplot:26Trend MAplotbgcolor:59bgcolorbgcolorbgcolor:60bgcolorbgcolorbgcolor:61bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open tradeID + "L" long(close > ma)On72
Exit tradeID + "SL" stop and limit(close > ma)On73
Open tradeID + "S" short(close < ma)On76
Exit tradeID + "SL" stop and limit(close < ma)On77
cancel currentTradeID + "S"strategy.opentrades > 0On81
cancel currentTradeID + "L"strategy.opentrades > 0On82

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.

Not measuredAn engine gap, not the scriptThe script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script. The answer comes from the checks on the source alone.
  • 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%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−13.2%+5.5%119%0.2216.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−2.6%+9.8%1926%0.806.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+2.7%+8.4%2438%1.176.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+3.9%+16.7%1443%1.473.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−3.1%+21.5%1527%0.738.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−2.1%+148.3%2030%0.857.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−2.1%+17.1%2030%0.857.2%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
Double Inside Bar & Trend Strategy - Kaspricci this page—v5 strategy0.0%00.0%
Open Close Cross Strategy plus Explorer by roses27sma ema wma vwma atrv4 strategydoes not run in Zeal Terminal
Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalaisma ema hma vwmav5 strategy+1.3%1135.6%
Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] by myncryptosma ema wma atrv5 strategy−47.2%448.6%
Multi MA Trend Following Strategy Template by TradeAutomationema hma sma vwma wma atrv5 strategy+12.3%326.9%
TriautoETF(TQQQ) Short Strategy B1 by BBcomhma vwma emav5 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?

Yes

Same 11 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

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

Where it runs

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

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © Kaspricci//@version=5strategy(     title = "Double Inside Bar & Trend Strategy - Kaspricci",      shorttitle = "Double Inside Bar & Trend",      overlay=true,      initial_capital = 100000,      currency = currency.USD,      default_qty_type = strategy.percent_of_equity,      default_qty_value = 100,      calc_on_every_tick = true,      close_entries_rule = "ANY")// ================================================ Entry Inputs ======================================================================headlineEntry   = "Entry Seettings"maSource        = input.source(defval = close,             group = headlineEntry, title = "MA Source")maType          = input.string(defval = "HMA",             group = headlineEntry, title = "MA Type", options = ["EMA", "HMA", "SMA", "SWMA", "VWMA", "WMA"])maLength        = input.int(   defval = 45,    minval = 1, group = headlineEntry, title = "HMA Length")float ma = switch maType     "EMA"  => ta.ema(maSource,  maLength)    "HMA"  => ta.hma(maSource,  maLength)    "SMA"  => ta.sma(maSource,  maLength)    "SWMA" => ta.swma(maSource)    "VWMA" => ta.vwma(maSource, maLength)    "WMA"  => ta.wma(maSource,  maLength)plot(ma, "Trend MA", color.purple)// ================================================ Trade Inputs ======================================================================headlineTrade   = "Trade Seettings"stopLossType    = input.string(defval = "ATR",                         group = headlineTrade,                 title = "Stop Loss Type",            options = ["ATR", "FIX"])atrLength       = input.int(   defval = 50,   minval = 1,              group = headlineTrade, inline = "ATR", title = "   ATR: Length                 ")atrFactor       = input.float( defval =  2.5, minval = 0, step = 0.05, group = headlineTrade, inline = "ATR", title = "Factor       ",             tooltip = "multiplier for ATR value")takeProfitRatio = input.float( defval =  2.0, minval = 0, step = 0.05, group = headlineTrade,                 title = "            TP Ration",     tooltip = "Multiplier for Take Profit calculation")fixStopLoss     = input.float( defval = 10.0, minval = 0, step = 0.5,  group = headlineTrade, inline = "FIX", title = "   FIX: Stop Loss             ") * 10 // need this in ticksfixTakeProfit   = input.float( defval = 20.0, minval = 0, step = 0.5,  group = headlineTrade, inline = "FIX", title = "Take Profit",               tooltip = "in pips") * 10 // need this in ticksuseRiskMagmt    = input.bool(  defval = true,                          group = headlineTrade, inline = "RM",  title = "")riskPercent     = input.float( defval = 1.0,  minval = 0., step = 0.5, group = headlineTrade, inline = "RM",  title = "Risk in %                ", tooltip = "This will overwrite quantity from startegy settings and calculate the trade size based on stop loss and risk percent") / 100// ================================================ Filter Inputs =====================================================================headlineFilter  = "Filter Setings"// date filterfilterDates     = input.bool(defval = false,                                 group = headlineFilter, title = "Filter trades by dates")startDateTime   = input.time(defval = timestamp("2022-01-01T00:00:00+0000"), group = headlineFilter, title = "       Start Date & Time")endDateTime     = input.time(defval = timestamp("2099-12-31T23:59:00+0000"), group = headlineFilter, title = "       End Date & Time  ")dateFilter      = not filterDates or (time >= startDateTime and time <= endDateTime)// session filterfilterSession   = input.bool(title = "Filter trades by session", defval = false, group = headlineFilter)session         = input.session(title = "       Session", defval = "0045-2245", group = headlineFilter)sessionFilter   = not filterSession or time(timeframe.period, session, timezone = "CET")// ================================================ Trade Entries and Exits =====================================================================// calculate stop lossstopLoss        = switch stopLossType    "ATR" => nz(math.round(ta.atr(atrLength) * atrFactor / syminfo.mintick, 0), 0)    "FIX" => fixStopLoss// calculate take profittakeProfit      = switch stopLossType    "ATR" => math.round(stopLoss * takeProfitRatio, 0)    "FIX" => fixTakeProfitdoubleInsideBar = high[2] > high[1] and high[2] > high[0] and low[2] < low[1] and low[2] < low[0]// highlight mother candel and inside bar candlesbgcolor(doubleInsideBar ? color.rgb(33, 149, 243, 80) : na)bgcolor(doubleInsideBar ? color.rgb(33, 149, 243, 80) : na, offset = -1)bgcolor(doubleInsideBar ? color.rgb(33, 149, 243, 80) : na, offset = -2)var float buyStopPrice  = navar float sellStopPrice = naif (strategy.opentrades == 0 and dateFilter and sessionFilter and doubleInsideBar and barstate.isconfirmed)    buyStopPrice  := high[0] // high of recent candle (second inside bar)    sellStopPrice := low[0] // low of recent candle (second inside bar)    tradeID = str.tostring(strategy.closedtrades + strategy.opentrades + 1)    quantity = useRiskMagmt ? math.round(strategy.equity * riskPercent / stopLoss, 2) / syminfo.mintick : na    commentTemplate = "{0} QTY: {1,number,#.##} SL: {2} TP: {3}"    if (close > ma)        longComment = str.format(commentTemplate, tradeID + "L", quantity, stopLoss / 10, takeProfit / 10)        strategy.entry(tradeID + "L", strategy.long, qty = quantity, stop = buyStopPrice, comment = longComment)        strategy.exit(tradeID + "SL", tradeID + "L", profit = takeProfit, loss = stopLoss, comment_loss = "SL", comment_profit = "TP")    if (close < ma)        shortComment = str.format(commentTemplate, tradeID + "S", quantity, stopLoss / 10, takeProfit / 10)        strategy.entry(tradeID + "S", strategy.short, qty = quantity, stop = sellStopPrice, comment = shortComment)        strategy.exit(tradeID + "SL", tradeID + "S", profit = takeProfit, loss = stopLoss, comment_loss = "SL", comment_profit = "TP")// as soon as the first pending order has been entered the remaing pending order shall be cancelled if strategy.opentrades > 0    currentTradeID = str.tostring(strategy.closedtrades + strategy.opentrades)    strategy.cancel(currentTradeID + "S")    strategy.cancel(currentTradeID + "L")