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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Entry Seettings | |||
| MA Source | close | source | ma |
| MA Type | HMA | string · options ["EMA", "HMA", "SMA", "SWMA", "VWMA", "WMA"] | ma |
| HMA Length | 45 | int · min 1 | ma |
| Trade Seettings | |||
| Stop Loss Type | ATR | string · options ["ATR", "FIX"] | stopLoss takeProfit |
| ATR: Length | 50 | int · min 1 | stopLoss |
| Factor multiplier for ATR value | 2.5 | float · min 0 · step 0.05 | stopLoss |
| TP RationMultiplier for Take Profit calculation | 2.0 | float · min 0 · step 0.05 | takeProfit |
| FIX: Stop Loss | 10.0 | float · min 0 · step 0.5 | stopLoss |
| Take Profitin pips | 20.0 | float · min 0 · step 0.5 | takeProfit |
| Use Risk Magmt (no label in the script) | true | bool | quantity |
| Risk in % This will overwrite quantity from startegy settings and calculate the trade size based on stop loss and risk percent | 1.0 | float · min 0. · step 0.5 | quantity |
| Filter Setings | |||
| Filter trades by dates | false | bool | dateFilter |
| Start Date & Time | timestamp("2022-01-01T00:00:00+0000") | time | dateFilter |
| End Date & Time | timestamp("2099-12-31T23:59:00+0000") | time | dateFilter |
| Filter trades by session | false | bool | sessionFilter |
| Session | 0045-2245 | session | sessionFilter |
What it calculates
- EMA / HMA / SMA / SWMA / VWMA / WMAMA Source (close), HMA Length (45) · chosen by MA Type
ma · line 19 - ATR ATR: Length (50) · chosen by Stop Loss Type
stopLoss · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open tradeID + "L" long | (close > ma) | On | 72 |
| Exit tradeID + "SL" stop and limit | (close > ma) | On | 73 |
| Open tradeID + "S" short | (close < ma) | On | 76 |
| Exit tradeID + "SL" stop and limit | (close < ma) | On | 77 |
| cancel currentTradeID + "S" | strategy.opentrades > 0 | On | 81 |
| cancel currentTradeID + "L" | strategy.opentrades > 0 | On | 82 |
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% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −13.2% | +5.5% | 11 | 9% | 0.22 | 16.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −2.6% | +9.8% | 19 | 26% | 0.80 | 6.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +2.7% | +8.4% | 24 | 38% | 1.17 | 6.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +3.9% | +16.7% | 14 | 43% | 1.47 | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −3.1% | +21.5% | 15 | 27% | 0.73 | 8.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −2.1% | +148.3% | 20 | 30% | 0.85 | 7.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −2.1% | +17.1% | 20 | 30% | 0.85 | 7.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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Double Inside Bar & Trend Strategy - Kaspricci this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Open Close Cross Strategy plus Explorer by roses27 | sma ema wma vwma atr | v4 strategy | does not run in Zeal Terminal | ||
| Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalai | sma ema hma vwma | v5 strategy | +1.3% | 113 | 5.6% |
| Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] by myncrypto | sma ema wma atr | v5 strategy | −47.2% | 4 | 48.6% |
| Multi MA Trend Following Strategy Template by TradeAutomation | ema hma sma vwma wma atr | v5 strategy | +12.3% | 3 | 26.9% |
| TriautoETF(TQQQ) Short Strategy B1 by BBcom | hma vwma ema | v5 strategy | No 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
VerifiedNothing 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.
⋯// © Kaspricci-//@version=5+//@version=6strategy(⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | With a workaround 1,000 bars in 86 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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")