Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

ROC_PA_Strategy (A3Sh)

A Pine Script v5 strategy built on Valuewhen (rocCrossed, condforValue), Barssince (rocCrossed) and TR. It has 6 order rules, 4 entries among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.075% commission. 19 settings; defaults include Portfolio Percentage 25, Leverage 3 and Percentage 3.5.

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 ROC_PA_Strategy (A3Sh) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 36 of 36 trades.
How did ROC_PA_Strategy (A3Sh) do on BTCUSDT 1D with default settings?
+56.33%
From 26 Jan 2024 to 21 Oct 2026, over 88 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does ROC_PA_Strategy (A3Sh) 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: 88 before, 24 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 ROC_PA_Strategy (A3Sh) use a stop loss?
Yes
strategy.exit sets a stop on line 148.
Does ROC_PA_Strategy (A3Sh) run in Zeal Terminal?
Yes
It compiles in 49 ms and runs 1,000 bars in 96 ms, in the browser.

BTCUSDT · 1D · default settings

  • take profit
  • stopp loss
  • roc threshold
  • Long Entry Threshold
  • Close Long Threshold
  • Long 1 Layer
  • Long 2 Layer
  • Long 3 Layer
  • Long 4 Layer
  • 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 (19)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,572$2,025Equity from $1,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. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep.
Net profit
+56.33%
$563.31
Buy and hold
+102.5%
same period
Closed trades
88
46 won · 42 lost
Profitable
52.3%
of closed trades
Profit factor
1.49
gross profit ÷ gross loss
Max drawdown
63.31%
−$965.94

One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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

    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 an argument v6 removed

    when = on line 148. 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
Risk
Portfolio Percentage25float · min 0.1 · max 200 · step 0.1c
Leverage3int · min 1 · max 100c
Take ProfittrueboolcloseCondition take profit
Percentage3.5float · min 0.1 · step 0.1tp
Stop Lossss trueboolstopLoss stopp loss
Percentage8.0float · min 0.1 · step 0.1sl
Price Averaging Layers
2nd Layer Long Entry %3float · step 0.1long2
3rd Layer Long Entry %7float · step 0.1long3
4th Layer Long Entry %15float · step 0.1long4
ROC Logic to OPEN Long Entry
Rate of Change bar lookback3introc
ROC Threshold % to Setup Long Entry2.2float · step 0.1roc
Price Drop Threshold % to OPEN Long Entry0.4float · step 0.1condforValue
Duration of Long Entry Threshold Line in bars6intplotLineOpen endLineOpen
Min % of Price Drop to OPEN Long Entry0.4float · step 0.1minThres
ROC Logic to CLOSE Long Entry
Rate of Change bar lookback3introc_CL
ROC Threshold % to Setup Close Threshold0.4float · step 0.1roc_CL
Price Rise Threshold % to CLOSE Long Entry1.0float · step 0.1condforValue_CL
Duration of Entry Limit in bars3intplotLineClose endLineClose
Activate Continues Close Limit LinefalseboolwhenCondition Close Long Threshold

What it calculates

  • ValuewhenrocCrossed, condforValue, 0openValue · line 57
  • BarssincerocCrossedsincerocCrossed · line 59
  • TRreturn_1 · line 75
  • ValuewhenrocCrossed_CL, condforValue_CL, 0closeValue · line 100
  • BarssincerocCrossed_CLsincerocCrossed_CL · line 102
  • ValuewhenopenLong, close, 0long1 · line 114
  • ValuewhenopenLong, close - close / 100 * ps2, 0long2 · line 115
  • ValuewhenopenLong, close - close / 100 * ps3, 0long3 · line 116
  • ValuewhenopenLong, close - close / 100 * ps4, 0long4 · line 117

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

Order rules

OrderFires whenBy defaultLine
Open Long1 longopenLong and strategy.opentrades == 0On140
Open Long2 longstrategy.opentrades == 1On142
Open Long3 longstrategy.opentrades == 2On144
Open Long4 longstrategy.opentrades == 3On146
Exit Exit stop and limitwhenConditionOn148
cancel_all longCloseOn152

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.

36/36trades 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+56.3%+102.5%8852%1.4963.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+15.4%+5.5%1173%2.3726.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+231.9%+9.8%7070%3.20137.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−26.9%+8.4%2752%0.3039.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+237.3%+16.7%8065%2.13171.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−14.6%+21.5%3456%0.6837.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+58.2%+148.3%14552%1.6393.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−17.5%+17.1%1547%0.3624.9%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 market4146%$316.03
Sideways market2654%−$41.24
Falling market2162%$290.98

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

How bad could the drawdown be?

30.0%

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

0%34%
All 88 trades
SideEntryExitBarsP&L
long17 Mar 2024 65,300.6018 Mar 2024 68,393.501$32.32
long20 Mar 2024 61,937.4021 Mar 2024 67,840.501$66.77
long13 Apr 2024 67,116.5017 Apr 2024 60,272.704−$81.88
long14 Apr 2024 63,924.5017 Apr 2024 60,272.703−$44.57
long15 Apr 2024 62,418.4017 Apr 2024 60,272.702−$28.87
long1 May 2024 60,672.004 May 2024 62,882.003$23.50
long2 May 2024 58,365.004 May 2024 62,882.002$50.02
long12 Jun 2024 67,314.2024 Jun 2024 60,995.9012−$70.56
long14 Jun 2024 65,294.8024 Jun 2024 60,995.9010−$48.77
long24 Jun 2024 62,602.2024 Jun 2024 60,995.900−$18.86
long25 Jun 2024 60,293.3030 Jun 2024 63,006.305$27.25
long5 Jul 2024 57,050.0014 Jul 2024 59,204.009$23.35
long8 Jul 2024 55,338.5014 Jul 2024 59,204.006$43.47
long3 Aug 2024 61,498.305 Aug 2024 56,578.502−$56.09
long4 Aug 2024 59,653.405 Aug 2024 56,578.501−$37.31
long5 Aug 2024 57,193.406 Aug 2024 54,018.801−$35.51
long5 Aug 2024 57,193.409 Aug 2024 61,686.004$1.76
long6 Aug 2024 54,018.809 Aug 2024 61,686.003$82.63
long7 Aug 2024 56,022.009 Aug 2024 61,686.002$66.91
long2 Sep 2024 57,301.806 Sep 2024 52,717.604−$59.27
long6 Sep 2024 55,582.806 Sep 2024 52,717.600−$37.42
long2 Oct 2024 60,804.907 Oct 2024 63,105.705$23.40
long5 Nov 2024 67,850.007 Nov 2024 75,572.002$76.91
long27 Nov 2024 91,965.2028 Nov 2024 95,863.101$30.43
long20 Dec 2024 97,461.9026 Dec 2024 99,429.606$14.01
long22 Dec 2024 94,538.0026 Dec 2024 99,429.604$37.49
long31 Dec 2024 92,792.102 Jan 2025 96,097.102$27.52
long26 Feb 2025 88,680.402 Mar 2025 87,418.604−$12.68
long27 Feb 2025 84,250.102 Mar 2025 87,418.603$27.36
long28 Feb 2025 82,472.802 Mar 2025 87,418.602$46.26
long10 Mar 2025 80,734.5012 Mar 2025 82,933.002$21.17
long11 Mar 2025 78,312.3012 Mar 2025 82,933.001$48.15
long9 Apr 2025 76,322.4010 Apr 2025 82,615.201$72.23
long30 May 2025 105,590.009 Jun 2025 106,956.0010$10.98
long5 Jun 2025 102,422.009 Jun 2025 106,956.004$40.70
long18 Jun 2025 104,551.0025 Jun 2025 107,128.007$23.21
long21 Jun 2025 101,415.0025 Jun 2025 107,128.004$53.90
long19 Aug 2025 116,227.0011 Sep 2025 114,045.0023−$21.66
long20 Aug 2025 112,740.0011 Sep 2025 114,045.0022$10.33
long29 Aug 2025 108,091.0011 Sep 2025 114,045.0013$54.98
long26 Sep 2025 108,994.0029 Sep 2025 113,472.003$42.24
long11 Oct 2025 112,774.0017 Oct 2025 103,753.006−$86.33
long16 Oct 2025 109,391.0017 Oct 2025 103,753.001−$57.99
long17 Oct 2025 104,880.0021 Oct 2025 110,532.004$53.26
long17 Oct 2025 104,880.0021 Oct 2025 110,532.004$1.10
long18 Oct 2025 106,432.0021 Oct 2025 110,532.003$38.20
long31 Oct 2025 108,323.004 Nov 2025 99,657.004−$88.22
long4 Nov 2025 105,073.004 Nov 2025 99,657.000−$55.14
long14 Nov 2025 99,692.0015 Jan 2026 96,951.8062−$28.30
long15 Nov 2025 94,594.0015 Jan 2026 96,951.8061$21.26
long17 Nov 2025 92,713.6015 Jan 2026 96,951.8059$40.96
long21 Nov 2025 84,738.2015 Jan 2026 96,951.8055$105.07
long21 Jan 2026 88,427.7030 Jan 2026 81,353.409−$85.70
long29 Jan 2026 85,774.8030 Jan 2026 81,353.401−$56.38
long30 Jan 2026 82,237.7031 Jan 2026 81,353.401−$11.88
long31 Jan 2026 84,260.5031 Jan 2026 81,353.400−$0.61
long31 Jan 2026 84,260.501 Feb 2026 78,741.101−$62.62
long31 Jan 2026 84,260.5022 Sep 2026 86,620.00234$1.56
long1 Feb 2026 78,741.1022 Sep 2026 86,620.00233$85.30
long1 Feb 2026 78,741.1022 Sep 2026 86,620.00233$0.78
long2 Feb 2026 76,968.2022 Sep 2026 86,620.00232$111.49
long3 Feb 2026 75,163.5022 Sep 2026 86,620.00231$6.80
long3 Feb 2026 75,163.5023 Sep 2026 85,774.80232$123.79
long23 Sep 2026 85,774.8023 Sep 2026 85,774.800−$0.26
long23 Sep 2026 85,774.8024 Sep 2026 84,397.601−$17.76
long24 Sep 2026 84,397.6024 Sep 2026 84,397.600−$0.23
long24 Sep 2026 84,397.6025 Sep 2026 84,410.201−$1.34
long25 Sep 2026 84,410.2025 Sep 2026 84,410.200−$0.27
long25 Sep 2026 84,410.2026 Sep 2026 84,100.001−$5.15
long26 Sep 2026 84,100.0026 Sep 2026 84,100.000−$0.25
long26 Sep 2026 84,100.0027 Sep 2026 84,433.101$2.44
long27 Sep 2026 84,433.1027 Sep 2026 84,433.100−$0.27
long27 Sep 2026 84,433.1028 Sep 2026 84,472.001−$1.04
long28 Sep 2026 84,472.0028 Sep 2026 84,472.000−$0.25
long28 Sep 2026 84,472.0029 Sep 2026 83,500.001−$12.96
long29 Sep 2026 83,500.0029 Sep 2026 83,500.000−$0.24
long29 Sep 2026 83,500.0030 Sep 2026 83,663.701$0.45
long30 Sep 2026 83,663.7030 Sep 2026 83,663.700−$0.26
long30 Sep 2026 83,663.701 Oct 2026 83,623.601−$1.95
long1 Oct 2026 83,623.601 Oct 2026 83,623.600−$0.25
long1 Oct 2026 83,623.602 Oct 2026 84,880.101$13.34
long2 Oct 2026 84,880.102 Oct 2026 84,880.100−$0.28
long2 Oct 2026 84,880.103 Oct 2026 84,518.001−$5.77
long3 Oct 2026 84,518.003 Oct 2026 84,518.000−$0.24
long3 Oct 2026 84,518.004 Oct 2026 84,753.601$1.28
long4 Oct 2026 84,753.604 Oct 2026 84,753.600−$0.25
long4 Oct 2026 84,753.606 Oct 2026 86,122.502$14.64
long5 Oct 2026 85,774.806 Oct 2026 86,122.501$0.46

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
ROC_PA_Strategy (A3Sh) this page—v5 strategy+56.3%8863.3%
Momentum Strategy (BTC-USDT; 30m) - STOCH RSI (with source code) by Drun30valuewhen barssincev4 strategy+13.3%1213.6%
Twin Range Filter Algo by OrcChieftaintr barssincev4 strategy+48.4%186.8%

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.

  • 1 strategy call uses the when = argument (line 148). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 88 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 148: when = whenCondition → if block
⋯// Setup Limit Close / Take Profit / Stop Loss order -strategy.exit('Exit', stop=stopLoss, limit=closeCondition, when=whenCondition, comment='Close All')+if whenCondition+    strategy.exit('Exit', stop=stopLoss, limit=closeCondition, comment='Close All')// Make sure that all open limit orders are canceled after exiting all the positions ⋯

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: 88 before, 24 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.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 49 msYes 1,000 bars in 96 msNot measured
PineTSNot testedNot testedNot measured

“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.

//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © A3Sh// Rate of price change / Price averaging strategy //// When the price drops to a specified percentage, a Long Entry Threshold is setup.// The Long Entry Threshold is only active for a specified number of bars and will de-activate when not crossed. // When the price drops further and crosses the Entry Threshold with a minimum of a specified percentage, a Long Position is entered. // The same reverse logic used to close the Long Position.// Stop loss and take profit are active by default. With proper tweaking of the settings it is possible to de-activate SL and TP.// The strategy is inspired by the following strategies:// Price Change Scalping Strategy developed by Prosum Solutions, https://www.tradingview.com/script/ue7Uc3sN-Price-Change-Scalping-Strategy-v1-0-0/// Scalping Dips On Trend Strategy developed by Coinrule, https://www.tradingview.com/script/iHHO0PJA-Scalping-Dips-On-Trend-by-Coinrule/strategy(title='ROC_PA_Strategy_@A3Sh', overlay=true, pyramiding=4, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.075)// Portfolio & Leverage Example// credit: @RafaelZioni, https://www.tradingview.com/script/xGk5K4DE-BTC-15-min/ge(value, precision) =>    math.round(value * math.pow(10, precision)) / math.pow(10, precision)port     = input.float(25,  group='Risk', title='Portfolio Percentage', step=0.1, minval=0.1, maxval=200)leverage = input.int(3,     group='Risk', title='Leverage',                       minval=1,   maxval=100)c = ge(strategy.equity * leverage / open * (port / 100), 4)// Take Profittpa = input.bool(true, title='Take Profit', group='Risk', inline='Take Profit')tpp = input.float(3.5, title='Percentage',  group='Risk', step=0.1, minval=0.1, inline='Take Profit')tp = strategy.position_avg_price + strategy.position_avg_price / 100 * tppplot(tpa and strategy.position_size > 0 ? tp : na, color=color.new(color.gray, 0), title='take profit', style=plot.style_linebr, linewidth=1)// Stop Losssla = input.bool(true, title='Stop Lossss ', group='Risk',                       inline='Stop Loss')slp = input.float(8.0, title='Percentage',   group='Risk', step=0.1, minval=0.1, inline='Stop Loss')sl = strategy.position_avg_price - strategy.position_avg_price / 100 * slpplot(sla and strategy.position_size > 0 ? sl : na, color=color.new(color.red, 0), title='stopp loss', style=plot.style_linebr, linewidth=1)stopLoss = sla ? sl : na// Long position entry layers. Percentage from the entry price of the the first longps2 = input.float(3,  group='Price Averaging Layers', title='2nd Layer Long Entry %', step=0.1)ps3 = input.float(7,  group='Price Averaging Layers', title='3rd Layer Long Entry %', step=0.1)ps4 = input.float(15, group='Price Averaging Layers', title='4th Layer Long Entry %', step=0.1)// ROC_Trigger Logic to open Long PositionrocLookBack =  input.int(3,     group='ROC Logic to OPEN Long Entry', title='Rate of Change bar lookback')rocThreshold = input.float(2.2, group='ROC Logic to OPEN Long Entry', title='ROC Threshold % to Setup Long Entry',       step=0.1)entryLimit =   input.float(0.4, group='ROC Logic to OPEN Long Entry', title='Price Drop Threshold % to OPEN Long Entry', step=0.1)entryTime =    input.int(6,     group='ROC Logic to OPEN Long Entry', title='Duration of Long Entry Threshold Line in bars')minLimit =     input.float(0.4, group='ROC Logic to OPEN Long Entry', title='Min % of Price Drop to OPEN Long Entry',    step=0.1)//ROC calculation based to the price level of previous X barsroc = close[rocLookBack] - close / 100 * rocThresholdplot(roc, color=color.new(color.gray, 20), title='roc threshold', linewidth=1)rocT1 = open > roc and close < roc ? 1 : 0  // When the price CROSSES the Entry LimitrocT2 = open < roc and close < roc ? 1 : 0  // When the price is BELOW the Entry LimitrocTrigger = rocT1 or rocT2// Condition for Setting Up a Long Entry Thershold LinerocCrossed    = falsevar SetUpLong = falseif rocTrigger and not SetUpLong    rocCrossed := true    SetUpLong  := true    SetUpLong// Defining the Value of the Long Entry ThersholdcondforValue = rocCrossed and (open - low) / (open / 100) > 0 or open < roc and close < roc ? low - close / 100 * entryLimit : roc - close / 100 * entryLimitopenValue    = ta.valuewhen(rocCrossed, condforValue, 0)// Defining the length of the Long Entry Thershold in bars, specified with an input parametersincerocCrossed = ta.barssince(rocCrossed)plotLineOpen    = sincerocCrossed <= entryTime ? openValue : naendLineOpen     = sincerocCrossed == entryTime ? 1 : 0// Set the conditions back to false when the Entry Limit Threshold Line ends after specied number of barsif endLineOpen and SetUpLong    rocCrossed := false    SetUpLong  := false    SetUpLong// Set minimum percentage of price drop to open a Long Position.minThres = (open - close) / (open / 100) > minLimit ? 1 : 0// Open Long TriggeropenLong = ta.crossunder(close, plotLineOpen) and strategy.position_size == 0 and minThresplot(strategy.position_size == 0 ? plotLineOpen : na, title='Long Entry Threshold', color=color.new(color.yellow, 0), style=plot.style_linebr, linewidth=2)// Show vertical dashed line when long condition is triggered // credit: @midtownsk8rguy, https://www.tradingview.com/script/EmTkvfCM-vline-Function-for-Pine-Script-v4-0/vline(BarIndex, Color, LineStyle, LineWidth) =>    return_1 = line.new(BarIndex, low - ta.tr, BarIndex, high + ta.tr, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)    return_1if openLong    vline(bar_index, color.blue, line.style_dashed, 1)// ROC_Trigger Logic to close Long PositionrocLookBackL    = input.int(3,      group='ROC Logic to CLOSE Long Entry', title='Rate of Change bar lookback')entryThresholdL = input.float(0.4,  group='ROC Logic to CLOSE Long Entry', title='ROC Threshold % to Setup Close Threshold',  step=0.1)  // Percentage from close priceentryLimit_CL   = input.float(1.0,  group='ROC Logic to CLOSE Long Entry', title='Price Rise Threshold % to CLOSE Long Entry', step=0.1)  // Percentage from roc thresholdentryTime_CL    = input.int(3,      group='ROC Logic to CLOSE Long Entry', title='Duration of Entry Limit in bars')changeLogic     = input.bool(false, group='ROC Logic to CLOSE Long Entry', title='Activate Continues Close Limit Line')roc_CL = close[rocLookBackL] + close / 100 * entryThresholdL//plot(rocL, color=color.gray, linewidth=1, transp=20)rocT1_CL = open < roc_CL and close > roc_CL ? 1 : 0rocT2_CL = open > roc_CL and close > roc_CL ? 1 : 0rocTrigger_CL = rocT1_CL or rocT2_CL// Condition for Setting Up a Long CLOSE Thershold LinerocCrossed_CL  = falsevar SetUpClose = falseif rocTrigger_CL and not SetUpClose    // The trigger for condA occurs and the last condition set was condB.    rocCrossed_CL := true    SetUpClose    := true    SetUpClose// Defining the Value of the Long CLOSE ThersholdcondforValue_CL = rocCrossed_CL and (high - open) / (open / 100) > 0 or open > roc_CL and close > roc_CL ? high + close / 100 * entryLimit_CL : roc_CL + close / 100 * entryLimit_CLcloseValue      = ta.valuewhen(rocCrossed_CL, condforValue_CL, 0)// Defining the length of the Long CLOSE Thershold in bars, specified with an input parametersincerocCrossed_CL = ta.barssince(rocCrossed_CL)plotLineClose      = sincerocCrossed_CL <= entryTime_CL ? closeValue : naendLineClose       = sincerocCrossed_CL == entryTime_CL ? 1 : 0// Set the conditions back to false when the CLOSE Limit Threshold Line ends after specied number of barsif endLineClose and SetUpClose    rocCrossed_CL := false    SetUpClose    := false    SetUpClose// ROC Close + Take Profit combinedcloseCondition = close < tp ? plotLineClose : tpa ? tp : plotLineCloseplot(changeLogic and strategy.position_size > 0 ? closeValue : strategy.position_size > 0 ? plotLineClose : na, color=color.new(color.white, 0), title='Close Long Threshold', style=plot.style_linebr, linewidth=2)// Store values to create and plot the different PA layerslong1 = ta.valuewhen(openLong, close, 0)long2 = ta.valuewhen(openLong, close - close / 100 * ps2, 0)long3 = ta.valuewhen(openLong, close - close / 100 * ps3, 0)long4 = ta.valuewhen(openLong, close - close / 100 * ps4, 0)eps1 = 0.00eps1 := na(eps1[1]) ? na : eps1[1]eps2 = 0.00eps2 := na(eps2[1]) ? na : eps2[1]eps3 = 0.00eps3 := na(eps3[1]) ? na : eps3[1]eps4 = 0.00eps4 := na(eps4[1]) ? na : eps4[1]plot(strategy.position_size > 0 ? eps1 : na, title='Long 1 Layer', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps2 : na, title='Long 2 Layer', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps3 : na, title='Long 3 Layer', style=plot.style_linebr)plot(strategy.position_size > 0 ? eps4 : na, title='Long 4 Layer', style=plot.style_linebr)// Option to choose between old and new logic// There was a flaw in the original script that caused positions to close even after the close limit line ended. // Now you can choose between a logic where the line is continues(the orginal script) and one where the close limit is active an X amount of bars(the inteded logic)whenCondition = changeLogic ? rocTrigger_CL and strategy.position_size > 0 : strategy.position_size > 0 and close > eps2// Ener Long Positionsif openLong and strategy.opentrades == 0    eps1 := long1    eps2 := long2    eps3 := long3    eps4 := long4    strategy.entry('Long1', strategy.long, c, comment='Enter Long1')if strategy.opentrades == 1    strategy.entry('Long2', strategy.long, c, limit=eps2, comment='Enter Long2')if strategy.opentrades == 2    strategy.entry('Long3', strategy.long, c, limit=eps3, comment='Enter Long3')if strategy.opentrades == 3    strategy.entry('Long4', strategy.long, c, limit=eps4, comment='Enter Long4')// Setup Limit Close / Take Profit / Stop Loss order strategy.exit('Exit', stop=stopLoss, limit=closeCondition, when=whenCondition, comment='Close All')// Make sure that all open limit orders are canceled after exiting all the positions longClose = strategy.position_size[1] > 0 and strategy.position_size == 0 ? 1 : 0if longClose    strategy.cancel_all()