Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Backtest Custom HiLo Strategy

A Pine Script v4 strategy built on EMA or SMA (high, 34), Highest (high, 34) and Lowest (low, 34). It has 5 order rules, 4 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100.0% of equity and pays no commission. 15 settings; defaults include Start Day 2, Start Month 1 and Start Year 2020.

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 Backtest Custom HiLo Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Backtest Custom HiLo Strategy 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.
Can Backtest Custom HiLo Strategy be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does Backtest Custom HiLo Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Backtest Custom HiLo Strategy run in Zeal Terminal?
Yes
It compiles in 21 ms and runs 1,000 bars in 76 ms, in the browser.

BTCUSDT · 1D · default settings

  • HiLo
  • Buy
  • Sell
  • 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 (15)
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. Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 90, 92, 94, 96) 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, $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 stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses transp =, which v5 removed line 66

    transp = on line 66, 67, 68. v5 folds the transparency into the colour with color.new(c, transp).

  • Note

    Uses long =, which v5 renamed line 90

    long = on line 90, 92, 94, 96. v5 writes it as direction = strategy.long or strategy.short.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames ema → ta.ema, sma → ta.sma, highest → ta.highest, lowest → ta.lowest, sign → math.sign, crossover → ta.crossover, crossunder → ta.crossunder.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 3: //@version=4 → //@version=5
  • Line 12: input(type = input.integer) → input.int()
  • Line 14: input(type = input.integer) → input.int()
  • Line 16: input(type = input.integer) → input.int()
  • Line 19: input(type = input.integer) → input.int()
  • Line 21: input(type = input.integer) → input.int()
20 more edits
  • Line 23: input(type = input.integer) → input.int()
  • Line 26: input(type = input.integer) → input.int()
  • Line 28: input(type = input.integer) → input.int()
  • Line 42: ema → ta.ema
  • Line 42: sma → ta.sma
  • Line 43: ema → ta.ema
  • Line 43: sma → ta.sma
  • Line 44: highest → ta.highest
  • Line 45: lowest → ta.lowest
  • Line 53: sign → math.sign
  • Line 54: sign → math.sign
  • Line 57: crossover → ta.crossover
  • Line 58: crossunder → ta.crossunder
  • Line 66: transp = 0 → color.new(hlColor, 0)
  • Line 67: transp = 0 → color.new(color.green, 0)
  • Line 68: transp = 0 → color.new(color.maroon, 0)
  • Line 90: long = true → direction = strategy.long
  • Line 92: long = false → direction = strategy.short
  • Line 94: long = true → direction = strategy.long
  • Line 96: long = false → direction = strategy.short
⋯// © luyikaibr-//@version=4+//@version=5strategy("Backtest Custom HiLo Strategy", "BTCHiLoS", overlay=true, precision=2,⋯// Configure backtest start date with inputs-startDay = input(title="Start Day", type=input.integer,+startDay = input.int(title="Start Day",     defval=2, minval=1, maxval=31)-startMonth = input(title="Start Month", type=input.integer,+startMonth = input.int(title="Start Month",     defval=1, minval=1, maxval=12)-startYear = input(title="Start Year", type=input.integer,+startYear = input.int(title="Start Year",     defval=2020, minval=1800, maxval=2100)// Set backtest end date with inputs-endDay = input(title="End Day", type=input.integer,+endDay = input.int(title="End Day",     defval=31, minval=1, maxval=31)-endMonth = input(title="End Month", type=input.integer,+endMonth = input.int(title="End Month",     defval=10, minval=1, maxval=12)-endYear = input(title="End Year", type=input.integer,+endYear = input.int(title="End Year",     defval=2020, minval=1800, maxval=2100)     -endHour = input(title="End Hour", type=input.integer,+endHour = input.int(title="End Hour",     defval=17, minval=0, maxval=23)-endMin = input(title="End Minute", type=input.integer,+endMin = input.int(title="End Minute",     defval=0, minval=0, maxval=59)⋯opBoth  = (opType == "Both")-hima = (useEMA ? ema(high, len) : sma(high, len))+hima = (useEMA ? ta.ema(high, len) : ta.sma(high, len))-loma = (useEMA ? ema(low, len) : sma(low, len))+loma = (useEMA ? ta.ema(low, len) : ta.sma(low, len))-hihi = (simpleHiLo ? na: highest(high, len))+hihi = (simpleHiLo ? na: ta.highest(high, len))-lolo = (simpleHiLo ? na: lowest(low, len))+lolo = (simpleHiLo ? na: ta.lowest(low, len))hilo = close⋯hlColor := (close < loma[offset] ? color.red : (close > hima[offset] ? color.green : hlColor[1]))-buyArith  = sign(close - hima[offset])+buyArith  = math.sign(close - hima[offset])-sellArith = sign(close - loma[offset])+sellArith = math.sign(close - loma[offset])buyCond = (close > hima[offset])sellCond = (close < loma[offset])-buy = crossover(buyArith, 0.5)+buy = ta.crossover(buyArith, 0.5)-sell = crossunder(sellArith, -0.5)+sell = ta.crossunder(sellArith, -0.5)buyState = false⋯ -plot(hilo, color=hlColor, linewidth=2, style=plot.style_cross, transp=0, title="HiLo")+plot(hilo, color=color.new(hlColor, 0), linewidth=2, style=plot.style_cross, title="HiLo")-plotshape(enterBuyState,  title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green,textcolor = color.white, transp = 0, size = size.tiny)+plotshape(enterBuyState,  title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.new(color.green, 0),textcolor = color.white, size = size.tiny)-plotshape(enterSellState, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.maroon,textcolor = color.white, transp = 0, size = size.tiny)+plotshape(enterSellState, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.new(color.maroon, 0),textcolor = color.white, size = size.tiny)// See if this bar's time happened on/after start date⋯if (atStartDate and beforeEndDate and buyCond)-    strategy.entry(id="EL", long=true)+    strategy.entry(id="EL", direction = strategy.long)if (atStartDate and beforeEndDate and sellCond)-    strategy.entry(id="ES", long=false)+    strategy.entry(id="ES", direction = strategy.short)if (afterStartDate and beforeEndDate and enterBuyState)-    strategy.entry(id="EL", long=true)+    strategy.entry(id="EL", direction = strategy.long)if (afterStartDate and beforeEndDate and enterSellState)-    strategy.entry(id="ES", long=false)+    strategy.entry(id="ES", direction = strategy.short)              ⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 30: input() → input.bool()
  • Line 31: input() → input.bool()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 34: input() → input.string()
  • Line 36: input() → input.string()
  • Line 38: input() → input.string()
⋯     defval=0, minval=0, maxval=59)-startAtOrigin = input(false, title="Start at Origin")+startAtOrigin = input.bool(false, title="Start at Origin")-endNow = input(false, title="End Now")+endNow = input.bool(false, title="End Now")-len = input(34, title="Length", minval=0)+len = input.int(34, title="Length", minval=0)-offset = input(0, title="Offset", minval=0)+offset = input.int(0, title="Offset", minval=0)-hiloType = input(title="Type", defval="HiLo", options=["HiLo", "HiLo Activator"])+hiloType = input.string(title="Type", defval="HiLo", options=["HiLo", "HiLo Activator"])simpleHiLo = (hiloType == "HiLo")-maType = input(title="MA Type", defval="SMA", options=["SMA", "EMA"])+maType = input.string(title="MA Type", defval="SMA", options=["SMA", "EMA"])useEMA = (maType == "EMA")-opType = input(title="Operation Type", defval="Long", options=["Long", "Short", "Both"])+opType = input.string(title="Operation Type", defval="Long", options=["Long", "Short", "Both"])opShort = (opType != "Long")⋯

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.

⋯// © luyikaibr-//@version=5+//@version=6strategy("Backtest Custom HiLo Strategy", "BTCHiLoS", overlay=true, precision=2,⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Start Day2int (written input.integer) · min 1 · max 31startDate
Start Month1int (written input.integer) · min 1 · max 12startDate
Start Year2020int (written input.integer) · min 1800 · max 2100startDate
End Day31int (written input.integer) · min 1 · max 31endTS
End Month10int (written input.integer) · min 1 · max 12endTS
End Year2020int (written input.integer) · min 1800 · max 2100endTS
End Hour17int (written input.integer) · min 0 · max 23endTS
End Minute0int (written input.integer) · min 0 · max 59endTS
Start at OriginfalseboolafterStartDate atStartDate
End NowfalseboolendTS
Length34int · min 0hima loma hihi lolo
Offset0int · min 0hilo hlColor buyArith sellArith buyCond sellCond
TypeHiLostring · options ["HiLo", "HiLo Activator"]simpleHiLo
MA TypeSMAstring · options ["SMA", "EMA"]useEMA
Operation TypeLongstring · options ["Long", "Short", "Both"]opShort opLong opBoth

What it calculates

  • EMA / SMA (ema, ta.ema in v5)high, Length (34)hima · line 42
  • EMA / SMA (ema, ta.ema in v5)low, Length (34)loma · line 43
  • Highest (highest, ta.highest in v5)high, Length (34)hihi · line 44
  • Lowest (lowest, ta.lowest in v5)low, Length (34)lolo · line 45
  • Crossover (crossover, ta.crossover in v5)buyArith, 0.5buy · line 57
  • Crossunder (crossunder, ta.crossunder in v5)sellArith, -0.5sell · line 58

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.

highhighprice datalenLengthsetting · 34lowlowprice dataclosecloseprice dataoffsetOffsetsetting · 0startYearStart Yearsetting · 2020startMonthStart Monthsetting · 1startDayStart Daysetting · 2endYearEnd Yearsetting · 2020endMonthEnd Monthsetting · 10endDayEnd Daysetting · 31endHourEnd Hoursetting · 17endMinEnd Minutesetting · 0timetimeprice datahiloTypeTypesetting · HiLomaTypeMA Typesetting · SMAopTypeOperation Typesetting · LonghimaEMA / SMA→ himalomaEMA / SMA→ lomahihiHighest→ hihiloloLowest→ lolobuyCrossover→ buysellCrossunder→ sellhilohilovaluebuyArithbuyArithvaluesellArithsellArithvaluebuyStatebuyStatevaluesellStatesellStatevaluestartDatestartDatevalueendTSendTSvaluebuyCondbuyCondconditionsellCondsellCondconditionenterBuyStateenterBuyStateconditionenterSellStateenterSellStateconditionafterStartDateafterStartDateconditionatStartDateatStartDateconditionbeforeEndDatebeforeEndDateconditionsimpleHiLosimpleHiLoconditionuseEMAuseEMAconditionopShort, opLong, opBothopShort · opLong +13 conditionshlColorColourhlColorentry:ELOpen ELstrategy.entryentry:ESOpen ESstrategy.entryclose_all:close_all strategy.close_allplot:66HiLoplotplotshape:67Buyplotshapeplotshape:68Sellplotshape

Order rules

OrderFires whenBy defaultLine
Open EL long(atStartDate and beforeEndDate and buyCond)On90
Open ES short(atStartDate and beforeEndDate and sellCond)On92
Open EL long(afterStartDate and beforeEndDate and enterBuyState)On94
Open ES short(afterStartDate and beforeEndDate and enterSellState)On96
Close (not beforeEndDate and strategy.position_size != 0)On100

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
Backtest Custom HiLo Strategy this page—v4 strategy0.0%00.0%
Forex bot full strategy with risk management by exlux99lowest highest ema smav4 strategy−26.4%1138.9%
ATR + STC + MA by Romediusema lowest highest smav5 strategy−1.2%153.3%
Bagheri IG Ether by Bagheri_IGema highest lowest smav4 strategy+0.0%30.0%
Bagheri IG Ether v2 by Bagheri_IGema highest lowest smav4 strategy−0.0%20.0%
Crunchster's Turtle and Trend System by Crunchster1lowest highest ema smav5 strategy+18.0%3116.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 21 msWith a workaround 1,000 bars in 76 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 90, 92, 94, 96) 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. PineTS runs Pine Script v5 and v6 only.

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/// © luyikaibr//@version=4strategy("Backtest Custom HiLo Strategy", "BTCHiLoS", overlay=true, precision=2,         process_orders_on_close=true,         pyramiding=1,         close_entries_rule="FIFO",         initial_capital=100000,          default_qty_type=strategy.percent_of_equity,         default_qty_value=100.0)// Configure backtest start date with inputsstartDay = input(title="Start Day", type=input.integer,     defval=2, minval=1, maxval=31)startMonth = input(title="Start Month", type=input.integer,     defval=1, minval=1, maxval=12)startYear = input(title="Start Year", type=input.integer,     defval=2020, minval=1800, maxval=2100)// Set backtest end date with inputsendDay = input(title="End Day", type=input.integer,     defval=31, minval=1, maxval=31)endMonth = input(title="End Month", type=input.integer,     defval=10, minval=1, maxval=12)endYear = input(title="End Year", type=input.integer,     defval=2020, minval=1800, maxval=2100)     endHour = input(title="End Hour", type=input.integer,     defval=17, minval=0, maxval=23)endMin = input(title="End Minute", type=input.integer,     defval=0, minval=0, maxval=59)startAtOrigin = input(false, title="Start at Origin")endNow = input(false, title="End Now")len = input(34, title="Length", minval=0)offset = input(0, title="Offset", minval=0)hiloType = input(title="Type", defval="HiLo", options=["HiLo", "HiLo Activator"])simpleHiLo = (hiloType == "HiLo")maType = input(title="MA Type", defval="SMA", options=["SMA", "EMA"])useEMA = (maType == "EMA")opType = input(title="Operation Type", defval="Long", options=["Long", "Short", "Both"])opShort = (opType != "Long")opLong  = (opType != "Short")opBoth  = (opType == "Both")hima = (useEMA ? ema(high, len) : sma(high, len))loma = (useEMA ? ema(low, len) : sma(low, len))hihi = (simpleHiLo ? na: highest(high, len))lolo = (simpleHiLo ? na: lowest(low, len))hilo = closehilo := if simpleHiLo    (close < loma[offset] ? hima : (close > hima[offset] ? loma : hilo[1]))else    (close < loma[offset] ? hihi : (close > hima[offset] ? lolo : hilo[1]))hlColor = color.redhlColor := (close < loma[offset] ? color.red : (close > hima[offset] ? color.green : hlColor[1]))buyArith  = sign(close - hima[offset])sellArith = sign(close - loma[offset])buyCond = (close > hima[offset])sellCond = (close < loma[offset])buy = crossover(buyArith, 0.5)sell = crossunder(sellArith, -0.5)buyState = falsebuyState :=  buy ? true : (sell ? false : buyState[1])sellState = falsesellState :=  buy ? false : (sell ? true : sellState[1])enterBuyState  = buyState[0]  and not buyState[1]enterSellState = sellState[0] and not sellState[1] plot(hilo, color=hlColor, linewidth=2, style=plot.style_cross, transp=0, title="HiLo")plotshape(enterBuyState,  title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green,textcolor = color.white, transp = 0, size = size.tiny)plotshape(enterSellState, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.maroon,textcolor = color.white, transp = 0, size = size.tiny)// See if this bar's time happened on/after start datestartDate = timestamp(syminfo.timezone, startYear, startMonth, startDay, 0, 0)afterStartDate = if startAtOrigin    trueelse    (time >= startDate)atStartDate = if startAtOrigin    falseelse    (time >= startDate and time < (startDate + time_close[1]-time_close[2]))     // See if bar's close time is before end dateendTS = if endNow    timenow - 2*(time_close[1]-time_close[2]) // 86400else    timestamp(syminfo.timezone, endYear, endMonth, endDay, endHour, endMin, 0)beforeEndDate = (time < endTS)// Only submit enter long ordersstrategy.risk.allow_entry_in(opBoth ? strategy.direction.all : (opLong ? strategy.direction.long : strategy.direction.short))// Submit entry orders, but only on/after start dateif (atStartDate and beforeEndDate and buyCond)    strategy.entry(id="EL", long=true)if (atStartDate and beforeEndDate and sellCond)    strategy.entry(id="ES", long=false)if (afterStartDate and beforeEndDate and enterBuyState)    strategy.entry(id="EL", long=true)if (afterStartDate and beforeEndDate and enterSellState)    strategy.entry(id="ES", long=false)              // if (barstate.islast or not beforeEndDate)if (not beforeEndDate and strategy.position_size != 0)    strategy.close_all(comment="End")