Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Loft Strategy V4

A Pine Script v5 strategy with no technical-analysis calculation. It has 20 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 100 in cash and pays 0.05% commission. 28 settings; defaults include Kalman Gain: 100.0, Source: close and Beginning Approach(%) 5.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 V4 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 V4 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 V4 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 V4 use a stop loss?
Yes
strategy.exit sets a stop on line 280, 282, 299, 301, 304, 306.
Does Loft Strategy V4 run in Zeal Terminal?
Yes
It compiles in 99 ms and runs 1,000 bars in 104 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 (28)
40,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. 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, $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.

  • 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 219, 220, 225, 226, 230, 231, 239, 240. 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:100.0float · min 1 · max 10000.0 · step 1velo smooth
Source:closesourcedk smooth
Beginning Approach(%)5.0float · min 0.1 · max 30.0 · step 0.1stopPercentMax stopPercent
Final Approach(%)1.0float · min 0.1 · max 30.0 · step 0.1stopPercent line 102 line 117
Approach Decrease Step0.001float · min 0.0 · max 5 · step 0.001stopPercent
Base Order Quantity100.0float · min 0.001orderQty maxOrderSize line 216
Max Safe Order Attemp4int · min 1maxOrderSize
Safe Order Deviation3float · min 1.0 · step 0.1orderQty maxOrderSize
Profit Deviation1.0float · min 1.0 · max 10 · step 0.1tp1 tp2 tp3
Max Take Profit(%)25.0float · max 100 · step 0.1tp1 tp2 tp3
Max Order Quantity10000.0float · min 0.01takeQty1 takeQty2 takeQty3 line 208 line 211 line 214 entry LONG entry SHORT
TP1(%)1.0float · min 0.0 · max 100.0 · step 0.1tp1 line 130 line 141
QT1(%):40int · min 1 · max 100 · step 5takeQty1
TP2(%)3.0float · min 0.0 · max 100.0 · step 0.1tp2
QT2(%):30int · min 1 · max 100 · step 5takeQty2
TP3(%)5.0float · min 0.0 · max 100.0 · step 0.1tp3
QT3(%):30int · min 1 · max 100 · step 5takeQty3
Stop Loss(%)0.0float · min 0.0 · max 100.0 · step 0.1stopLoss line 302
Long Entrytrueboolentry LONG close LONG line 129 line 156 line 206 line 209 line 217 line 229
Short Entrytrueboolentry SHORT close SHORT line 129 line 164 line 206 line 212 line 217 line 238
Safe Stop After TP2trueboolexit LONG exit SHORT line 279 line 298
Safe Stop After TP1falseboolexit LONG exit SHORT line 281 line 300
From Date:1int · min 1 · max 31start
/1int · min 1 · max 12start
/2021int · min 2010start
To__ Date:30int · min 1 · max 31finish
/12int · min 1 · max 12finish
/2022int · 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.

The script has 62 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Close buySignallwindow() and long and (not stoppedOutLong)On219
Open LONG longbuySignallwindow() and long and (not stoppedOutLong)On220
Close sellSignallwindow() and (not long) and (not stoppedOutShort)On225
Open SHORT shortsellSignallwindow() and (not long) and (not stoppedOutShort)On226
Open LONG longbuySignallwindow() and long and (not stoppedOutLong)On230
Close LONGsellSignallwindow() and (not long) and (not stoppedOutShort)On231
Open SHORT shortsellSignallwindow() and (not long) and (not stoppedOutShort)On239
Close SHORTbuySignallwindow() and long and (not stoppedOutLong)On240
Close LONGclose > longProfitPrice1 and tp1 > 0 and isTakeTP1 == falseOn268
Close LONGclose > longProfitPrice2 and tp2 > 0 and isTakeTP2 == falseOn272
Close LONGclose > longProfitPrice3 and tp3 > 0 and isTakeTP3 == falseOn276
Exit LONG stopisTakeTP2 == true and useSafeStop2On280
Exit LONG stopisTakeTP1 == true and useSafeStop1On282
Close SHORTclose < shortProfitPrice1 and tp1 > 0 and isTakeTP1 == falseOn287
Close SHORTclose < shortProfitPrice2 and tp2 > 0 and isTakeTP2 == falseOn291
Close SHORTclose < shortProfitPrice3 and tp3 > 0 and isTakeTP3 == falseOn295
Exit SHORT stopisTakeTP2 == true and useSafeStop2On299
Exit SHORT stopisTakeTP1 == true and useSafeStop1On301
Exit LONG stop( strategy.position_size > 0 )On304
Exit SHORT stop( strategy.position_size < 0 )On306

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.

  • 8 strategy calls use the when = argument (line 219, 220, 225, 226, 230, 231, 239, 240). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 1 setting uses the untyped input() (line 20). 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 20: input() → input.source()
  • Line 219: when = buySignall → if block
  • Line 220: when = buySignall → if block
  • Line 225: when = sellSignall → if block
  • Line 226: when = sellSignall → if block
  • Line 230: when = buySignall → if block
3 more edits
  • Line 231: when = sellSignall → if block
  • Line 239: when = sellSignall → if block
  • Line 240: when = buySignall → if block
⋯gain = input.float(title="Kalman Gain:", defval=100.0, minval=1, maxval=10000.0, step=1)-src = input(defval=close, title='Source:')+src = input.source(defval=close, title='Source:')stopPercentBase = input.float(title='Beginning Approach(%)', defval=5.0, minval=0.1, maxval=30.0, step=0.1)⋯    if long-        strategy.close_all( when = buySignall, comment = exitShortComment)+        if buySignall+            strategy.close_all( comment = exitShortComment)-        strategy.entry("LONG", strategy.long, when = buySignall, qty=math.min(orderQty, maxOrderQty), comment = enterLongComment)+        if buySignall+            strategy.entry("LONG", strategy.long, qty=math.min(orderQty, maxOrderQty), comment = enterLongComment)        stoppedOutLong := true⋯    else-        strategy.close_all(when=sellSignall, comment = exitLongComment)+        if sellSignall+            strategy.close_all(comment = exitLongComment)-        strategy.entry("SHORT", strategy.short, when = sellSignall, qty=math.min(orderQty, maxOrderQty), comment = enterShortComment)+        if sellSignall+            strategy.entry("SHORT", strategy.short, qty=math.min(orderQty, maxOrderQty), comment = enterShortComment)        stoppedOutLong  := false⋯else if(longEntry)-    strategy.entry("LONG", strategy.long,  when = buySignall, qty=math.min(orderQty, maxOrderQty), comment = enterLongComment)+    if buySignall+        strategy.entry("LONG", strategy.long, qty=math.min(orderQty, maxOrderQty), 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, qty=math.min(orderQty, maxOrderQty), comment = enterShortComment)+    if sellSignall+        strategy.entry("SHORT", strategy.short, qty=math.min(orderQty, maxOrderQty), 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.

⋯    //          |___/                                                     -//@version=5+//@version=6strategy(title='Loft Strategy V4', overlay=true, ⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 99 msWith a workaround 1,000 bars in 104 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 V4', overlay=true,      pyramiding=0, default_qty_type=strategy.cash,      default_qty_value=100, initial_capital=10000,      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=100.0, minval=1, maxval=10000.0, step=1)src = input(defval=close, title='Source:')stopPercentBase = input.float(title='Beginning Approach(%)', defval=5.0, minval=0.1, maxval=30.0, step=0.1)stopPercentMin = input.float(title='Final Approach(%)', defval=1.0, minval=0.1, maxval=30.0, step=0.1)downStep = input.float(title='Approach Decrease Step', defval=0.001, minval=0.0, maxval = 5, step=0.001)//stopPercentDeviation = input.float(title="Approach Deviation", defval=1.0, minval=0.1, maxval = 5.0, step=0.1)baseOrderQty = input.float(title="Base Order Quantity", defval=100.0, minval=0.001)maxOrderCount = input.int(title="Max Safe Order Attemp", defval=4, minval=1)priceDeviation = input.float(title="Safe Order Deviation", defval=3, minval=1.0, step=0.1)profitDeviation = input.float(title="Profit Deviation", defval=1.0, minval=1.0, maxval=10, step=0.1)maxTakeProfit = input.float(title="Max Take Profit(%)", defval=25.0, maxval=100, step=0.1)maxOrderQty = input.float(title="Max Order Quantity", defval=10000.0, minval=0.01)baseTP1 = input.float(title="TP1(%)", defval=1.0, minval=0.0, maxval=100.0, step=0.1, inline="0")qt1     = input.int(title="QT1(%):", defval=40, minval=1, maxval=100, step=5, inline="0")baseTP2 = input.float(title="TP2(%)", defval=3.0, minval=0.0, maxval=100.0, step=0.1, inline="1")qt2     = input.int(title="QT2(%):", defval=30, minval=1, maxval=100, step=5, inline="1")baseTP3 = input.float(title="TP3(%)", defval=5.0, minval=0.0, maxval=100.0, step=0.1, inline="2")qt3     = input.int(title="QT3(%):", defval=30, minval=1, maxval=100, step=5, inline="2")initialStopLoss = input.float(title="Stop Loss(%)", defval=0.0, minval=0.0, maxval=100.0, step=0.1)longEntry = input.bool(defval=true, title= 'Long Entry', inline="3")shortEntry = input.bool(defval=true, title='Short Entry', inline="3")useSafeStop2 = input.bool(defval = true, title="Safe Stop After TP2", inline="6")useSafeStop1 = input.bool(defval = false, title="Safe Stop After TP1", inline="6")//---------- backtest range setup ------------fromDay   = input.int(defval = 1, title = "From Date:", minval = 1, maxval = 31, inline="4")fromMonth = input.int(defval = 1, title = "/", minval = 1, maxval = 12, inline="4")fromYear  = input.int(defval = 2021, title = "/", minval = 2010, inline="4")toDay     = input.int(defval = 30, title = "To__ Date:", minval = 1, maxval = 31, inline="5")toMonth   = input.int(defval = 12, title = "/", minval = 1, maxval = 12, inline="5")toYear    = input.int(defval = 2022, title = "/", minval = 2010, inline="5")//------------ 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 order comments ------enterLongComment = ""exitLongComment = ""enterShortComment = ""exitShortComment = ""longTPSL = ""longTP = ""longSL = ""shortTPSL = ""shortTP = ""shortSL = ""//--------- Define global variables -----------var bool long = truevar bool stoppedOutLong = falsevar bool stoppedOutShort = falsevar float kf = 0.0var float velo = 0.0var float orderQty = baseOrderQtyvar float stopLoss = initialStopLossvar bool isProfit = falsevar int barindex = 1var int winCounter = 0var int winCounterBuffer = 0var int failCounter = 0var float tp1 = baseTP1var float tp2 = baseTP2var float tp3 = baseTP3var bool isTakeTP1 = falsevar bool isTakeTP2 = false  var bool isTakeTP3 = false  var bool isLastProfit = truevar float stopPercentMax = stopPercentBasevar float stopPercent = stopPercentBasevar float stopLine = 0.0var labelColor = color.blue//------ 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 ---------//stopPercentMax := isLastProfit ? stopPercentBase : (stopPercentBase * stopPercentDeviation)if long == true    stopLine := kf - (kf * (stopPercent / 100))        if long[1] == true and stopLine <= stopLine[1]        stopLine := stopLine[1]    else if (long[1] == true)        stopPercent := stopPercent - downStep        if(stopPercent < stopPercentMin)            stopPercent := stopPercentMin        if(kf < stopLine)        long := false        stopPercent := stopPercentMax        stopLine := kf + (kf * (stopPercent / 100))        else    stopLine := kf + (kf * (stopPercent / 100))        if long[1] == false and stopLine >= stopLine[1]        stopLine := stopLine[1]    else if(long[1] == false)        stopPercent := stopPercent - downStep        if(stopPercent < stopPercentMin)            stopPercent := stopPercentMin                if(kf > stopLine)        long := true        stopPercent := stopPercentMax        stopLine := kf - (kf * (stopPercent / 100))//------------------- determine buy and sell points ---------------------buySignall = window() and long  and (not stoppedOutLong)sellSignall = window() and (not long)  and (not stoppedOutShort)                                        if longEntry and shortEntry     if buySignall and baseTP1 <= 0.0                    if strategy.position_size < 0            if close < strategy.position_avg_price                isLastProfit := true        else if strategy.position_size == 0            if strategy.wintrades > winCounter //strategy.wintrades[ barindex ]                isLastProfit := true        else            isLastProfit := false            else if sellSignall and baseTP1 <= 0.0                if strategy.position_size > 0            if close > strategy.position_avg_price                isLastProfit := true        else if strategy.position_size == 0            if strategy.wintrades > winCounter //strategy.wintrades[ barindex ]                isLastProfit := true        else            isLastProfit := false        else if isTakeTP2 == true        isLastProfit := true    else        isLastProfit := falseelse if longEntry    if sellSignall        winCounterBuffer := winCounter    if buySignall        if winCounter > winCounterBuffer            isLastProfit := true        else            isLastProfit := falseelse if shortEntry    if buySignall        winCounterBuffer := winCounter    if sellSignall        if winCounter > winCounterBuffer            isLastProfit := true        else            isLastProfit := false    //------------- set the deviations ------------var float maxOrderSize = (baseOrderQty * math.pow(priceDeviation, maxOrderCount - 1))if buySignall or sellSignall        if isLastProfit == false            orderQty := orderQty * priceDeviation                tp1 := tp1 * profitDeviation        tp2 := tp2 * profitDeviation        tp3 := tp3 * profitDeviation                tp1 := math.min(tp1, maxTakeProfit)        tp2 := math.min(tp2, maxTakeProfit)        tp3 := math.min(tp3, maxTakeProfit)                if orderQty > maxOrderSize            failCounter := failCounter + 1            orderQty := baseOrderQty            tp1 := baseTP1            tp2 := baseTP2            tp3 := baseTP3                    else        orderQty := baseOrderQty        tp1 := baseTP1        tp2 := baseTP2        tp3 := baseTP3// ----------------- put debug labels -------------------if orderQty == maxOrderSize    labelColor := color.redelse    labelColor := isLastProfit ? color.lime : color.yellowif longEntry and shortEntry    if buySignall or sellSignall        label.new( x=bar_index, y=high, text="Qty:"+str.tostring(math.min(orderQty, maxOrderQty))+" | Worst Case:"+str.tostring(failCounter) ,color = labelColor  )else if longEntry    if buySignall        label.new( x=bar_index, y=high, text="Qty:"+str.tostring(math.min(orderQty, maxOrderQty))+" | Worst Case:"+str.tostring(failCounter) ,color = labelColor  )else if shortEntry    if sellSignall        label.new( x=bar_index, y=high, text="Qty:"+str.tostring(math.min(orderQty, maxOrderQty))+" | Worst Case:"+str.tostring(failCounter) ,color = labelColor  )//---------- execute the strategy -----------------nz(orderQty, baseOrderQty)if longEntry and shortEntry    if long        strategy.close_all( when = buySignall, comment = exitShortComment)        strategy.entry("LONG", strategy.long, when = buySignall, qty=math.min(orderQty, maxOrderQty), comment = enterLongComment)        stoppedOutLong := true        stoppedOutShort := false                else        strategy.close_all(when=sellSignall, comment = exitLongComment)        strategy.entry("SHORT", strategy.short, when = sellSignall, qty=math.min(orderQty, maxOrderQty), comment = enterShortComment)        stoppedOutLong  := false        stoppedOutShort := trueelse if(longEntry)    strategy.entry("LONG", strategy.long,  when = buySignall, qty=math.min(orderQty, maxOrderQty), comment = enterLongComment)    strategy.close("LONG", when = sellSignall, comment = exitLongComment)    if long         stoppedOutLong := true        stoppedOutShort := false    else        stoppedOutLong  := false        stoppedOutShort := trueelse if(shortEntry)    strategy.entry("SHORT", strategy.short, when = sellSignall, qty=math.min(orderQty, maxOrderQty), comment = enterShortComment)    strategy.close("SHORT", when = buySignall, comment = exitShortComment)    if not long        stoppedOutShort := true        stoppedOutLong  := false    else        stoppedOutShort := false        stoppedOutLong := true//--------- calculate the TP/SL entries -----------longProfitPrice1  = strategy.position_avg_price * (1 + tp1 * 0.01)longProfitPrice2  = strategy.position_avg_price * (1 + tp2 * 0.01)longProfitPrice3  = strategy.position_avg_price * (1 + tp3 * 0.01)        shortProfitPrice1  = strategy.position_avg_price * (1 - tp1 * 0.01)shortProfitPrice2  = strategy.position_avg_price * (1 - tp2 * 0.01)shortProfitPrice3  = strategy.position_avg_price * (1 - tp3 * 0.01)longStopPrice = strategy.position_avg_price * (1 - stopLoss * 0.01)shortStopPrice = strategy.position_avg_price * (1 + stopLoss * 0.01)shortSafeStopPrice2 = strategy.position_avg_price * (1 - 0.2 * 0.01)longSafeStopPrice2 = strategy.position_avg_price * (1 + 0.2 * 0.01)longSafeStopPrice1 = stopLineshortSafeStopPrice1 = stopLine//----------- calculate TP quantity values -----------takeQty1 = math.min(orderQty, maxOrderQty) * qt1 / 100takeQty2 = math.min(orderQty, maxOrderQty) * qt2 / 100takeQty3 = math.min(orderQty, maxOrderQty) * qt3 / 100//----------------- take profit and stop loss processes -----------------if strategy.position_size > 0    if close > longProfitPrice1 and tp1 > 0 and isTakeTP1 == false        strategy.close(id="LONG", qty=takeQty1, comment = "longTP 1")        isTakeTP1 := true        if close > longProfitPrice2 and tp2 > 0 and isTakeTP2 == false        strategy.close(id="LONG", qty=takeQty2, comment = "longTP 2")        isTakeTP2 := true        if close > longProfitPrice3 and tp3 > 0 and isTakeTP3 == false        strategy.close(id="LONG", qty=takeQty3, comment = "longTP 3")        isTakeTP3 := true        if isTakeTP2 == true and useSafeStop2        strategy.exit(id="LONG", stop=longSafeStopPrice2, comment = "Long Safe Stop2")    if isTakeTP1 == true and useSafeStop1        strategy.exit(id="LONG", stop=longSafeStopPrice1, comment = "Long Safe Stop1")                if strategy.position_size < 0    if close < shortProfitPrice1 and tp1 > 0 and isTakeTP1 == false        strategy.close(id="SHORT", qty=takeQty1, comment = "Short TP 1")        isTakeTP1 := true        if close < shortProfitPrice2 and tp2 > 0 and isTakeTP2 == false        strategy.close(id="SHORT", qty=takeQty2, comment = "Short TP 2")        isTakeTP2 := true        if close < shortProfitPrice3 and tp3 > 0 and isTakeTP3 == false        strategy.close(id="SHORT", qty=takeQty3, comment = "Short TP 3")        isTakeTP3 := true        if isTakeTP2 == true and useSafeStop2        strategy.exit(id="SHORT", stop=shortSafeStopPrice2, comment = "Short Safe Stop2")        if isTakeTP1 == true and useSafeStop1        strategy.exit(id="SHORT", stop=shortSafeStopPrice1, comment = "Short Safe Stop1")if(initialStopLoss>0.0)    if ( strategy.position_size > 0 )        strategy.exit(id="LONG",  stop=longStopPrice, comment = "Long Stop Loss")    else if ( strategy.position_size < 0 )        strategy.exit(id="SHORT",  stop=shortStopPrice,  comment = "Short Stop Loss")                if buySignall or sellSignall        isTakeTP1 := false    isTakeTP2 := false      isTakeTP3 := false        winCounter := strategy.wintrades    //------------- plot charts ---------------------lineColor1 = long ? color.green : color.redlineColor2 = long ? color.aqua : color.fuchsiakalmanPlot = plot(kf, color=lineColor1, linewidth=3, title = "Kalman Filter")stopPlot = plot(stopLine, color=lineColor2, linewidth=2, title = "Stop Loss Line")