Skip to content
ChartDeck ChartScript docs Account Open the terminal

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 })
ParameterTypeDescription
idconst stringThe 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.
pricefloatdefault naThe price the event is about (na when none).
sideintdefault 01 = up / bullish / support, -1 = down / bearish / resistance, 0 = neither.
strengthfloatdefault naHow strong, on your own scale (na when not given).
textstringdefault ""A short plain text (at most 64 characters).
backintdefault 0How many bars back the event is about (0 = this bar). A pivot found 5 bars late is shared with back: 5.

Example

ChartScriptFragmentOpen in editor
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 })
ParameterTypeDescription
idconst stringThe 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.
keystringWhat 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.
pricefloatThe level's price (the middle of a zone).
topfloatdefault naThe top of a zone (na for a line).
bottomfloatdefault naThe bottom of a zone (na for a line).
namestringdefault ""A short name (at most 24 characters), such as "PDH".
kindstringdefault ""Your own word for the kind of level, such as "R", "S" or "zone".
sideintdefault 01 = support / bullish, -1 = resistance / bearish, 0 = neither.
strengthfloatdefault naHow strong, on your own scale (na when not given).

Example

ChartScriptFragmentOpen in editor
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)
ParameterTypeDescription
idconst stringThe 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.
keystringThe key the level was shared with.

Example

ChartScriptFragmentOpen in editor
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 })
ParameterTypeDescription
idconst stringThe 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.
valuefloatThe value to share on each bar: a number or a bool.
titleconst stringdefault ""A name shown to people who link the script.
formatconst formatdefault naThe number format (format.*), for readers that show the value.
precisionconst intdefault naDecimals, for readers that show the value.

Example

ChartScriptFragmentOpen in editor
share.series("trend", math.sign(ta.ema(close, 21) - ta.ema(close, 55)), { title: "Trend (-1 / 0 / 1)" })

Since ChartScript 1

The ChartScript documentation is in English for now; translations will follow.