Mis à jour
TECore_StableSort_TickRound_TextScan

## 0. Using it: import it into your own script
A library is not a chart tool. Its job is to be imported by another Pine script, which then calls its
functions. Once it is published, add this line under your own `indicator(...)` or `strategy(...)` line:
```
import TradersEdgeUSA/TECore_StableSort_TickRound_TextScan/<version> as lib
```
`<version>` is the number TradingView shows on the published script page (the first publication is `1`).
Call any export as `lib.<name>(...)`. The exported functions and types, exactly as declared:
- `stableIsortIdx(array<int> idx, array<float> key, bool desc)` — stable insertion sort of an index array by key[element], in place. Strict comparison, so equal keys keep their input order (the same order as a stable sort). If any element is not a valid index into key, the array is returned UNSORTED rather than throwing.
- `sliceF(array<float> a, int i0, int i1)` — a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
- `sliceI(array<int> a, int i0, int i1)` — a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
- `tickDecimals(float t)` — the fewest decimals d (0 to 10) at which t × 10^d is an integer within 1e-9. 0.25 → 2, 0.1 → 1, 0.005 → 3, 1 → 0
- `roundToTick(float px, float tick)` — round a price to the nearest multiple of the tick as round(px / tick) × units / 10^d, with units = round(tick × 10^d): integers and one division, so the result is the correctly rounded decimal. A tick ≤ 0 is treated as 0.01
- `withinBand(float price, float reference)` — whether a price is positive and, when the reference is a positive number, within 0.65 × to 1.35 × of it
- `roundStepFor(float lo, float hi, int maxLevels, array<float> ladder)` — the first rung s of the ladder (ascending) at which (hi − lo) / s ≤ maxLevels; the last rung when none qualifies; na when hi ≤ lo. The ladder must not be empty
- `roundNumbersInto(float lo, float hi, float rStep, array<float> cP, array<int> cT, array<int> cL, int ty, int lb)` — append every multiple of rStep from ceil(lo / rStep) × rStep up to hi to three parallel arrays, each tagged with the caller's two codes. At most 2,000 values, a guard that cannot bind when rStep comes from roundStepFor
- `dateKeyIn(int t, string tz = "America/New_York")` — the calendar date of t in a timezone as one integer, year × 10000 + month × 100 + day
- `minuteOfDayIn(int t, string tz = "America/New_York")` — the minute of the day of t in a timezone, hour × 60 + minute
- `sessionWindowStart(int firstOpen, int sessions, string tz = "America/New_York", int openHour = 18, int openMinute = 0, int skipA = dayofweek.friday, int skipB = dayofweek.saturday)` — walk back from one session open to the open `sessions − 1` sessions earlier. Each step goes 20 hours back, re-anchors to openHour:openMinute on that calendar date in tz, and counts unless the new open falls on skipA or skipB; at most 60 steps. The 20-hour step reaches the previous date only for openHour 0 to 19
- `isDigit(string ch)` — whether ch is exactly one character from 0 to 9
- `isLetter(string ch)` — whether ch is exactly one ASCII letter
- `charAt(string s, int i, int n)` — the character of s at index i, or "" when i is outside 0 .. n − 1
- `pricesFromText(string s, int maxOut = 40)` — every positive number written in free text, in text order and without duplicates, under the scan rules in the header (thousands groups, one decimal part, range tails; a number touching a letter, ".", ":", "%" or a lone "-" is refused)
- `unitsForRisk(float usd, float pts, float pv)` — how many whole units fit a currency budget when each unit risks `pts` points at `pv` currency per point: floor(usd / (pts × pv) + 1e-9); 0 unless all three are positive
- `trancheAlloc(int N, float s1, float s2, float s3, bool t2Round)` — split N whole units into three tranches and a remainder: a1 = min(N, max(1, round(s1 × N))); a2 = min(round (t2Round) or floor(s2 × N), N − a1); a3 = min(floor(s3 × N), N − a1 − a2); remainder = N − a1 − a2 − a3. A negative N counts as 0
- `wilderAtrOf(array<float> h, array<float> l, array<float> c, int nAtr)` — Wilder's ATR (TE Math's Atr: the mean of the first nAtr true ranges, then (ATR × (nAtr − 1) + TR) / nAtr) folded over whole arrays, oldest first; na unless at least nAtr + 1 bars are given and nAtr ≥ 1
- `medianVolumeRatio(array<float> vols, int lookback)` — the median of the last `lookback` values divided by the median of all of them; na unless there are at least 2 × lookback values and the overall median is positive
- `percentileOfLast(array<float> atrs, int cap, int minN)` — 100 × the mid-rank of the LAST value among up to `cap` values before it, by TE Math's Rank ((count strictly below + half the exact ties) / n); na until `minN` values are held or when the last value is na. The last value is rated before it would join, never against itself
The on-chart table described below belongs to the library itself: an importing script receives none of
it, only the functions above.
## 1. Seeing its own readout on a chart (optional)
1. Open the **Pine Editor** at the bottom of a TradingView chart.
2. Paste the contents of `te_core_lib_v2.pine` from this folder.
3. **Save it under a new name** — never overwrite an existing script.
4. Click **Add to chart**.
⚠️ **TradingView pins a study to the version it was added at.** Saving a newer version does *not*
upgrade a chart that already has it — remove the study and re-add it. Check you got the new one by
its version and its number of settings, never by "I loaded it".
## 2. What appears, and what each part is telling you
Every readout explains itself **on hover** — in plain language first, then the formula, then why
that number matters, then what it does *not* tell you. Hover anything you are unsure about; that is
the fastest way to learn this tool, and it is the same four questions every time.
The hover text below is reproduced exactly as the script composes it, which is why `⟨live value⟩`
appears: that is the spot where a number calculated from **your** chart on **that** bar gets dropped
in. On screen you will see the number, not the marker — and that is the whole point of the design.
The explanation is about the bar you are looking at, not a dictionary entry about the concept.
**The midpoint of the last closed bar, (high + low) / 2, rounded to this symbol's tick of ⟨live value⟩: ⟨live value⟩.**
- *How it is computed:* roundToTick: d = the fewest decimals at which the tick is a whole number, then round(price / tick) × round(tick × 10^d) / 10^d, integers and one division.
- *Why it matters:* A price computed from other prices rarely lands on the grid a market actually trades on; this puts it back on that grid without leaving binary residue in the last digits.
- *What it does not tell you:* It is arithmetic on one bar; the midpoint is not a level and says nothing about what price does next.
**Over the last ⟨live value⟩ closed bars (⟨live value⟩ to ⟨live value⟩) the round-number step is ⟨live value⟩, giving ⟨live value⟩ multiples inside that span.**
- *How it is computed:* roundStepFor takes the first rung of a ladder from 0.0001 to 10,000 at which (high − low) / rung ≤ 8; roundNumbersInto lists every multiple of it from ceil(low / step) × step up to the high.
- *Why it matters:* It scales round numbers to whatever the symbol trades at, so a 1.10 currency pair and a 60,000 coin both get a handful of lines rather than none or thousands.
- *What it does not tell you:* Round numbers are a reference grid, not support or resistance; nothing here says price reacts at them.
**The last closed bar opened on ⟨live value⟩ in this symbol's exchange time zone, ⟨live value⟩.**
- *How it is computed:* dateKeyIn = year × 10000 + month × 100 + day and minuteOfDayIn = hour × 60 + minute, both resolved by the time-zone database, so daylight-saving changes are handled.
- *Why it matters:* One integer per calendar date and per minute makes it cheap to group bars by day or by time of day in the market's own clock, whatever time zone the viewer is in.
- *What it does not tell you:* It is a calendar label; it knows nothing about holidays or which hours a market is open.
**Wilder's average true range over the last ⟨live value⟩ closed bars, length ⟨live value⟩: ⟨live value⟩.**
- *How it is computed:* wilderAtrOf folds the arrays oldest first: the mean of the first 14 true ranges, then ATR = (ATR × 13 + true range) / 14; true range = max(high − low, |high − prior close|, |low − prior close|).
- *Why it matters:* It is the same estimator as ta.atr, computed from stored arrays, which is what a script needs when its bars are aggregated rather than the chart's own.
- *What it does not tell you:* Seeded at the start of the window, it can differ slightly from an ATR run over the whole history; it measures how far bars travelled, not which way they go next.
**Where the latest ATR 14 reading sits among up to 499 readings before it: ⟨live value⟩.**
- *How it is computed:* percentileOfLast = 100 × (count strictly below + half the exact ties) / count, the latest reading rated before it joins; it waits for 50 earlier readings.
- *Why it matters:* It turns an ATR in points, which cannot be compared across symbols, into a position within this symbol's own recent history.
- *What it does not tell you:* A percentile describes the past readings it was given; it names no band and does not say whether volatility will rise or fall.
**The median volume of the last ⟨live value⟩ closed bars against the median of the last ⟨live value⟩: ⟨live value⟩.**
- *How it is computed:* medianVolumeRatio = median(last 30 volumes) / median(all volumes held); it needs at least 60 bars and a positive overall median.
- *Why it matters:* Medians keep one enormous bar from dominating the comparison, so the ratio says whether recent bars are typically busier or quieter than usual.
- *What it does not tell you:* On a symbol whose feed carries no volume there is no ratio to show, and it says so; a ratio is not a direction.
## 3. The settings
2 settings, in the order the dialog shows them.
### APPEARANCE
**Theme** — default `Dark` · options: Dark, Light
Which chart background this is drawn for. Changing it re-picks every colour so text and lines stay legible. It cannot detect your theme automatically, so set it to match your chart.
**Hover tooltips (on-chart explanations)** — default `true`
Shows or hides the explanation that appears when you hover a table cell or a label on the chart. Off removes that hover text only: every printed value, line, zone and alert is unchanged, and nothing is recomputed. Explanations in this settings dialog are not affected.
## 4. When not to trust it
Taken from the script's own limit clauses — these are the things it will never tell you, and it says
so on the chart rather than hiding them here:
- It is arithmetic on one bar; the midpoint is not a level and says nothing about what price does next.
- Round numbers are a reference grid, not support or resistance; nothing here says price reacts at them.
- It is a calendar label; it knows nothing about holidays or which hours a market is open.
- Seeded at the start of the window, it can differ slightly from an ATR run over the whole history; it measures how far bars travelled, not which way they go next.
- A percentile describes the past readings it was given; it names no band and does not say whether volatility will rise or fall.
- On a symbol whose feed carries no volume there is no ratio to show, and it says so; a ratio is not a direction.
---
_Not financial advice. This tool describes what has already happened; it does not predict
Library "TECore_StableSort_TickRound_TextScan"
Utility maths for Pine arrays and prices: a stable insertion sort, bounds-checked slices, decimal tick rounding, round-number steps, timezone date and minute keys, a session-open walk, a price-from-text scanner, whole-unit sizing arithmetic, a Wilder ATR over arrays, a median volume ratio and a trailing percentile. No trading rules.
stableIsortIdx(idx, key, desc)
stable insertion sort of an index array by key[element], in place. Strict comparison, so equal keys keep their input order (the same order as a stable sort). If any element is not a valid index into key, the array is returned UNSORTED rather than throwing.
Parameters:
idx (array<int>): the indices to order (each must satisfy 0 ≤ idx[q] < array.size(key))
key (array<float>): the values the indices point into
desc (bool): true sorts by descending key, false by ascending key
Returns: idx, reordered in place
sliceF(a, i0, i1)
a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
Parameters:
a (array<float>): the source array
i0 (int): the first index, inclusive
i1 (int): the end index, exclusive
Returns: a new float array
sliceI(a, i0, i1)
a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
Parameters:
a (array<int>): the source array
i0 (int): the first index, inclusive
i1 (int): the end index, exclusive
Returns: a new int array
tickDecimals(t)
the fewest decimals d (0 to 10) at which t × 10^d is an integer within 1e-9. 0.25 → 2, 0.1 → 1, 0.005 → 3, 1 → 0
Parameters:
t (float): a tick size
Returns: d
roundToTick(px, tick)
round a price to the nearest multiple of the tick as round(px / tick) × units / 10^d, with units = round(tick × 10^d): integers and one division, so the result is the correctly rounded decimal. A tick ≤ 0 is treated as 0.01
Parameters:
px (float): the price
tick (float): the tick size
Returns: the rounded price
withinBand(price, reference)
whether a price is positive and, when the reference is a positive number, within 0.65 × to 1.35 × of it
Parameters:
price (float): the price to test
reference (float): the reference price, or na (or ≤ 0) for no band
Returns: true when the price passes
roundStepFor(lo, hi, maxLevels, ladder)
the first rung s of the ladder (ascending) at which (hi − lo) / s ≤ maxLevels; the last rung when none qualifies; na when hi ≤ lo. The ladder must not be empty
Parameters:
lo (float): the low of the span
hi (float): the high of the span
maxLevels (int): the most multiples of the rung the span may hold
ladder (array<float>): the candidate steps, ascending
Returns: the step, or na
roundNumbersInto(lo, hi, rStep, cP, cT, cL, ty, lb)
append every multiple of rStep from ceil(lo / rStep) × rStep up to hi to three parallel arrays, each tagged with the caller's two codes. At most 2,000 values, a guard that cannot bind when rStep comes from roundStepFor
Parameters:
lo (float): the low of the span
hi (float): the high of the span
rStep (float): the step, > 0
cP (array<float>): receives the prices
cT (array<int>): receives ty once per price
cL (array<int>): receives lb once per price
ty (int): the caller's first tag code
lb (int): the caller's second tag code
Returns: true
dateKeyIn(t, tz)
Parameters:
t (int)
tz (string)
minuteOfDayIn(t, tz)
Parameters:
t (int)
tz (string)
sessionWindowStart(firstOpen, sessions, tz, openHour, openMinute, skipA, skipB)
Parameters:
firstOpen (int)
sessions (int)
tz (string)
openHour (int)
openMinute (int)
skipA (int)
skipB (int)
isDigit(ch)
Parameters:
ch (string)
isLetter(ch)
Parameters:
ch (string)
charAt(s, i, n)
Parameters:
s (string)
i (int)
n (int)
pricesFromText(s, maxOut)
Parameters:
s (string)
maxOut (int)
unitsForRisk(usd, pts, pv)
Parameters:
usd (float)
pts (float)
pv (float)
trancheAlloc(N, s1, s2, s3, t2Round)
Parameters:
N (int)
s1 (float)
s2 (float)
s3 (float)
t2Round (bool)
wilderAtrOf(h, l, c, nAtr)
Parameters:
h (array<float>)
l (array<float>)
c (array<float>)
nAtr (int)
medianVolumeRatio(vols, lookback)
Parameters:
vols (array<float>)
lookback (int)
percentileOfLast(atrs, cap, minN)
Parameters:
atrs (array<float>)
cap (int)
minN (int)
A library is not a chart tool. Its job is to be imported by another Pine script, which then calls its
functions. Once it is published, add this line under your own `indicator(...)` or `strategy(...)` line:
```
import TradersEdgeUSA/TECore_StableSort_TickRound_TextScan/<version> as lib
```
`<version>` is the number TradingView shows on the published script page (the first publication is `1`).
Call any export as `lib.<name>(...)`. The exported functions and types, exactly as declared:
- `stableIsortIdx(array<int> idx, array<float> key, bool desc)` — stable insertion sort of an index array by key[element], in place. Strict comparison, so equal keys keep their input order (the same order as a stable sort). If any element is not a valid index into key, the array is returned UNSORTED rather than throwing.
- `sliceF(array<float> a, int i0, int i1)` — a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
- `sliceI(array<int> a, int i0, int i1)` — a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
- `tickDecimals(float t)` — the fewest decimals d (0 to 10) at which t × 10^d is an integer within 1e-9. 0.25 → 2, 0.1 → 1, 0.005 → 3, 1 → 0
- `roundToTick(float px, float tick)` — round a price to the nearest multiple of the tick as round(px / tick) × units / 10^d, with units = round(tick × 10^d): integers and one division, so the result is the correctly rounded decimal. A tick ≤ 0 is treated as 0.01
- `withinBand(float price, float reference)` — whether a price is positive and, when the reference is a positive number, within 0.65 × to 1.35 × of it
- `roundStepFor(float lo, float hi, int maxLevels, array<float> ladder)` — the first rung s of the ladder (ascending) at which (hi − lo) / s ≤ maxLevels; the last rung when none qualifies; na when hi ≤ lo. The ladder must not be empty
- `roundNumbersInto(float lo, float hi, float rStep, array<float> cP, array<int> cT, array<int> cL, int ty, int lb)` — append every multiple of rStep from ceil(lo / rStep) × rStep up to hi to three parallel arrays, each tagged with the caller's two codes. At most 2,000 values, a guard that cannot bind when rStep comes from roundStepFor
- `dateKeyIn(int t, string tz = "America/New_York")` — the calendar date of t in a timezone as one integer, year × 10000 + month × 100 + day
- `minuteOfDayIn(int t, string tz = "America/New_York")` — the minute of the day of t in a timezone, hour × 60 + minute
- `sessionWindowStart(int firstOpen, int sessions, string tz = "America/New_York", int openHour = 18, int openMinute = 0, int skipA = dayofweek.friday, int skipB = dayofweek.saturday)` — walk back from one session open to the open `sessions − 1` sessions earlier. Each step goes 20 hours back, re-anchors to openHour:openMinute on that calendar date in tz, and counts unless the new open falls on skipA or skipB; at most 60 steps. The 20-hour step reaches the previous date only for openHour 0 to 19
- `isDigit(string ch)` — whether ch is exactly one character from 0 to 9
- `isLetter(string ch)` — whether ch is exactly one ASCII letter
- `charAt(string s, int i, int n)` — the character of s at index i, or "" when i is outside 0 .. n − 1
- `pricesFromText(string s, int maxOut = 40)` — every positive number written in free text, in text order and without duplicates, under the scan rules in the header (thousands groups, one decimal part, range tails; a number touching a letter, ".", ":", "%" or a lone "-" is refused)
- `unitsForRisk(float usd, float pts, float pv)` — how many whole units fit a currency budget when each unit risks `pts` points at `pv` currency per point: floor(usd / (pts × pv) + 1e-9); 0 unless all three are positive
- `trancheAlloc(int N, float s1, float s2, float s3, bool t2Round)` — split N whole units into three tranches and a remainder: a1 = min(N, max(1, round(s1 × N))); a2 = min(round (t2Round) or floor(s2 × N), N − a1); a3 = min(floor(s3 × N), N − a1 − a2); remainder = N − a1 − a2 − a3. A negative N counts as 0
- `wilderAtrOf(array<float> h, array<float> l, array<float> c, int nAtr)` — Wilder's ATR (TE Math's Atr: the mean of the first nAtr true ranges, then (ATR × (nAtr − 1) + TR) / nAtr) folded over whole arrays, oldest first; na unless at least nAtr + 1 bars are given and nAtr ≥ 1
- `medianVolumeRatio(array<float> vols, int lookback)` — the median of the last `lookback` values divided by the median of all of them; na unless there are at least 2 × lookback values and the overall median is positive
- `percentileOfLast(array<float> atrs, int cap, int minN)` — 100 × the mid-rank of the LAST value among up to `cap` values before it, by TE Math's Rank ((count strictly below + half the exact ties) / n); na until `minN` values are held or when the last value is na. The last value is rated before it would join, never against itself
The on-chart table described below belongs to the library itself: an importing script receives none of
it, only the functions above.
## 1. Seeing its own readout on a chart (optional)
1. Open the **Pine Editor** at the bottom of a TradingView chart.
2. Paste the contents of `te_core_lib_v2.pine` from this folder.
3. **Save it under a new name** — never overwrite an existing script.
4. Click **Add to chart**.
⚠️ **TradingView pins a study to the version it was added at.** Saving a newer version does *not*
upgrade a chart that already has it — remove the study and re-add it. Check you got the new one by
its version and its number of settings, never by "I loaded it".
## 2. What appears, and what each part is telling you
Every readout explains itself **on hover** — in plain language first, then the formula, then why
that number matters, then what it does *not* tell you. Hover anything you are unsure about; that is
the fastest way to learn this tool, and it is the same four questions every time.
The hover text below is reproduced exactly as the script composes it, which is why `⟨live value⟩`
appears: that is the spot where a number calculated from **your** chart on **that** bar gets dropped
in. On screen you will see the number, not the marker — and that is the whole point of the design.
The explanation is about the bar you are looking at, not a dictionary entry about the concept.
**The midpoint of the last closed bar, (high + low) / 2, rounded to this symbol's tick of ⟨live value⟩: ⟨live value⟩.**
- *How it is computed:* roundToTick: d = the fewest decimals at which the tick is a whole number, then round(price / tick) × round(tick × 10^d) / 10^d, integers and one division.
- *Why it matters:* A price computed from other prices rarely lands on the grid a market actually trades on; this puts it back on that grid without leaving binary residue in the last digits.
- *What it does not tell you:* It is arithmetic on one bar; the midpoint is not a level and says nothing about what price does next.
**Over the last ⟨live value⟩ closed bars (⟨live value⟩ to ⟨live value⟩) the round-number step is ⟨live value⟩, giving ⟨live value⟩ multiples inside that span.**
- *How it is computed:* roundStepFor takes the first rung of a ladder from 0.0001 to 10,000 at which (high − low) / rung ≤ 8; roundNumbersInto lists every multiple of it from ceil(low / step) × step up to the high.
- *Why it matters:* It scales round numbers to whatever the symbol trades at, so a 1.10 currency pair and a 60,000 coin both get a handful of lines rather than none or thousands.
- *What it does not tell you:* Round numbers are a reference grid, not support or resistance; nothing here says price reacts at them.
**The last closed bar opened on ⟨live value⟩ in this symbol's exchange time zone, ⟨live value⟩.**
- *How it is computed:* dateKeyIn = year × 10000 + month × 100 + day and minuteOfDayIn = hour × 60 + minute, both resolved by the time-zone database, so daylight-saving changes are handled.
- *Why it matters:* One integer per calendar date and per minute makes it cheap to group bars by day or by time of day in the market's own clock, whatever time zone the viewer is in.
- *What it does not tell you:* It is a calendar label; it knows nothing about holidays or which hours a market is open.
**Wilder's average true range over the last ⟨live value⟩ closed bars, length ⟨live value⟩: ⟨live value⟩.**
- *How it is computed:* wilderAtrOf folds the arrays oldest first: the mean of the first 14 true ranges, then ATR = (ATR × 13 + true range) / 14; true range = max(high − low, |high − prior close|, |low − prior close|).
- *Why it matters:* It is the same estimator as ta.atr, computed from stored arrays, which is what a script needs when its bars are aggregated rather than the chart's own.
- *What it does not tell you:* Seeded at the start of the window, it can differ slightly from an ATR run over the whole history; it measures how far bars travelled, not which way they go next.
**Where the latest ATR 14 reading sits among up to 499 readings before it: ⟨live value⟩.**
- *How it is computed:* percentileOfLast = 100 × (count strictly below + half the exact ties) / count, the latest reading rated before it joins; it waits for 50 earlier readings.
- *Why it matters:* It turns an ATR in points, which cannot be compared across symbols, into a position within this symbol's own recent history.
- *What it does not tell you:* A percentile describes the past readings it was given; it names no band and does not say whether volatility will rise or fall.
**The median volume of the last ⟨live value⟩ closed bars against the median of the last ⟨live value⟩: ⟨live value⟩.**
- *How it is computed:* medianVolumeRatio = median(last 30 volumes) / median(all volumes held); it needs at least 60 bars and a positive overall median.
- *Why it matters:* Medians keep one enormous bar from dominating the comparison, so the ratio says whether recent bars are typically busier or quieter than usual.
- *What it does not tell you:* On a symbol whose feed carries no volume there is no ratio to show, and it says so; a ratio is not a direction.
## 3. The settings
2 settings, in the order the dialog shows them.
### APPEARANCE
**Theme** — default `Dark` · options: Dark, Light
Which chart background this is drawn for. Changing it re-picks every colour so text and lines stay legible. It cannot detect your theme automatically, so set it to match your chart.
**Hover tooltips (on-chart explanations)** — default `true`
Shows or hides the explanation that appears when you hover a table cell or a label on the chart. Off removes that hover text only: every printed value, line, zone and alert is unchanged, and nothing is recomputed. Explanations in this settings dialog are not affected.
## 4. When not to trust it
Taken from the script's own limit clauses — these are the things it will never tell you, and it says
so on the chart rather than hiding them here:
- It is arithmetic on one bar; the midpoint is not a level and says nothing about what price does next.
- Round numbers are a reference grid, not support or resistance; nothing here says price reacts at them.
- It is a calendar label; it knows nothing about holidays or which hours a market is open.
- Seeded at the start of the window, it can differ slightly from an ATR run over the whole history; it measures how far bars travelled, not which way they go next.
- A percentile describes the past readings it was given; it names no band and does not say whether volatility will rise or fall.
- On a symbol whose feed carries no volume there is no ratio to show, and it says so; a ratio is not a direction.
---
_Not financial advice. This tool describes what has already happened; it does not predict
Library "TECore_StableSort_TickRound_TextScan"
Utility maths for Pine arrays and prices: a stable insertion sort, bounds-checked slices, decimal tick rounding, round-number steps, timezone date and minute keys, a session-open walk, a price-from-text scanner, whole-unit sizing arithmetic, a Wilder ATR over arrays, a median volume ratio and a trailing percentile. No trading rules.
stableIsortIdx(idx, key, desc)
stable insertion sort of an index array by key[element], in place. Strict comparison, so equal keys keep their input order (the same order as a stable sort). If any element is not a valid index into key, the array is returned UNSORTED rather than throwing.
Parameters:
idx (array<int>): the indices to order (each must satisfy 0 ≤ idx[q] < array.size(key))
key (array<float>): the values the indices point into
desc (bool): true sorts by descending key, false by ascending key
Returns: idx, reordered in place
sliceF(a, i0, i1)
a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
Parameters:
a (array<float>): the source array
i0 (int): the first index, inclusive
i1 (int): the end index, exclusive
Returns: a new float array
sliceI(a, i0, i1)
a bounds-checked copy of a[i0 .. i1 − 1]: an empty array when the window is empty or out of range, where array.slice would throw a runtime error
Parameters:
a (array<int>): the source array
i0 (int): the first index, inclusive
i1 (int): the end index, exclusive
Returns: a new int array
tickDecimals(t)
the fewest decimals d (0 to 10) at which t × 10^d is an integer within 1e-9. 0.25 → 2, 0.1 → 1, 0.005 → 3, 1 → 0
Parameters:
t (float): a tick size
Returns: d
roundToTick(px, tick)
round a price to the nearest multiple of the tick as round(px / tick) × units / 10^d, with units = round(tick × 10^d): integers and one division, so the result is the correctly rounded decimal. A tick ≤ 0 is treated as 0.01
Parameters:
px (float): the price
tick (float): the tick size
Returns: the rounded price
withinBand(price, reference)
whether a price is positive and, when the reference is a positive number, within 0.65 × to 1.35 × of it
Parameters:
price (float): the price to test
reference (float): the reference price, or na (or ≤ 0) for no band
Returns: true when the price passes
roundStepFor(lo, hi, maxLevels, ladder)
the first rung s of the ladder (ascending) at which (hi − lo) / s ≤ maxLevels; the last rung when none qualifies; na when hi ≤ lo. The ladder must not be empty
Parameters:
lo (float): the low of the span
hi (float): the high of the span
maxLevels (int): the most multiples of the rung the span may hold
ladder (array<float>): the candidate steps, ascending
Returns: the step, or na
roundNumbersInto(lo, hi, rStep, cP, cT, cL, ty, lb)
append every multiple of rStep from ceil(lo / rStep) × rStep up to hi to three parallel arrays, each tagged with the caller's two codes. At most 2,000 values, a guard that cannot bind when rStep comes from roundStepFor
Parameters:
lo (float): the low of the span
hi (float): the high of the span
rStep (float): the step, > 0
cP (array<float>): receives the prices
cT (array<int>): receives ty once per price
cL (array<int>): receives lb once per price
ty (int): the caller's first tag code
lb (int): the caller's second tag code
Returns: true
dateKeyIn(t, tz)
Parameters:
t (int)
tz (string)
minuteOfDayIn(t, tz)
Parameters:
t (int)
tz (string)
sessionWindowStart(firstOpen, sessions, tz, openHour, openMinute, skipA, skipB)
Parameters:
firstOpen (int)
sessions (int)
tz (string)
openHour (int)
openMinute (int)
skipA (int)
skipB (int)
isDigit(ch)
Parameters:
ch (string)
isLetter(ch)
Parameters:
ch (string)
charAt(s, i, n)
Parameters:
s (string)
i (int)
n (int)
pricesFromText(s, maxOut)
Parameters:
s (string)
maxOut (int)
unitsForRisk(usd, pts, pv)
Parameters:
usd (float)
pts (float)
pv (float)
trancheAlloc(N, s1, s2, s3, t2Round)
Parameters:
N (int)
s1 (float)
s2 (float)
s3 (float)
t2Round (bool)
wilderAtrOf(h, l, c, nAtr)
Parameters:
h (array<float>)
l (array<float>)
c (array<float>)
nAtr (int)
medianVolumeRatio(vols, lookback)
Parameters:
vols (array<float>)
lookback (int)
percentileOfLast(atrs, cap, minN)
Parameters:
atrs (array<float>)
cap (int)
minN (int)
Notes de version
v2Added:
floorToTick(x, tick)
Parameters:
x (float)
tick (float)
rMultiple(px, entry, stop)
Parameters:
px (float)
entry (float)
stop (float)
scaledR(px, fill, qty, entry, stop)
Parameters:
px (float)
fill (float)
qty (float)
entry (float)
stop (float)
swingLowAt(a, b, c)
Parameters:
a (float)
b (float)
c (float)
stopUnder(entry, stop, extreme, atr, k, tick)
Parameters:
entry (float)
stop (float)
extreme (float)
atr (float)
k (float)
tick (float)
trailUnder(swing, extreme, close, atr, k, tick)
Parameters:
swing (float)
extreme (float)
close (float)
atr (float)
k (float)
tick (float)
bankedUnits(share, entry, t1, risk, fund, unitRisk)
Parameters:
share (float)
entry (float)
t1 (float)
risk (float)
fund (float)
unitRisk (float)
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.