share
Values this script shares with scripts that link to it (link.script, input.script). Only what is shared here can be read by another script: never the code, plots, drawings or inputs.
#Functions
#share.eventfunction
Shares "this happened on this bar". The linking script reads the events delivered on a bar as h.events.<id>. An event is delivered on the bar it is shared, also when it is about an earlier bar (back). At most 8 events per id per bar.
share.event(id: const string, { price?: float = na, side?: int = 0, strength?: float = na, text?: string = "", back?: int = 0 })| Parameter | Type | Description |
|---|---|---|
id | const string | The share's id: a constant text of lower-case letters, digits and _ (it starts with a letter, at most 24 characters). The linking script reads it by this id. |
price | floatdefault na | The price the event is about (na when none). |
side | intdefault 0 | 1 = up / bullish / support, -1 = down / bearish / resistance, 0 = neither. |
strength | floatdefault na | How strong, on your own scale (na when not given). |
text | stringdefault "" | A short plain text (at most 64 characters). |
back | intdefault 0 | How many bars back the event is about (0 = this bar). A pivot found 5 bars late is shared with back: 5. |
Example
const ph = ta.pivothigh(high, 5, 5)
if (!na(ph)) {
share.event("pivot", { price: ph, side: -1, back: 5, text: "Pivot high" })
}Since ChartScript 1
#share.levelfunction
Shares a price level (or a zone with top and bottom) that stays active until share.level_end. Calling it again with the same key updates the level. The linking script reads the levels active on a bar as h.levels.<id>. At most 500 active levels per id (the oldest ends first).
share.level(id: const string, key: string, price: float, { top?: float = na, bottom?: float = na, name?: string = "", kind?: string = "", side?: int = 0, strength?: float = na })share.level(id: const string, key: int, price: float, { top?: float = na, bottom?: float = na, name?: string = "", kind?: string = "", side?: int = 0, strength?: float = na })| Parameter | Type | Description |
|---|---|---|
id | const string | The share's id: a constant text of lower-case letters, digits and _ (it starts with a letter, at most 24 characters). The linking script reads it by this id. |
key | string | What names this level inside the id: a text or a whole number (for example "R1", or a bar time). The same key updates or ends the same level. |
price | float | The level's price (the middle of a zone). |
top | floatdefault na | The top of a zone (na for a line). |
bottom | floatdefault na | The bottom of a zone (na for a line). |
name | stringdefault "" | A short name (at most 24 characters), such as "PDH". |
kind | stringdefault "" | Your own word for the kind of level, such as "R", "S" or "zone". |
side | intdefault 0 | 1 = support / bullish, -1 = resistance / bearish, 0 = neither. |
strength | floatdefault na | How strong, on your own scale (na when not given). |
Example
const ph = ta.pivothigh(high, 5, 5)
if (!na(ph)) {
share.level("pivots", "H" + str.tostring(time[5]), ph, { name: "PH", kind: "R", side: -1 })
}Since ChartScript 1
#share.level_endfunction
Ends an active shared level. A key that is not active writes one log line and is otherwise ignored.
share.level_end(id: const string, key: string)share.level_end(id: const string, key: int)| Parameter | Type | Description |
|---|---|---|
id | const string | The share's id: a constant text of lower-case letters, digits and _ (it starts with a letter, at most 24 characters). The linking script reads it by this id. |
key | string | The key the level was shared with. |
Example
state key = ""
const ph = ta.pivothigh(high, 5, 5)
if (!na(ph)) {
key = "H" + str.tostring(time[5])
share.level("pivots", key, ph)
}
if (key != "" && close > ta.highest(high, 20)[1]) {
share.level_end("pivots", key)
key = ""
}Since ChartScript 1
#share.seriesfunction
Shares one value per bar under an id. The linking script reads it as h.<id>, with history (h.<id>[1]). Top level only, once per id; it is not drawn and costs one column.
share.series(id: const string, value: float, { title?: const string = "", format?: const format = na, precision?: const int = na })share.series(id: const string, value: bool, { title?: const string = "", format?: const format = na, precision?: const int = na })| Parameter | Type | Description |
|---|---|---|
id | const string | The share's id: a constant text of lower-case letters, digits and _ (it starts with a letter, at most 24 characters). The linking script reads it by this id. |
value | float | The value to share on each bar: a number or a bool. |
title | const stringdefault "" | A name shown to people who link the script. |
format | const formatdefault na | The number format (format.*), for readers that show the value. |
precision | const intdefault na | Decimals, for readers that show the value. |
Example
share.series("trend", math.sign(ta.ema(close, 21) - ta.ema(close, 55)), { title: "Trend (-1 / 0 / 1)" })Since ChartScript 1