Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

BuyHighSellLow - Pivot points

A Pine Script v4 strategy with no technical-analysis calculation. It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.01% commission. 7 settings; defaults include Source close, Resolution 4D and Higher Timeframe multiplier (Used when resolution is set to Same as Symbol) 4.

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 BuyHighSellLow - Pivot points repaint?
Yes
At least one pattern in the source can repaint: higher-timeframe data.
How did BuyHighSellLow - Pivot points do on BTCUSDT 1D with default settings?
+17.29%
From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can BuyHighSellLow - Pivot points be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does BuyHighSellLow - Pivot points use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does BuyHighSellLow - Pivot points run in Zeal Terminal?
Yes
It compiles in 36 ms and runs 1,000 bars in 135 ms, in the browser.

BTCUSDT · 1D · default settings

  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$136,045$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. 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. The live re-run is not offered here: the script requests BINANCE:BTCUSDT 4D, which this page cannot load in your browser.
Net profit
+17.29%
$17,286.10
Buy and hold
+102.5%
same period
Closed trades
15
4 won · 11 lost
Profitable
26.7%
of closed trades
Profit factor
1.16
gross profit ÷ gross loss
Max drawdown
36.73%
−$53,939.90

One run with the author's default settings, $100,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

    No stop loss

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

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    3 settings have no label

    In the settings dialog Source (line 5), resolution (line 6), hideBands (line 13) show an empty name. The labels on this page come from the variable names.

  • 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 151, 152. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 127

    transp = on line 127, 128, 129, 130, 131, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147. v5 folds the transparency into the colour with color.new(c, transp).

Upgrade and export

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

  • Upgrading to v5 renames tostring → str.tostring, round → math.round, min → math.min, security → request.security, crossover → ta.crossover, crossunder → ta.crossunder.
  • 2 strategy calls use the when = argument (line 151, 152). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.resolution) → input.timeframe()
  • Line 25: tostring → str.tostring
  • Line 25: round → math.round
  • Line 26: tostring → str.tostring
  • Line 26: round → math.round
24 more edits
  • Line 26: min → math.min
  • Line 73: security → request.security
  • Line 127: transp = 50 → color.new(color.orange, 50)
  • Line 128: transp = 50 → color.new(color.yellow, 50)
  • Line 129: transp = 50 → color.new(color.navy, 50)
  • Line 130: transp = 50 → color.new(color.olive, 50)
  • Line 131: transp = 50 → color.new(color.lime, 50)
  • Line 133: transp = 50 → color.new(color.lime, 50)
  • Line 134: transp = 50 → color.new(color.olive, 50)
  • Line 135: transp = 50 → color.new(color.navy, 50)
  • Line 136: transp = 50 → color.new(color.yellow, 50)
  • Line 137: transp = 50 → color.new(color.orange, 50)
  • Line 138: transp = 90 → color.new(color.green, 90)
  • Line 139: transp = 90 → color.new(color.lime, 90)
  • Line 140: transp = 90 → color.new(color.olive, 90)
  • Line 141: transp = 90 → color.new(color.navy, 90)
  • Line 142: transp = 90 → color.new(color.yellow, 90)
  • Line 143: transp = 90 → color.new(color.orange, 90)
  • Line 144: transp = 90 → color.new(color.red, 90)
  • Line 145: transp = 90 → color.new(color.maroon, 90)
  • Line 146: transp = 90 → color.new(color.maroon, 90)
  • Line 147: transp = 90 → color.new(color.maroon, 90)
  • Line 149: crossover → ta.crossover
  • Line 150: crossunder → ta.crossunder
⋯// © HeWhoMustNotBeNamed-//@version=4+//@version=5strategy("BuyHighSellLow - Pivot points", overlay=true, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)Source = input(close)-resolution = input("4D", type=input.resolution)+resolution = input.timeframe("4D")HTFMultiplier = input(4, title="Higher Timeframe multiplier (Used when resolution is set to Same as Symbol)", minval=2, step=1)⋯      target_Res_In_Min   <= 0.751        ? "30S" :-      target_Res_In_Min   <= 1440         ? tostring(round(target_Res_In_Min)) :+      target_Res_In_Min   <= 1440         ? str.tostring(math.round(target_Res_In_Min)) :-      tostring(round(min(target_Res_In_Min / 1440, 365))) + "D"+      str.tostring(math.round(math.min(target_Res_In_Min / 1440, 365))) + "D"f_getBackTestTimeFrom(backtestFrom, backtestBars)=>⋯    [date, mth, yr]-f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)+f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)f_getClassicPivots(HIGHprev, LOWprev, CLOSEprev)=>⋯inDateRange = time >= timestamp(syminfo.timezone, yr, mth, date, 0, 0)-BBU5 = plot(not hideBands ? R5: na, title="R5", color=color.orange, linewidth=1, transp=50, style=plot.style_linebr)+BBU5 = plot(not hideBands ? R5: na, title="R5", color=color.new(color.orange, 50), linewidth=1, style=plot.style_linebr)-BBU4 = plot(not hideBands ? R4: na, title="R4", color=color.yellow, linewidth=1, transp=50, style=plot.style_linebr)+BBU4 = plot(not hideBands ? R4: na, title="R4", color=color.new(color.yellow, 50), linewidth=1, style=plot.style_linebr)-BBU3 = plot(not hideBands ? R3: na, title="R3", color=color.navy, linewidth=1, transp=50, style=plot.style_linebr)+BBU3 = plot(not hideBands ? R3: na, title="R3", color=color.new(color.navy, 50), linewidth=1, style=plot.style_linebr)-BBU2 = plot(not hideBands ? R2: na, title="R2", color=color.olive, linewidth=1, transp=50, style=plot.style_linebr)+BBU2 = plot(not hideBands ? R2: na, title="R2", color=color.new(color.olive, 50), linewidth=1, style=plot.style_linebr)-BBU1 = plot(not hideBands ? R1: na, title="R1", color=color.lime, linewidth=1, transp=50, style=plot.style_linebr)+BBU1 = plot(not hideBands ? R1: na, title="R1", color=color.new(color.lime, 50), linewidth=1, style=plot.style_linebr)BBM4 = plot(not hideBands ? PP:na, title="PP", color=color.black, linewidth=2, style=plot.style_linebr)-BBL1 = plot(not hideBands ? S1: na, title="S1", color=color.lime, linewidth=1, transp=50, style=plot.style_linebr)+BBL1 = plot(not hideBands ? S1: na, title="S1", color=color.new(color.lime, 50), linewidth=1, style=plot.style_linebr)-BBL2 = plot(not hideBands ? S2: na, title="S2", color=color.olive, linewidth=1, transp=50, style=plot.style_linebr)+BBL2 = plot(not hideBands ? S2: na, title="S2", color=color.new(color.olive, 50), linewidth=1, style=plot.style_linebr)-BBL3 = plot(not hideBands ? S3: na, title="S3", color=color.navy, linewidth=1, transp=50, style=plot.style_linebr)+BBL3 = plot(not hideBands ? S3: na, title="S3", color=color.new(color.navy, 50), linewidth=1, style=plot.style_linebr)-BBL4 = plot(not hideBands ? S4: na, title="S4", color=color.yellow, linewidth=1, transp=50, style=plot.style_linebr)+BBL4 = plot(not hideBands ? S4: na, title="S4", color=color.new(color.yellow, 50), linewidth=1, style=plot.style_linebr)-BBL5 = plot(not hideBands ? S5: na, title="S5", color=color.orange, linewidth=1, transp=50, style=plot.style_linebr)+BBL5 = plot(not hideBands ? S5: na, title="S5", color=color.new(color.orange, 50), linewidth=1, style=plot.style_linebr)-fill(BBU5, BBU4, title="RZ5", color=color.green, transp=90)+fill(BBU5, BBU4, title="RZ5", color=color.new(color.green, 90))-fill(BBU4, BBU3, title="RZ4", color=color.lime, transp=90)+fill(BBU4, BBU3, title="RZ4", color=color.new(color.lime, 90))-fill(BBU3, BBU2, title="RZ3", color=color.olive, transp=90)+fill(BBU3, BBU2, title="RZ3", color=color.new(color.olive, 90))-fill(BBU2, BBU1, title="RZ2", color=color.navy, transp=90)+fill(BBU2, BBU1, title="RZ2", color=color.new(color.navy, 90))-fill(BBU1, BBM4, title="RZ1", color=color.yellow, transp=90)+fill(BBU1, BBM4, title="RZ1", color=color.new(color.yellow, 90))-fill(BBM4, BBL1, title="SZ1", color=color.orange, transp=90)+fill(BBM4, BBL1, title="SZ1", color=color.new(color.orange, 90))-fill(BBL1, BBL2, title="SZ2", color=color.red, transp=90)+fill(BBL1, BBL2, title="SZ2", color=color.new(color.red, 90))-fill(BBL2, BBL3, title="SZ3", color=color.maroon, transp=90)+fill(BBL2, BBL3, title="SZ3", color=color.new(color.maroon, 90))-fill(BBL3, BBL4, title="SZ4", color=color.maroon, transp=90)+fill(BBL3, BBL4, title="SZ4", color=color.new(color.maroon, 90))-fill(BBL4, BBL5, title="SZ5", color=color.maroon, transp=90)+fill(BBL4, BBL5, title="SZ5", color=color.new(color.maroon, 90))strategy.risk.allow_entry_in(tradeDirection)-longCondition = crossover(Source[1],R1) and inDateRange+longCondition = ta.crossover(Source[1],R1) and inDateRange-shortCondition = crossunder(Source[1], S2) and inDateRange+shortCondition = ta.crossunder(Source[1], S2) and inDateRangestrategy.entry("Buy", strategy.long, when=longCondition, oca_name="oca", oca_type=strategy.oca.cancel)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.source()
  • Line 7: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.string()
  • Line 13: input() → input.bool()
  • Line 151: when = longCondition → if block
  • Line 152: when = shortCondition → if block
⋯strategy("BuyHighSellLow - Pivot points", overlay=true, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)-Source = input(close)+Source = input.source(close)resolution = input.timeframe("4D")-HTFMultiplier = input(4, title="Higher Timeframe multiplier (Used when resolution is set to Same as Symbol)", minval=2, step=1)+HTFMultiplier = input.int(4, title="Higher Timeframe multiplier (Used when resolution is set to Same as Symbol)", minval=2, step=1)//ppType = input(title="Pivot points type", defval="classic", options=["classic", "fib"])⋯tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])-backtestBars = input(title="Backtest from ", defval=10, minval=1, maxval=30)+backtestBars = input.int(title="Backtest from ", defval=10, minval=1, maxval=30)-backtestFrom = input(title="Timeframe", defval="years", options=["days", "months", "years"])+backtestFrom = input.string(title="Timeframe", defval="years", options=["days", "months", "years"])-hideBands = input(true)+hideBands = input.bool(true)f_multiple_resolution(HTFMultiplier) => ⋯shortCondition = ta.crossunder(Source[1], S2) and inDateRange-strategy.entry("Buy", strategy.long, when=longCondition, oca_name="oca", oca_type=strategy.oca.cancel)+if longCondition+    strategy.entry("Buy", strategy.long, oca_name="oca", oca_type=strategy.oca.cancel)-strategy.entry("Sell", strategy.short, when=shortCondition, oca_name="oca", oca_type=strategy.oca.cancel)+if shortCondition+    strategy.entry("Sell", strategy.short, oca_name="oca", oca_type=strategy.oca.cancel)

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, 21 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.

⋯// © HeWhoMustNotBeNamed-//@version=5+//@version=6strategy("BuyHighSellLow - Pivot points", overlay=true, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯

Settings

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

SettingDefaultType and rangeFeeds
Source (no label in the script)closesourcestate longCondition shortCondition
Resolution (no label in the script)4Dtimeframe (written input.resolution)PP R1 S1 R2 S2 R3 S3 R4 S4 R5 S5 derivedResolution
Higher Timeframe multiplier (Used when resolution is set to Same as Symbol)4int · min 2 · step 1target_Res_In_Min PP R1 S1 R2 S2 R3 S3 R4 S4 R5 S5 derivedResolution
Trade Directionstrategy.direction.longvalue · options [strategy.direction.all, strategy.direction.long, strategy.direction.short]line 148
Backtest from 10int · min 1 · max 30date mth yr
Timeframeyearsstring · options ["days", "months", "years"]byDate byMonth byYear date mth yr
Hide Bands (no label in the script)trueboolR5 R4 R3 R2 R1 PP S1 S2 S3 S4 S5

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.

HTFMultiplierHigher Timeframe multip…setting · 4backtestFromTimeframesetting · yearsbacktestBarsBacktest from setting · 10resolutionResolutionsetting · 4Dhighhighprice datalowlowprice dataclosecloseprice datatimetimeprice datatarget_Res_In_Mintarget_Res_In_Minvaluedate, mth, yrdate · mth +13 valuesnumberOfDaysInCurrentMonthnumberOfDaysInCurrentMo…valuePP, R1, S1, R2, S2, R3, S3, R4, S4, R5, S5, derivedResolutionPP · R1 +1012 valuesHIGHprevHIGHprevvalueLOWprevLOWprevvalueCLOSEprevCLOSEprevvalueRf5, Rf4, Rf3, Rf2, Rf1, PPf, Sf1, Sf2, Sf3, Sf4, Sf5Rf5 · Rf4 +911 valuesstatestatevaluelongConditionlongConditionconditionshortConditionshortConditionconditionbyDate, byMonth, byYearbyDate · byMonth +13 conditionsisLeapYearisLeapYearconditioninDateRangeinDateRangeconditionentry:BuyOpen Buystrategy.entryentry:SellOpen Sellstrategy.entryplot:127R5plotplot:128R4plotplot:129R3plotplot:130R2plotplot:131R1plotplot:132PPplotplot:133S1plotplot:134S2plotplot:135S3plotplot:136S4plotplot:137S5plotfill:RZ5RZ5fillfill:RZ4RZ4fillfill:RZ3RZ3fillfill:RZ2RZ2fillfill:RZ1RZ1fillfill:SZ1SZ1fillfill:SZ2SZ2fillfill:SZ3SZ3fillfill:SZ4SZ4fillfill:SZ5SZ5fill

Order rules

OrderFires whenBy defaultLine
Open Buy longlongConditioncrossover(Source[1],R1) and inDateRangeOn151
Open Sell shortshortConditioncrossunder(Source[1], S2) and inDateRangeOn152

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

2/2trades 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.
  • CheckHigher-timeframe data1 security call(s) use lookahead_on (line 73). Without a [1] offset this reads future bars in history.
  • 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+17.3%+102.5%1527%1.1636.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+19.0%+5.5%367%4.287.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−24.0%+9.8%2030%0.8764.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+23.8%+8.4%367%2.8214.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+45.4%+16.7%1040%1.4254.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+35.7%+21.5%367%2.9926.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+84.0%+148.3%1155%2.3626.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+10.0%+17.1%250%1.6818.1%8 May 2026 – 21 Oct 2026

Higher-timeframe data for request.security(): BINANCE:BTCUSDT 4D (aggregated from Binance BTCUSDT 1d), fetched from Binance's public market data for each market.

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market30%−$46,961.90
Sideways market1040%$89,086.70
Falling market20%−$24,827.00

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

How bad could the drawdown be?

52.6%

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, 26.4% to 52.6%; the tick is what actually happened, 30.2%. Order luck alone moves it this much.

0%60%
All 15 trades
SideEntryExitBarsP&L
long9 Feb 2024 45,288.704 Apr 2024 65,963.3055$45,621.60
long10 Apr 2024 69,146.003 May 2024 59,060.6023−$21,264.70
long15 May 2024 61,577.506 Jul 2024 56,628.8052−$10,016.90
long17 Jul 2024 65,044.004 Aug 2024 60,698.0018−$7,661.13
long10 Aug 2024 60,838.003 Oct 2024 60,649.3054−$352.19
long30 Oct 2024 72,736.4011 Jan 2025 94,726.1073$32,117.00
long17 Jan 2025 99,987.3026 Feb 2025 88,680.4040−$15,680.20
long4 Mar 2025 86,221.2031 Mar 2025 82,390.0027−$5,478.38
long11 Apr 2025 79,607.303 Aug 2025 112,546.00114$48,495.80
long9 Aug 2025 116,675.0024 Sep 2025 111,999.0046−$6,675.78
long1 Oct 2025 114,049.0012 Oct 2025 110,644.0011−$4,780.41
long28 Oct 2025 114,108.006 Nov 2025 103,885.009−$13,853.50
long5 Dec 2025 92,078.1022 Jan 2026 89,454.7048−$4,029.36
long6 Mar 2026 70,891.0027 Jun 2026 60,097.30113−$20,797.60
long4 Jul 2026 62,583.3014 Aug 2026 63,490.9041$1,653.64

Similar scripts

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

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 36 msWith a workaround 1,000 bars in 135 msNot measured
PineTSNo v5 and v6 only—Not 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. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © HeWhoMustNotBeNamed//@version=4strategy("BuyHighSellLow - Pivot points", overlay=true, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)Source = input(close)resolution = input("4D", type=input.resolution)HTFMultiplier = input(4, title="Higher Timeframe multiplier (Used when resolution is set to Same as Symbol)", minval=2, step=1)//ppType = input(title="Pivot points type", defval="classic", options=["classic", "fib"])ppType = "fib"tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])backtestBars = input(title="Backtest from ", defval=10, minval=1, maxval=30)backtestFrom = input(title="Timeframe", defval="years", options=["days", "months", "years"])hideBands = input(true)f_multiple_resolution(HTFMultiplier) =>     target_Res_In_Min = timeframe.multiplier * HTFMultiplier * (      timeframe.isseconds   ? 1. / 60. :      timeframe.isminutes   ? 1. :      timeframe.isdaily     ? 1440. :      timeframe.isweekly    ? 7. * 24. * 60. :      timeframe.ismonthly   ? 30.417 * 24. * 60. : na)    target_Res_In_Min     <= 0.0417       ? "1S"  :      target_Res_In_Min   <= 0.167        ? "5S"  :      target_Res_In_Min   <= 0.376        ? "15S" :      target_Res_In_Min   <= 0.751        ? "30S" :      target_Res_In_Min   <= 1440         ? tostring(round(target_Res_In_Min)) :      tostring(round(min(target_Res_In_Min / 1440, 365))) + "D"f_getBackTestTimeFrom(backtestFrom, backtestBars)=>    byDate = backtestFrom == "days"    byMonth = backtestFrom == "months"    byYear = backtestFrom == "years"        date = dayofmonth(timenow)    mth = month(timenow)    yr = year(timenow)        leapYearDaysInMonth = array.new_int(12,0)    array.set(leapYearDaysInMonth,0,31)    array.set(leapYearDaysInMonth,1,29)    nonleapYearDaysInMonth = array.new_int(12,0)    array.set(leapYearDaysInMonth,0,31)    array.set(leapYearDaysInMonth,1,28)        restMonths = array.new_int(10,0)    array.set(leapYearDaysInMonth,0,31)    array.set(leapYearDaysInMonth,1,30)    array.set(leapYearDaysInMonth,2,31)    array.set(leapYearDaysInMonth,3,30)    array.set(leapYearDaysInMonth,4,31)    array.set(leapYearDaysInMonth,5,31)    array.set(leapYearDaysInMonth,6,30)    array.set(leapYearDaysInMonth,7,31)    array.set(leapYearDaysInMonth,8,30)    array.set(leapYearDaysInMonth,9,31)        array.concat(leapYearDaysInMonth,restMonths)    array.concat(nonleapYearDaysInMonth,restMonths)    isLeapYear = yr % 4 == 0 and (year%100 != 0 or year%400 == 0)    numberOfDaysInCurrentMonth = isLeapYear ? array.get(leapYearDaysInMonth, mth-2) : array.get(nonleapYearDaysInMonth, mth-2)    if(byDate)        mth := (date - backtestBars) < 0 ? mth - 1 : mth        yr := mth < 1 ? yr - 1 : yr        mth := mth < 1 ? 1 : mth        date := (date - backtestBars) < 0 ? numberOfDaysInCurrentMonth - backtestBars + date + 1 : date - backtestBars + 1    if(byMonth)        date := 1        yr := (mth - (backtestBars%12)) < 0 ? yr - int(backtestBars/12) - 1 : yr - int(backtestBars/12)        mth := mth - (backtestBars%12) + 1    if(byYear)        date := 1        mth := 1        yr := yr - backtestBars    [date, mth, yr]f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)f_getClassicPivots(HIGHprev, LOWprev, CLOSEprev)=>    PP = (HIGHprev + LOWprev + CLOSEprev) / 3    R1 = PP * 2 - LOWprev    S1 = PP * 2 - HIGHprev    R2 = PP + (HIGHprev - LOWprev)    S2 = PP - (HIGHprev - LOWprev)    R3 = PP * 2 + (HIGHprev - 2 * LOWprev)    S3 = PP * 2 - (2 * HIGHprev - LOWprev)    R4 = PP * 3 + (HIGHprev - 3 * LOWprev)    S4 = PP * 3 - (3 * HIGHprev - LOWprev)    R5 = PP * 4 + (HIGHprev - 4 * LOWprev)    S5 = PP * 4 - (4 * HIGHprev - LOWprev)    [R5, R4, R3, R2, R1, PP, S1, S2, S3, S4, S5]    f_getFibPivots(HIGHprev, LOWprev, CLOSEprev)=>    PP = (HIGHprev + LOWprev + CLOSEprev) / 3    R1 = PP + 0.382 * (HIGHprev - LOWprev)    S1 = PP - 0.382 * (HIGHprev - LOWprev)    R2 = PP + 0.618 * (HIGHprev - LOWprev)    S2 = PP - 0.618 * (HIGHprev - LOWprev)    R3 = PP + (HIGHprev - LOWprev)    S3 = PP - (HIGHprev - LOWprev)    R4 = PP + 1.41 * (HIGHprev - LOWprev)    S4 = PP - 1.41 * (HIGHprev - LOWprev)    R5 = PP + 1.65 * (HIGHprev - LOWprev)    S5 = PP - 1.65 * (HIGHprev - LOWprev)    [R5, R4, R3, R2, R1, PP, S1, S2, S3, S4, S5]    f_getPivotPoints(HTFMultiplier, resolution, ppType)=>    derivedResolution = resolution == ""? f_multiple_resolution(HTFMultiplier) : resolution    HIGHprev = f_secureSecurity(syminfo.tickerid, derivedResolution, high)    LOWprev = f_secureSecurity(syminfo.tickerid, derivedResolution, low)    CLOSEprev = f_secureSecurity(syminfo.tickerid, derivedResolution, close)    [R5, R4, R3, R2, R1, PP, S1, S2, S3, S4, S5] = f_getClassicPivots(HIGHprev, LOWprev, CLOSEprev)    [Rf5, Rf4, Rf3, Rf2, Rf1, PPf, Sf1, Sf2, Sf3, Sf4, Sf5] = f_getFibPivots(HIGHprev, LOWprev, CLOSEprev)    [R5, R4, R3, R2, R1, PP, S1, S2, S3, S4, S5]f_getState(Source, R5, R4, R3, R2, R1, PP, S1, S2, S3, S4, S5)=>    state =     Source > R5 ? 5 :     Source > R4 ? 4 :     Source > R3 ? 3 :      Source > R2 ? 2 :     Source > R1 ? 1 :     Source > PP ? 0 :     Source > S1 ? -1 :     Source > S2 ? -2 :     Source > S3 ? -3 :     Source > S4 ? -4 :     Source > S5 ? -5 : -6    state[R5, R4, R3, R2, R1, PP, S1, S2, S3, S4, S5] = f_getPivotPoints(HTFMultiplier, resolution, ppType)[date, mth, yr] = f_getBackTestTimeFrom(backtestFrom, backtestBars)inDateRange = time >= timestamp(syminfo.timezone, yr, mth, date, 0, 0)BBU5 = plot(not hideBands ? R5: na, title="R5", color=color.orange, linewidth=1, transp=50, style=plot.style_linebr)BBU4 = plot(not hideBands ? R4: na, title="R4", color=color.yellow, linewidth=1, transp=50, style=plot.style_linebr)BBU3 = plot(not hideBands ? R3: na, title="R3", color=color.navy, linewidth=1, transp=50, style=plot.style_linebr)BBU2 = plot(not hideBands ? R2: na, title="R2", color=color.olive, linewidth=1, transp=50, style=plot.style_linebr)BBU1 = plot(not hideBands ? R1: na, title="R1", color=color.lime, linewidth=1, transp=50, style=plot.style_linebr)BBM4 = plot(not hideBands ? PP:na, title="PP", color=color.black, linewidth=2, style=plot.style_linebr)BBL1 = plot(not hideBands ? S1: na, title="S1", color=color.lime, linewidth=1, transp=50, style=plot.style_linebr)BBL2 = plot(not hideBands ? S2: na, title="S2", color=color.olive, linewidth=1, transp=50, style=plot.style_linebr)BBL3 = plot(not hideBands ? S3: na, title="S3", color=color.navy, linewidth=1, transp=50, style=plot.style_linebr)BBL4 = plot(not hideBands ? S4: na, title="S4", color=color.yellow, linewidth=1, transp=50, style=plot.style_linebr)BBL5 = plot(not hideBands ? S5: na, title="S5", color=color.orange, linewidth=1, transp=50, style=plot.style_linebr)fill(BBU5, BBU4, title="RZ5", color=color.green, transp=90)fill(BBU4, BBU3, title="RZ4", color=color.lime, transp=90)fill(BBU3, BBU2, title="RZ3", color=color.olive, transp=90)fill(BBU2, BBU1, title="RZ2", color=color.navy, transp=90)fill(BBU1, BBM4, title="RZ1", color=color.yellow, transp=90)fill(BBM4, BBL1, title="SZ1", color=color.orange, transp=90)fill(BBL1, BBL2, title="SZ2", color=color.red, transp=90)fill(BBL2, BBL3, title="SZ3", color=color.maroon, transp=90)fill(BBL3, BBL4, title="SZ4", color=color.maroon, transp=90)fill(BBL4, BBL5, title="SZ5", color=color.maroon, transp=90)strategy.risk.allow_entry_in(tradeDirection)longCondition = crossover(Source[1],R1) and inDateRangeshortCondition = crossunder(Source[1], S2) and inDateRangestrategy.entry("Buy", strategy.long, when=longCondition, oca_name="oca", oca_type=strategy.oca.cancel)strategy.entry("Sell", strategy.short, when=shortCondition, oca_name="oca", oca_type=strategy.oca.cancel)