Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Loft Strategy V1

A Pine Script v5 strategy with no technical-analysis calculation. It has 12 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is 100 contracts and pays 0.05% commission. 15 settings; defaults include Kalman Gain: 1.0, Source: close and Beginning Approach(%): 2.0.

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 Loft Strategy V1 repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Loft Strategy V1 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 Loft Strategy V1 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 Loft Strategy V1 use a stop loss?
Yes
strategy.exit sets a stop on line 121, 123, 132, 134.
Does Loft Strategy V1 run in Zeal Terminal?
Yes
It compiles in 60 ms and runs 1,000 bars in 75 ms, in the browser.

BTCUSDT · 1D · default settings

  • Kalman Filter
  • Stop Loss Line
  • 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. 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.

  • Note

    No slippage

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

  • Note

    Uses an argument v6 removed

    when = on line 96, 100, 104, 105, 111, 112. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Kalman Gain:1.0float · min 1.0 · max 5000.0 · step 100.0velo smooth
Source:closesourcedk smooth
Beginning Approach(%):2.0float · min 0.1 · max 30.0 · step 0.1stopPercent
Final Approach(%): 0.5float · min 0.1 · max 30.0 · step 0.1stopPercent line 62 line 77
Approach Decrease Step:0.005float · min 0.0 · max 5 · step 0.005stopPercent
Take Profit:1.5float · min 0.0 · max 100.0 · step 0.1longProfitPrice shortProfitPrice line 119 line 124
Stop Loss: 0.0float · min 0.0 · max 100.0 · step 0.1longStopPrice shortStopPrice line 119 line 130
Long Entrytrueboolentry LONG close LONG line 94 line 103
Short Entrytrueboolentry SHORT close SHORT line 94 line 110
From Day1int · min 1 · max 31start
From Month1int · min 1 · max 12start
From Year2021int · min 2010start
To Day30int · min 1 · max 31finish
To Month12int · min 1 · max 12finish
To Year2022int · min 2010finish

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

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.

fromYearFrom Yearsetting · 2021fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1toYearTo Yearsetting · 2022toMonthTo Monthsetting · 12toDayTo Daysetting · 30gainKalman Gain:setting · 1.0closecloseprice datastopPercentMaxBeginning Approach(%):setting · 2.0downStepApproach Decrease Step:setting · 0.005stopPercentMinFinal Approach(%): setting · 0.5tpTake Profit:setting · 1.5slStop Loss: setting · 0.0startstartvaluefinishfinishvaluekfkfvaluevelovelovaluedkdkvaluesmoothsmoothvaluestopPercentstopPercentvaluestopLossstopLossvaluelongProfitPrice, shortProfitPricelongProfitPrice · short…2 valueslongStopPrice, shortStopPricelongStopPrice · shortSt…2 valuesbuySignallbuySignallconditionsellSignallsellSignallconditionlineColor1, lineColor2ColourlineColor1 · lineColor2entry:LONGOpen LONGstrategy.entryentry:SHORTOpen SHORTstrategy.entryclose:LONGClose LONGstrategy.closeclose:SHORTClose SHORTstrategy.closeexit:LONGexit LONGstrategy.exitexit:SHORTexit SHORTstrategy.exitplot:139Kalman Filterplotplot:140Stop Loss Lineplot

Order rules

OrderFires whenBy defaultLine
Open LONG longbuySignallwindow() and long and (not stoppedOutLong)On96
Open SHORT shortsellSignallwindow() and (not long) and (not stoppedOutShort)On100
Open LONG longbuySignallwindow() and long and (not stoppedOutLong)On104
Close LONGsellSignallwindow() and (not long) and (not stoppedOutShort)On105
Open SHORT shortsellSignallwindow() and (not long) and (not stoppedOutShort)On111
Close SHORTbuySignallwindow() and long and (not stoppedOutLong)On112
Exit LONG stop and limit( strategy.position_size > 0 )On121
Exit SHORT stop and limit( strategy.position_size < 0 )On123
Exit LONG limit( strategy.position_size > 0 )On126
Exit SHORT limit( strategy.position_size < 0 )On128
Exit LONG stop( strategy.position_size > 0 )On132
Exit SHORT stop( strategy.position_size < 0 )On134

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

No other indicator or strategy here shares enough of its calculations.

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 strategy calls use the when = argument (line 96, 100, 104, 105, 111, 112). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 1 setting uses the untyped input() (line 12). 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 12: input() → input.source()
  • Line 96: when = buySignall → if block
  • Line 100: when = sellSignall → if block
  • Line 104: when = buySignall → if block
  • Line 105: when = sellSignall → if block
  • Line 111: when = sellSignall → if block
  • Line 112: when = buySignall → if block
⋯gain = input.float(title="Kalman Gain:", defval=1.0, minval=1.0, maxval=5000.0, step=100.0)-src = input(defval=close, title='Source:')+src = input.source(defval=close, title='Source:')stopPercentMax = input.float(title='Beginning Approach(%):', defval=2.0, minval=0.1, maxval=30.0, step=0.1)⋯    if long -        strategy.entry("LONG", strategy.long, when = buySignall, comment = enterLongComment)+        if buySignall+            strategy.entry("LONG", strategy.long, comment = enterLongComment)        stoppedOutLong := true⋯    else -        strategy.entry("SHORT", strategy.short, when = sellSignall, comment = enterShortComment)+        if sellSignall+            strategy.entry("SHORT", strategy.short, comment = enterShortComment)        stoppedOutLong  := false⋯else if(longEntry)-    strategy.entry("LONG", strategy.long,  when = buySignall, comment = enterLongComment)+    if buySignall+        strategy.entry("LONG", strategy.long, comment = enterLongComment)-    strategy.close("LONG", when = sellSignall, comment = exitLongComment)+    if sellSignall+        strategy.close("LONG", comment = exitLongComment)    if long ⋯else if(shortEntry)-    strategy.entry("SHORT", strategy.short, when = sellSignall, comment = enterShortComment)+    if sellSignall+        strategy.entry("SHORT", strategy.short, comment = enterShortComment)-    strategy.close("SHORT", when = buySignall, comment = exitShortComment)+    if buySignall+        strategy.close("SHORT", comment = exitShortComment)    if not 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.

⋯// © BigCoinHunter-//@version=5+//@version=6strategy(title='Loft Strategy V1', overlay=true, ⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 60 msWith a workaround 1,000 bars in 75 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/// © BigCoinHunter//@version=5strategy(title='Loft Strategy V1', overlay=true,      pyramiding=0, default_qty_type=strategy.fixed,      default_qty_value=100, initial_capital=100000,      currency=currency.USD, commission_value=0.05,      commission_type=strategy.commission.percent,      process_orders_on_close=true)//-------------- fetch user inputs ------------------gain = input.float(title="Kalman Gain:", defval=1.0, minval=1.0, maxval=5000.0, step=100.0)src = input(defval=close, title='Source:')stopPercentMax = input.float(title='Beginning Approach(%):', defval=2.0, minval=0.1, maxval=30.0, step=0.1)stopPercentMin = input.float(title='Final Approach(%):    ', defval=0.5, minval=0.1, maxval=30.0, step=0.1)downStep = input.float(title='Approach Decrease Step:', defval=0.005, minval=0.0, maxval = 5, step=0.005)tp = input.float(title="Take Profit:", defval=1.5, minval=0.0, maxval=100.0, step=0.1) * 0.01sl = input.float(title="Stop Loss:  ", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01longEntry = input.bool(defval=true, title= 'Long Entry', inline="11")shortEntry = input.bool(defval=true, title='Short Entry', inline="11")//---------- backtest range setup ------------fromDay   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear  = input.int(defval = 2021, title = "From Year", minval = 2010)toDay     = input.int(defval = 30, title = "To Day", minval = 1, maxval = 31)toMonth   = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)toYear    = input.int(defval = 2022, title = "To Year", minval = 2010)//------------ time interval setup -----------start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)  // backtest start windowfinish    = timestamp(toYear, toMonth, toDay, 23, 59)        // backtest finish windowwindow()  => time >= start and time <= finish ? true : false // create function "within window of time"//------- define the global variables ------enterLongComment = "ENTER LONG"exitLongComment = "EXIT LONG"enterShortComment = "ENTER SHORT"exitShortComment = "EXIT SHORT"longTPSL = "Long TP/SL"longTP = "Long TP"longSL = "Long SL"shortTPSL = "Short TP/SL"shortTP = "Short TP"shortSL = "Short SL"var bool long = truevar bool stoppedOutLong = falsevar bool stoppedOutShort = falsevar float kf = 0.0var float velo = 0.0//------ kalman filter calculation --------dk = src - nz(kf[1], src)smooth = nz(kf[1], src) + dk * math.sqrt(gain / 10000 * 2)velo := nz(velo[1], 0) + gain / 10000 * dkkf := smooth + velo//--------- calculate the loft stopLoss line ---------var stopPercent = stopPercentMaxvar stopLoss = kf - kf * (stopPercent /100)if long == true    stopLoss := kf - (kf * (stopPercent / 100))        if long[1] == true and stopLoss <= stopLoss[1]        stopLoss := stopLoss[1]    else if (long[1] == true)        stopPercent := stopPercent - downStep        if(stopPercent < stopPercentMin)            stopPercent := stopPercentMin        if(kf < stopLoss)        long := false        stopPercent := stopPercentMax        stopLoss := kf + (kf * (stopPercent / 100))        else    stopLoss := kf + (kf * (stopPercent / 100))        if long[1] == false and stopLoss >= stopLoss[1]        stopLoss := stopLoss[1]    else if(long[1] == false)        stopPercent := stopPercent - downStep        if(stopPercent < stopPercentMin)            stopPercent := stopPercentMin                if(kf > stopLoss)        long := true        stopPercent := stopPercentMax        stopLoss := kf - (kf * (stopPercent / 100))        //--------- calculate the input/output points -----------longProfitPrice  = strategy.position_avg_price * (1 + tp)     // tp -> take profit percentagelongStopPrice = strategy.position_avg_price * (1 - sl)        // sl -> stop loss percentageshortProfitPrice  = strategy.position_avg_price * (1 - tp)shortStopPrice = strategy.position_avg_price * (1 + sl)//------------------- determine buy and sell points ---------------------buySignall = window() and long  and (not stoppedOutLong)sellSignall = window() and (not long)  and (not stoppedOutShort)//---------- execute the strategy -----------------if(longEntry and shortEntry)    if long         strategy.entry("LONG", strategy.long, when = buySignall, comment = enterLongComment)        stoppedOutLong := true        stoppedOutShort := false    else         strategy.entry("SHORT", strategy.short, when = sellSignall, comment = enterShortComment)        stoppedOutLong  := false        stoppedOutShort := trueelse if(longEntry)    strategy.entry("LONG", strategy.long,  when = buySignall, comment = enterLongComment)    strategy.close("LONG", when = sellSignall, comment = exitLongComment)    if long         stoppedOutLong := true    else        stoppedOutLong  := falseelse if(shortEntry)    strategy.entry("SHORT", strategy.short, when = sellSignall, comment = enterShortComment)    strategy.close("SHORT", when = buySignall, comment = exitShortComment)    if not long        stoppedOutShort := true    else        stoppedOutShort := false    //----------------- take profit and stop loss -----------------if(tp>0.0 and sl>0.0)    if ( strategy.position_size > 0 )        strategy.exit(id="LONG", limit=longProfitPrice, stop=longStopPrice, comment = longTPSL)    else if ( strategy.position_size < 0 )        strategy.exit(id="SHORT", limit=shortProfitPrice, stop=shortStopPrice, comment = shortTPSL)else if(tp>0.0)    if ( strategy.position_size > 0 )        strategy.exit(id="LONG", limit=longProfitPrice, comment = longTP)    else if ( strategy.position_size < 0 )        strategy.exit(id="SHORT", limit=shortProfitPrice, comment = shortTP)        else if(sl>0.0)    if ( strategy.position_size > 0 )        strategy.exit(id="LONG",  stop=longStopPrice, comment = longSL)    else if ( strategy.position_size < 0 )        strategy.exit(id="SHORT",  stop=shortStopPrice, comment = shortSL)        //------------- plot charts ---------------------lineColor1 = long ? color.green : color.redlineColor2 = long ? color.aqua : color.fuchsiakalmanLine = plot(kf, color=lineColor1, linewidth=3, title = "Kalman Filter")stopLine = plot(stopLoss, color=lineColor2, linewidth=2, title = "Stop Loss Line")