Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

LowFinder_PyraMider_V2

A Pine Script v5 strategy built on RMA (change_mtf, 0, len*mtf), EMA (vrsi, 26) and Crossover (cc, 0). It has 5 order rules, 2 entries among them, and trades long only with the default settings. Exits use a profit target and no stop loss. Each trade commits 10% of equity and pays 0.06% commission. 35 settings; defaults include Precision 4, Portfolio % 100 and Leverage 1.

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 LowFinder_PyraMider_V2 repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 10 of 10 trades.
How did LowFinder_PyraMider_V2 do on BTCUSDT 1D with default settings?
+1.90%
From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does LowFinder_PyraMider_V2 run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 15 before, 15 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does LowFinder_PyraMider_V2 use a stop loss?
No
Its exits set a profit target but no stop.
Does LowFinder_PyraMider_V2 run in Zeal Terminal?
Yes
It compiles in 57 ms and runs 1,000 bars in 154 ms, in the browser.

BTCUSDT · 1D · default settings

  • Average Price
  • Stop Level
  • Take Profit Level
  • 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 (35)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,190$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. Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 170) so the engine trades the way the script says.
Net profit
+1.90%
$189.69
Buy and hold
+102.5%
same period
Closed trades
15
13 won · 2 lost
Profitable
86.7%
of closed trades
Profit factor
13.41
gross profit ÷ gross loss
Max drawdown
0.81%
−$81.87

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.

  • Check

    No stop loss

    strategy.exit is used without a stop, loss or trailing stop.

  • Note

    2 settings have no label

    In the settings dialog stopLoss (line 39), exit_mode (line 46) show an empty name. The labels on this page come from the variable names.

Settings

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

SettingDefaultType and rangeFeeds
Backtest Window
Start Timetimestamp("01 April 2021 20:00")timeline 29
End Timetimestamp("01 Aug 2030 20:00")timeline 29
Strtaegy Properties
PrecisionSpecifies the number of digits after the floating point of the script's displayed values.4int · min 0 · max 16line 87 entry L_1
Risk - Portfolio
Portfolio %100float · step 1.0iq q
Leverage1int · min 1iq q
Risk - Order Size
Order Size ModeBase mode: the base quantiy for each sequential order. Multiply mode: each quantity is multiplied by order numbermultiplystring · options ['base', 'multiply']entry_comment line 76 line 87 entry entry_id
Order Size Divider (Multiply Mode)Divide Multiply by this number to lower the sequential order sizes1intnq line 87
Fixed Order SizeUse with caution! Overrides all Risk calculationsfalseboolline 74
. . Base Currency:1floatq
Risk - Stop Loss
StopLoss offalseboolclose_all StopLoss Stop Loss line 184
Stop Loss (no label in the script)1.5float · step 0.1loss_equity loss_avg_price
% ofequitystring · options ['avg_price', 'equity']stop_loss
Risk - Stop Level
Stop Level LengthLookback most recent highest high100intstop_long1_level stop_long2_level stop_long3_level stop_long4_level
Deviatation % above Stop Level0.3float · step 0.1stop_long1_level stop_long2_level stop_long3_level
Risk - Take Profit
Take Profit/Trailing Stoptrueboolexit_conditions plot_trailing_stop plot_tp_level close_all Exit All line 181
..........%1.0float · step 0.1exit_condition_2 tp_exit plot_trailing_stop plot_tp_level
Exit Crossover Take Profit and .....trueboolclose_all Exit All line 181
Exit mode (no label in the script)stoplevelstring · options ['close', 'stoplevel']ex_m
Take Profit % per OrderEach separate order exits when hit10.0float · step 0.1take_profit_price
Pyramiding Settings
Max Number of Orders12intiq q entry entry_id line 79 line 167
Next Order % below Avg. Price0.2float · step 0.1below_avg
Next Order after X candlesPrevents opening too much orders in a Row0intentry entry_id line 167
MTF LowFinder Settings
Lookback of RSI5intvrsi
Higher TimeFrame Multiplier RSIMultiplies the current timeframe by specified value1intvrsi
MA Length / Sensitivity26intpp
First Order % below LowOpen % lower then the found low0.1float · step 0.1entry_price
Moving Average Filter
Moving Average Length100intmoving_average_signal
MTF Stochastic Filter
K14int · min 1k mtfK mtfD
D3int · min 1d
Smooth3int · min 1k
MTF Stoch Filter (above gets filtered)30intbuy_signal
Higher TimeFrame MultiplierMultiplies the current timeframe by specified value10intmtfK mtfD
Plots
Plot Average PricetrueboolAverage Price
Plot Moving AveragefalseboolMoving Average
Plot Trailing Stop Levelfalseboolplot_trailing_stop

What it calculates

  • RMAmath.max(change_mtf, 0), len*mtfup_mtf · line 92
  • RMA-math.min(change_mtf, 0), len*mtfdown_mtf · line 93
  • EMAvrsi, MA Length / Sensitivity (26)pp · line 97
  • Crossovercc, 0lows · line 100
  • SMA / Stochta.stoch(source, high, low, periodK * mtf), smoothK * mtfk · line 106
  • SMAk, periodD * mtfd · line 107
  • SMAclose, Moving Average Length (100)moving_average_signal · line 114
  • Highesthigh, Stop Level Length (100)stop_long1_level · line 127
  • Highesthigh, Stop Level Length (100)stop_long2_level · line 128
  • Highesthigh, Stop Level Length (100)stop_long3_level · line 129
  • Highesthigh, Stop Level Length (100)stop_long4_level · line 130
  • Crossoverclose, stop_long1_levelstop_long1 · line 132
  • Crossoverclose, stop_long2_levelstop_long2 · line 133
  • Crossunderclose, stop_long4_levelstop_long4 · line 134

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 80 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open L_1 longta.crossunder(close,entry_price) and window() and strategy.position_size == 0On162
Open entry_id longstrategy.opentrades == i and i < posCount and order_after > oa_lookbackOn170
Exit exit_id limitstrategy.opentrades > 0 and window()On178
Close Exit Allexit_conditions or (tp_exit and tp_on and cond2_toggle) and window()On182
Close StopLossta.crossunder(close,stop_loss) and sl_on and window()On185

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, and the live replay matched history.

10/10trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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 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 1D+1.9%+102.5%1587%13.410.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.5%+5.5%3100%—0.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+3.8%+9.8%2871%3.172.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%3100%74.810.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+3.4%+16.7%2778%3.372.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.6%+21.5%5100%856.290.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+3.8%+148.3%2396%17.791.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.4%+17.1%786%155.021.4%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market0—$0.00
Sideways market4100%$73.63
Falling market1182%$116.06

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

0.2%

The 95th percentile of the worst drawdown when the same 15 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.1% to 0.2%; the tick is what actually happened, 0.1%. Order luck alone moves it this much.

0%1%
All 15 trades
SideEntryExitBarsP&L
long20 Nov 2025 91,555.0013 Jan 2026 95,959.6054$5.15
long24 Nov 2025 86,830.0013 Jan 2026 95,959.6050$12.63
long24 Nov 2025 86,830.0014 Jan 2026 97,404.8051$12.56
long17 Dec 2025 87,863.4014 Jan 2026 97,404.8028$24.52
long17 Dec 2025 87,863.4017 Mar 2026 75,476.5090−$14.98
long7 Feb 2026 70,580.3017 Mar 2026 75,476.5038$16.83
long26 Feb 2026 67,988.0017 Mar 2026 75,476.5019$2.96
long26 Feb 2026 67,988.0013 Apr 2026 73,871.5046$19.13
long26 Feb 2026 67,988.0017 Apr 2026 78,095.7050$14.03
long31 Mar 2026 66,797.4017 Apr 2026 78,095.7017$23.54
long31 Mar 2026 66,797.4021 Jul 2026 66,622.80112−$0.31
long27 Jun 2026 60,097.3021 Jul 2026 66,622.8024$16.12
long27 Jun 2026 60,097.3021 Jul 2026 66,785.8024$7.93
long30 Jun 2026 60,260.2021 Jul 2026 66,785.8021$27.73
long30 Jun 2026 60,260.2026 Aug 2026 78,539.1057$21.83

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
LowFinder_PyraMider_V2 this page—v5 strategy+1.9%150.8%
PB Trend Scalper by PatrickGwynBuckleyema rma stoch highestv5 strategy−16.9%1068.3%
Bagheri IG Ether by Bagheri_IGema highest rma smav4 strategy+0.0%30.0%
Bagheri IG Ether v2 by Bagheri_IGema highest rma smav4 strategy−0.0%20.0%
Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10ksma ema rmav4 strategy−19.4%3670.0%
Slight Swing Momentum Strategy. by fzj20020403sma highest emav5 strategy+3.1%70.6%

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?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 15 before, 15 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © A3Sh-//@version=5+//@version=6// Strategy that finds potential lows in the price action and spreads the risk by entering multiple positions at these lows.⋯

Where it runs

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

Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 170) 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.

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/// © A3Sh//@version=5// Strategy that finds potential lows in the price action and spreads the risk by entering multiple positions at these lows.// The low is detected based on the difference between MTF RSI and EMA based RSI, Moving Average and MTF Stochastic indicators.// The size of each next position that is entered is multiplied by the sequential number of the position.// Each separate position can exit when a specified take profit is triggered and re-open when detecting a new potential low.// All positions are closed when the price action crosses over the dynamic blue stop level line.// Additionally a take profit / trailing stop and a stop loss can be activated to lower the risk.// This strategy combines open-source code developed by fellow Tradingview community members: // The Lowfinder code is developed by RafaelZioni// https://www.tradingview.com/script/GzKq2RVl-Low-finder/// Both the MTF RSI code and the MTF Stochastic code are adapted from the MTFindicators libary written by Peter_O// https://www.tradingview.com/script/UUVWSpXR-MTFindicators/// The Stop Level calculation is inspired by the syminfo-mintick tutorial on Kodify.net// https://kodify.net/tradingview/info/syminfo-mintick/strategy("LowFinder_PyraMider",          overlay=true, pyramiding=99,          initial_capital=10000,          default_qty_type=strategy.percent_of_equity,          default_qty_value=10,         commission_type=strategy.commission.percent,          commission_value=0.06,         slippage=1         )// Backtest Windowstart_time   = input.time(defval=timestamp("01 April 2021 20:00"), group = "Backtest Window", title="Start Time")end_time     = input.time(defval=timestamp("01 Aug 2030 20:00"),   group = "Backtest Window", title="End Time")window() => time >= start_time and time <= end_time// Inputsprec            = input.int    (4,           group = 'Strtaegy Properties',    title = 'Precision', minval = 0, maxval = 16, tooltip = "Specifies the number of digits after the floating point of the script's displayed values.")portfolio_size  = input.float  (100,         group = 'Risk - Portfolio',       title = 'Portfolio %', step=1.0) / 100leverage        = input.int    (1,           group = 'Risk - Portfolio',       title = 'Leverage', minval = 1)q_mode          = input.string ('multiply',  group = 'Risk - Order Size',      title = 'Order Size Mode', options = ['base', 'multiply'], tooltip = 'Base mode: the base quantiy for each sequential order. Multiply mode: each quantity is multiplied by order number')q_mode_m        = input.int    (1,           group = 'Risk - Order Size',      title = 'Order Size Divider (Multiply Mode)',  tooltip = 'Divide Multiply by this number to lower the sequential order sizes')fixed_q         = input.bool   (false,       group = 'Risk - Order Size',      title = 'Fixed Order Size',     inline = '01', tooltip = 'Use with caution! Overrides all Risk calculations')amount_q        = input.float  (1,           group = 'Risk - Order Size',      title = '. . Base Currency:',   inline = '01')sl_on           = input.bool   (false,       group = 'Risk - Stop Loss',       title = 'StopLoss of',          inline = '03')stopLoss        = input.float  (1.5,         group = 'Risk - Stop Loss',       title = '',   step=0.1,         inline = '03') / 100sl_mode         = input.string ('equity',    group = 'Risk - Stop Loss',       title = '% of',  options = ['avg_price', 'equity'], inline = '03')stop_len        = input.int    (100,         group = 'Risk - Stop Level',      title = 'Stop Level Length', tooltip = 'Lookback most recent highest high')stop_deviation  = input.float  (0.3,         group = 'Risk - Stop Level',      title = 'Deviatation % above Stop Level', step=0.1) / 100cond2_toggle    = input.bool   (true ,       group = 'Risk - Take Profit',     title = 'Take Profit/Trailing Stop', inline = '04')tp_all          = input.float  (1.0,         group = 'Risk - Take Profit',     title = '..........%', step=0.1,     inline = '04') / 100tp_on           = input.bool   (true,        group = 'Risk - Take Profit',     title = 'Exit Crossover Take Profit and .....', inline = '02')exit_mode       = input.string ('stoplevel', group = 'Risk - Take Profit',     title = '',   options = ['close', 'stoplevel'], inline = '02')takeProfit      = input.float  (10.0,        group = 'Risk - Take Profit',     title = 'Take Profit % per Order', tooltip = 'Each separate order exits when hit', step=0.1)posCount        = input.int    (12,          group = 'Pyramiding Settings',    title = 'Max Number of Orders')next_entry      = input.float  (0.2,         group = 'Pyramiding Settings',    title = 'Next Order % below Avg. Price', step=0.1)oa_lookback     = input.int    (0,           group = 'Pyramiding Settings',    title = 'Next Order after X candles', tooltip = 'Prevents opening too much orders in a Row')len_rsi         = input.int    (5,           group = 'MTF LowFinder Settings', title = 'Lookback of RSI')mtf_rsi         = input.int    (1,           group = 'MTF LowFinder Settings', title = 'Higher TimeFrame Multiplier RSI',  tooltip='Multiplies the current timeframe by specified value')ma_length       = input.int    (26,          group = 'MTF LowFinder Settings', title = 'MA Length / Sensitivity')new_entry       = input.float  (0.1,         group = 'MTF LowFinder Settings', title = 'First Order % below Low',step=0.1, tooltip = 'Open % lower then the found low')/100ma_signal       = input.int    (100,         group = 'Moving Average Filter',  title = 'Moving Average Length')periodK         = input.int    (14,          group = 'MTF Stochastic Filter',  title = 'K',      minval=1)periodD         = input.int    (3,           group = 'MTF Stochastic Filter',  title = 'D',      minval=1)smoothK         = input.int    (3,           group = 'MTF Stochastic Filter',  title = 'Smooth', minval=1)lower           = input.int    (30,          group = 'MTF Stochastic Filter',  title = 'MTF Stoch Filter (above gets filtered)')mtf_stoch       = input.int    (10,          group = 'MTF Stochastic Filter',  title = 'Higher TimeFrame Multiplier', tooltip='Multiplies the current timeframe by specified value')avg_on          = input.bool   (true,        group = 'Plots',                  title = 'Plot Average Price')plot_ma         = input.bool   (false,       group = 'Plots',                  title = 'Plot Moving Average')plot_ts         = input.bool   (false,       group = 'Plots',                  title = 'Plot Trailing Stop Level')// variables //var entry_price     = 0.0    // The entry price of the first entryvar iq              = 0.0    // Inititial order quantity before risk calculationvar nq              = 0.0    // Updated new quantity after the loopvar oq              = 0.0    // Old quantity at the beginning or the loopvar q               = 0.0    // Final calculated quantity used as base order sizevar int order_after = 0      // Candle counter. Prevent opening too much orders in a row// Order size calaculations // // Order size based on max amount of pyramiding orders or fixed by user input ///// Order size calculation based on 'base' mode or ' multiply' mode //if fixed_q    q := amount_qelse if q_mode == 'multiply'    iq := (math.abs(strategy.equity * portfolio_size  / posCount) / open) * leverage    oq := iq    for i = 0 to posCount        nq := oq + (iq * ( i/ q_mode_m + 1))        oq := nq     q := (iq  * posCount /  oq) * iqelse    q := (math.abs(strategy.equity * portfolio_size  / posCount) / open) * leverage// Function to calcaulate final order size based on order size modes and round the result with 1 decimal //quantity_mode(index,string q_mode) =>    q_mode == 'base' ? math.round(q,prec) : q_mode == 'multiply' ? math.round(q * (index/q_mode_m  + 1),prec) : na// LowFinder Calculations //// MTF RSI by Peter_O //rsi_mtf(float source, simple int mtf,simple int len) =>    change_mtf=source-source[mtf]    up_mtf = ta.rma(math.max(change_mtf, 0), len*mtf)    down_mtf = ta.rma(-math.min(change_mtf, 0), len*mtf)    rsi_mtf = down_mtf == 0 ? 100 : up_mtf == 0 ? 0 : 100 - (100 / (1 + up_mtf / down_mtf))// Lowfinder by RafaelZioni //vrsi = rsi_mtf(close,mtf_rsi,len_rsi)pp=ta.ema(vrsi,ma_length)dd=(vrsi-pp)*5cc=(vrsi+dd+pp)/2lows=ta.crossover(cc,0) // MTF Stoch Calcualation // MTF Stoch adapted from  Peter_O //stoch_mtfK(source, mtf, len) =>    k = ta.sma(ta.stoch(source, high, low, periodK * mtf), smoothK * mtf)    stoch_mtfD(source, mtf, len) =>    k = ta.sma(ta.stoch(source, high, low, periodK * mtf), smoothK * mtf)    d = ta.sma(k, periodD * mtf)    mtfK = stoch_mtfK(close, mtf_stoch, periodK)mtfD = stoch_mtfD(close, mtf_stoch, periodK)// Open next position % below average position price //below_avg = close < (strategy.position_avg_price * (1 - (next_entry / 100)))// Moving Average Filter //moving_average_signal = ta.sma(close, ma_signal)plot (plot_ma ? moving_average_signal : na, title = 'Moving Average', color = color.rgb(154, 255, 72))// Buy Signal //buy_signal = lows and close < moving_average_signal and mtfK < lower// First Entry % Below lows //if buy_signal    entry_price := close * (1 - new_entry)// Plot Average Price of Position//plot (avg_on  ? strategy.position_avg_price : na, title = 'Average Price', style = plot.style_linebr, color = color.new(color.white,0), linewidth = 1)// Take profit per Open Order //take_profit_price = close * takeProfit / 100 / syminfo.mintick// Calculate different Stop Level conditions to exit All //// Stop Level Caculation //stop_long1_level = ta.highest (high, stop_len)[1]  * (1 + stop_deviation)stop_long2_level = ta.highest (high, stop_len)[2]  * (1 + stop_deviation)stop_long3_level = ta.highest (high, stop_len)[3]  * (1 + stop_deviation)stop_long4_level = ta.highest (high, stop_len)[1]  * (1 - 0.008) // Stop triggers //stop_long1 = ta.crossover(close,stop_long1_level)stop_long2 = ta.crossover(close,stop_long2_level)stop_long4 = ta.crossunder(close,stop_long4_level)// Exit Conditions, cond 1 only Stop Level, cond2 Trailing Stop option //exit_condition_1 = close < strategy.position_avg_price ? stop_long1 : close > strategy.position_avg_price ? stop_long2 : naexit_condition_2 = close < strategy.position_avg_price * (1 + tp_all) ? stop_long2 :                    close > strategy.position_avg_price * (1 + tp_all) ? stop_long4 :                   close < strategy.position_avg_price ? stop_long1 : na// Switch between conditions //exit_conditions = cond2_toggle ? exit_condition_2 : exit_condition_1// Exit when take profit //ex_m = exit_mode == 'close' ? close : stop_long2_leveltp_exit = ta.crossover(ex_m, strategy.position_avg_price * (1 + tp_all)) and close > strategy.position_avg_price * 1.002// Plot stoplevel, take profit level //plot_stop_level    = strategy.position_size > 0 ? stop_long2_level : naplot_trailing_stop = cond2_toggle and plot_ts and strategy.position_size > 0 and stop_long4_level > strategy.position_avg_price * (1 + tp_all) ? stop_long4_level : naplot(plot_stop_level,    title = 'Stop Level',    style=plot.style_linebr, color = color.new(#41e3ff, 0), linewidth = 1)plot(plot_trailing_stop, title = 'Trailing Stop', style=plot.style_linebr, color = color.new(#4cfca4, 0), linewidth = 1)plot_tp_level = cond2_toggle and strategy.position_size > 0 ? strategy.position_avg_price * (1 + tp_all) : naplot(plot_tp_level, title = 'Take Profit Level', style=plot.style_linebr, color = color.new(#ff41df, 0), linewidth = 1)// Calculate Stop Loss based on equity and average price //loss_equity = ((strategy.position_size * strategy.position_avg_price) - (strategy.equity * stopLoss)) / strategy.position_sizeloss_avg_price = strategy.position_avg_price * (1 - stopLoss)stop_loss = sl_mode == 'avg_price' ? loss_avg_price : loss_equityplot(strategy.position_size > 0  and sl_on ? stop_loss : na, title = 'Stop Loss', color=color.new(color.red,0),style=plot.style_linebr, linewidth = 1)// Counter to prevent opening too much orders in a row. //if strategy.position_size > 0     order_after := order_after + 1// Enter first position //if ta.crossunder(close,entry_price) and window() and strategy.position_size == 0    strategy.entry('L_1', strategy.long, qty = math.round(q,prec), comment = '+' + str.tostring(math.round(q,prec)))// Enter Next Pyramiding Orders //if buy_signal and window() and strategy.position_size > 0 and below_avg    for i = 1 to strategy.opentrades        entry_comment = '+' + str.tostring((quantity_mode(i,q_mode))) // Comment with variable //        if strategy.opentrades == i and i < posCount and order_after > oa_lookback            entry_price := close            entry_id = 'L_' + str.tostring(i + 1)             strategy.entry(id = entry_id, direction=strategy.long, limit=entry_price, qty= quantity_mode(i,q_mode), comment = entry_comment)            order_after := 0 // Reset counter to prevent opening to much orders in a row.// Exit per Order //if strategy.opentrades > 0 and window()     for i = 0 to strategy.opentrades         exit_comment = '-' + str.tostring(strategy.opentrades.size(i))        exit_from = 'L_' + str.tostring(i + 1)        exit_id = 'Exit_' + str.tostring(i + 1)        strategy.exit(id= exit_id, from_entry= exit_from, profit = take_profit_price, comment = exit_comment)            // Exit All //if exit_conditions or (tp_exit and tp_on and cond2_toggle) and window()    strategy.close_all('Exit All')    entry_price := 0if ta.crossunder(close,stop_loss)  and sl_on and window()    strategy.close_all('StopLoss')    entry_price := 0