Pinescript
Pinescript
=
Not equal to. Applicable to expressions of any type.
expr1 != expr2
RETURNS
Boolean value, or series of boolean values.
%
Modulo (integer remainder). Applicable to numerical expressions.
expr1 % expr2
RETURNS
Integer or float value, or series of values
*
Multiplication. Applicable to numerical expressions.
expr1 * expr2
RETURNS
Integer or float value, or series of values
+
Addition or unary plus. Applicable to numerical expressions or strings.
expr1 + expr2
+ expr
RETURNS
Binary `+` for strings returns concatenation of expr1 and expr2
For numbers returns integer or float value, or series of values:
Binary `+` returns expr1 plus expr2.
Unary `+` returns expr (does nothing added just for the symmetry with the unary - operator).
REMARKS
You may use arithmetic operators with numbers as well as with series variables. In case of
usage with series the operators are applied elementwise.
-
Subtraction or unary minus. Applicable to numerical expressions.
expr1 - expr2
- expr
RETURNS
Returns integer or float value, or series of values:
Binary `-` returns expr1 minus expr2.
Unary `-` returns the negation of expr.
REMARKS
You may use arithmetic operators with numbers as well as with series variables. In case of
usage with series the operators are applied elementwise.
/
Division. Applicable to numerical expressions.
expr1 / expr2
RETURNS
Integer or float value, or series of values
<
Less than. Applicable to numerical expressions.
expr1 < expr2
RETURNS
Boolean value, or series of boolean values.
<=
Less than or equal to. Applicable to numerical expressions.
expr1 <= expr2
RETURNS
Boolean value, or series of boolean values.
==
Equal to. Applicable to expressions of any type.
expr1 == expr2
RETURNS
Boolean value, or series of boolean values.
>
Greater than. Applicable to numerical expressions.
expr1 > expr2
RETURNS
Boolean value, or series of boolean values.
>=
Greater than or equal to. Applicable to numerical expressions.
expr1 >= expr2
RETURNS
Boolean value, or series of boolean values.
?:
Ternary conditional operator.
expr1 ? expr2 : expr3
EXAMPLE
a := a[1] // immediately set current value to the same as previous. `na` in the beginning of
history
//@version=4
study("My sma")
sum = price
for i = 1 to length-1
sum / length
plot(my_sma(close,14))
REMARKS
Variable ‘sum’ is a mutable variable and a new value can be given to it by an operator := in
body of the loop. Also note that we recommend to use a built-in function sma for Moving
Average as it calculates faster.
SEE ALSO
sum
if
If statement defines what block of statements must be executed when conditions of the
expression are satisfied.
To have access to and use the if statement, one should specify the version >= 2 of Pine Script
language in the very first line of code, for example: //@version=4
General code form:
var_declarationX = if condition
var_decl_then0
var_decl_then1
…
var_decl_thenN
else
var_decl_else0
var_decl_else1
…
var_decl_elseN
return_expression_else
where
var_declarationX — this variable gets the value of the if statement
condition — if the condition is true, the logic from the block then (var_decl_then0,
var_decl_then1, etc) is used, if the condition is false, the logic from the block ‘else’
(var_decl_else0, var_decl_else1, etc) is used.
return_expression_then, return_expression_else — the last expression from the block then
or from the block else will return the final value of the statement. If declaration of the
variable is in the end, its value will be the result.
The type of returning value of the if statement depends on return_expression_then and
return_expression_else type (their types must match: it is not possible to return an integer
value from then, while you have a string value in else block).
EXAMPLE
close
else
open
else
close
else
"open"
It is possible to omit the else block. In this case if the condition is false, an “empty” value (na,
or false, or “”) will be assigned to the var_declarationX variable.:
EXAMPLE
close
close
else
close[1]
b
else
open
It is possible to ignore the resulting value of an if statement (“var_declarationX=“ can be
omited). It may be useful if you need the side effect of the expression, for example in strategy
trading:
EXAMPLE
if (crossover(source, lower))
oca_name="BollingerBands",
oca_type=strategy.oca.cancel, comment="BBandLE")
else
strategy.cancel(id="BBandLE")
not
Logical negation (NOT). Applicable to boolean expressions.
not expr1
RETURNS
Boolean value, or series of boolean values.
or
Logical OR. Applicable to boolean expressions.
expr1 or expr2
RETURNS
Boolean value, or series of boolean values.
var
var is the keyword used for assigning and one-time initializing of the variable.
Normally, a syntax of assignment of variables, which doesn’t include the keyword var, results
in the value of the variable being overwritten with every update of the data. Contrary to that,
when assigning variables with the keyword var, they can “keep the state” despite the data
updating, only changing it when conditions within if-expressions are met.
Available starting from version 4.
var variable_name = expression
where:
variable_name - any name of the user’s variable that’s allowed in Pine Script (can contain
capital and lowercase Latin characters, numbers, and underscores (_), but can’t start with a
number).
expression - any arithmetic expression, just as with defining a regular variable. The expression
will be calculated and assigned to a variable once.
EXAMPLE
//@version=4
var b = 0.0
var c = 0.0
var green_bars_count = 0
var x = close
b := x
green_bars_count := green_bars_count + 1
if green_bars_count >= 10
var y = close
c := y
plot(a)
plot(b)
plot(c)
The variable ‘a‘ keeps the closing price of the first bar for each bar in the series.
The variable ‘b‘ keeps the closing price of the first “green” bar in the series.
The variable ‘c‘ keeps the closing price of the tenth “green” bar in the series.
Built-In Variables
accdist
Accumulation/distribution index.
TYPE
float
adjustment.dividends
Constant for dividends adjustment type (dividends adjustment is applied).
TYPE
string
SEE ALSO
adjustment.noneadjustment.splitstickerid
adjustment.none
Constant for none adjustment type (no adjustment is applied).
TYPE
string
SEE ALSO
adjustment.splitsadjustment.dividendstickerid
adjustment.splits
Constant for splits adjustment type (splits adjustment is applied).
TYPE
string
SEE ALSO
adjustment.noneadjustment.dividendstickerid
bar_index
Current bar index. Numbering is zero-based, index of the first bar is 0.
TYPE
integer
EXAMPLE
plot(bar_index)
plot(bar_index > 5000 ? close : 0)
REMARKS
Note that bar_index has replaced n variable in version 4.
barmerge.gaps_off
Merge strategy for requested data. Data is merged continuously without gaps, all the gaps are
filled with the previous nearest existing value.
TYPE
bool
SEE ALSO
securitybarmerge.gaps_on
barmerge.gaps_on
Merge strategy for requested data. Data is merged with possible gaps (na values).
TYPE
bool
SEE ALSO
securitybarmerge.gaps_off
barmerge.lookahead_off
Merge strategy for the requested data position. Requested barset is merged with current barset
in the order of sorting bars by their close time. This merge strategy disables effect of getting
data from "future" on calculation on history.
TYPE
bool
SEE ALSO
securitybarmerge.lookahead_on
barmerge.lookahead_on
Merge strategy for the requested data position. Requested barset is merged with current barset
in the order of sorting bars by their opening time. This merge strategy can lead to undesirable
effect of getting data from "future" on calculation on history. This is unacceptable in
backtesting strategies, but can be useful in indicators.
TYPE
bool
SEE ALSO
securitybarmerge.lookahead_off
barstate.isconfirmed
Returns true if the script is calculating the last (closing) update of the current bar. The next
script calculation will be on the new bar data.
TYPE
bool
REMARKS
PineScript code that uses this variable could calculate differently on history and real-time
data.
It is NOT recommended to use barstate.isconfirmed in security expression. Its value requested
from security is unpredictable.
SEE ALSO
barstate.isfirstbarstate.islastbarstate.ishistorybarstate.isrealtimebarstate.isnew
barstate.isfirst
Returns true if current bar is first bar in barset, false otherwise.
TYPE
bool
REMARKS
PineScript code that uses this variable could calculate differently on history and real-time
data.
SEE ALSO
barstate.islastbarstate.ishistorybarstate.isrealtimebarstate.isnewbarstate.isconfirmed
barstate.ishistory
Returns true if current bar is a historical bar, false otherwise.
TYPE
bool
REMARKS
PineScript code that uses this variable could calculate differently on history and real-time
data.
SEE ALSO
barstate.isfirstbarstate.islastbarstate.isrealtimebarstate.isnewbarstate.isconfirmed
barstate.islast
Returns true if current bar is the last bar in barset, false otherwise. This condition is true for
all real-time bars in barset.
TYPE
bool
REMARKS
PineScript code that uses this variable could calculate differently on history and real-time
data.
SEE ALSO
barstate.isfirstbarstate.ishistorybarstate.isrealtimebarstate.isnewbarstate.isconfirmed
barstate.isnew
Returns true if script is currently calculating on new bar, false otherwise. This variable is true
when calculating on historical bars or on first update of a newly generated real-time bar.
TYPE
bool
REMARKS
PineScript code that uses this variable could calculate differently on history and real-time
data.
SEE ALSO
barstate.isfirstbarstate.islastbarstate.ishistorybarstate.isrealtimebarstate.isconfirmed
barstate.isrealtime
Returns true if current bar is a real-time bar, false otherwise.
TYPE
bool
REMARKS
PineScript code that uses this variable could calculate differently on history and real-time
data.
SEE ALSO
barstate.isfirstbarstate.islastbarstate.ishistorybarstate.isnewbarstate.isconfirmed
close
Current close price.
TYPE
float
REMARKS
Previous values may be accessed with square brackets operator [], e.g. close[1], close[2].
SEE ALSO
openhighlowvolumetimehl2hlc3ohlc4
color.aqua
Is a named constant for #00BCD4 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.orange
color.black
Is a named constant for #363A45 color.
TYPE
color
SEE ALSO
color.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolor.greencolo
r.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.blue
Is a named constant for #2196F3 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.limecolor.olivecolor.yellowcolor.navycolor.tealcolor.aquacolor.orange
color.fuchsia
Is a named constant for #E040FB color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.greencolor.
limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.gray
Is a named constant for #787B86 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolor.greencol
or.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.green
Is a named constant for #4CAF50 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.lime
Is a named constant for #00E676 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.maroon
Is a named constant for #880E4F color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.redcolor.purplecolor.fuchsiacolor.greencolor.l
imecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.navy
Is a named constant for #311B92 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.limecolor.olivecolor.yellowcolor.bluecolor.tealcolor.aquacolor.orange
color.olive
Is a named constant for #808000 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.limecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.orange
Is a named constant for #FF9800 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aqua
color.purple
Is a named constant for #9C27B0 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.fuchsiacolor.greencolor
.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.red
Is a named constant for #FF5252 color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.purplecolor.fuchsiacolor.greenco
lor.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.silver
Is a named constant for #B2B5BE color.
TYPE
color
SEE ALSO
color.blackcolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolor.greencolo
r.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.teal
Is a named constant for #00897B color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.aquacolor.orange
color.white
Is a named constant for #FFFFFF color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.marooncolor.redcolor.purplecolor.fuchsiacolor.greencolo
r.limecolor.olivecolor.yellowcolor.navycolor.bluecolor.tealcolor.aquacolor.orange
color.yellow
Is a named constant for #FFEB3B color.
TYPE
color
SEE ALSO
color.blackcolor.silvercolor.graycolor.whitecolor.marooncolor.redcolor.purplecolor.fuchsiacolo
r.greencolor.limecolor.olivecolor.navycolor.bluecolor.tealcolor.aquacolor.orange
currency.AUD
Australian dollar.
TYPE
string
SEE ALSO
strategy
currency.CAD
Canadian dollar.
TYPE
string
SEE ALSO
strategy
currency.CHF
Swiss franc.
TYPE
string
SEE ALSO
strategy
currency.EUR
Euro.
TYPE
string
SEE ALSO
strategy
currency.GBP
Pound sterling.
TYPE
string
SEE ALSO
strategy
currency.HKD
Hong Kong dollar.
TYPE
string
SEE ALSO
strategy
currency.JPY
Japanese yen.
TYPE
string
SEE ALSO
strategy
currency.NOK
Norwegian krone.
TYPE
string
SEE ALSO
strategy
currency.NONE
Unspecified currency.
TYPE
string
SEE ALSO
strategy
currency.NZD
New Zealand dollar.
TYPE
string
SEE ALSO
strategy
currency.RUB
Russian ruble.
TYPE
string
SEE ALSO
strategy
currency.SEK
Swedish krona.
TYPE
string
SEE ALSO
strategy
currency.SGD
Singapore dollar.
TYPE
string
SEE ALSO
strategy
currency.TRY
Turkish lira.
TYPE
string
SEE ALSO
strategy
currency.USD
United States dollar.
TYPE
string
SEE ALSO
strategy
currency.ZAR
South African rand.
TYPE
string
SEE ALSO
strategy
dayofmonth
Date of current bar time in exchange timezone.
TYPE
integer
SEE ALSO
dayofmonthtimeyearmonthweekofyeardayofweekhourminutesecond
dayofweek
Day of week for current bar time in exchange timezone.
TYPE
integer
REMARKS
You can
use dayofweek.sunday, dayofweek.monday, dayofweek.tuesday, dayofweek.wednesday, dayof
week.thursday, dayofweek.friday and dayofweek.saturday variables for comparisons.
SEE ALSO
dayofweektimeyearmonthweekofyeardayofmonthhourminutesecond
dayofweek.friday
Is a named constant for return value of dayofweek function and value of dayofweek variable.
TYPE
integer
SEE ALSO
dayofweek.sundaydayofweek.mondaydayofweek.tuesdaydayofweek.wednesdaydayofweek.thurs
daydayofweek.saturday
dayofweek.monday
Is a named constant for return value of dayofweek function and value of dayofweek variable.
TYPE
integer
SEE ALSO
dayofweek.sundaydayofweek.tuesdaydayofweek.wednesdaydayofweek.thursdaydayofweek.frid
aydayofweek.saturday
dayofweek.saturday
Is a named constant for return value of dayofweek function and value of dayofweek variable.
TYPE
integer
SEE ALSO
dayofweek.sundaydayofweek.mondaydayofweek.tuesdaydayofweek.wednesdaydayofweek.thurs
daydayofweek.friday
dayofweek.sunday
Is a named constant for return value of dayofweek function and value of dayofweek variable.
TYPE
integer
SEE ALSO
dayofweek.mondaydayofweek.tuesdaydayofweek.wednesdaydayofweek.thursdaydayofweek.fri
daydayofweek.saturday
dayofweek.thursday
Is a named constant for return value of dayofweek function and value of dayofweek variable.
TYPE
integer
SEE ALSO
dayofweek.sundaydayofweek.mondaydayofweek.tuesdaydayofweek.wednesdaydayofweek.frida
ydayofweek.saturday
dayofweek.tuesday
Is a named constant for return value of dayofweek function and value of dayofweek variable.
TYPE
integer
SEE ALSO
dayofweek.sundaydayofweek.mondaydayofweek.wednesdaydayofweek.thursdaydayofweek.frid
aydayofweek.saturday
dayofweek.wednesday
Is a named constant for return value of dayofweek function and value of dayofweek variable.
TYPE
integer
SEE ALSO
dayofweek.sundaydayofweek.mondaydayofweek.tuesdaydayofweek.thursdaydayofweek.fridayd
ayofweek.saturday
display.all
A named constant that specifies where the plot is displayed. Display everywhere.
TYPE
integer
SEE ALSO
plotplotshapeplotcharplotarrowplotbarplotcandle
display.none
A named constant that specifies where the plot is displayed. Display nowhere. Available in
alert template message
TYPE
integer
SEE ALSO
plotplotshapeplotcharplotarrowplotbarplotcandle
extend.both
A named constant for line.new and line.set_extend functions
TYPE
string
SEE ALSO
line.newline.set_extendextend.noneextend.leftextend.right
extend.left
A named constant for line.new and line.set_extend functions
TYPE
string
SEE ALSO
line.newline.set_extendextend.noneextend.rightextend.both
extend.none
A named constant for line.new and line.set_extend functions
TYPE
string
SEE ALSO
line.newline.set_extendextend.leftextend.rightextend.both
extend.right
A named constant for line.new and line.set_extend functions
TYPE
string
SEE ALSO
line.newline.set_extendextend.noneextend.leftextend.both
format.inherit
Is a named constant for selecting the formatting of the script output values from the parent
series in the study function.
TYPE
string
SEE ALSO
studyformat.priceformat.volume
format.price
Is a named constant for selecting the formatting of the script output values as prices in
the study function.
TYPE
string
REMARKS
If format is format.price, default precision value is set. You can use the precision argument of
study function to change the precision value.
SEE ALSO
studyformat.inheritformat.volume
format.volume
Is a named constant for selecting the formatting of the script output values as volume in
the study function, e.g. '5183' will be formatted as '5K'
TYPE
string
SEE ALSO
studyformat.inheritformat.price
high
Current high price.
TYPE
float
REMARKS
Previous values may be accessed with square brackets operator [], e.g. high[1], high[2].
SEE ALSO
openlowclosevolumetimehl2hlc3ohlc4
hl2
Is a shortcut for (high + low)/2
TYPE
float
SEE ALSO
openhighlowclosevolumetimehlc3ohlc4
hlc3
Is a shortcut for (high + low + close)/3
TYPE
float
SEE ALSO
openhighlowclosevolumetimehl2ohlc4
hline.style_dashed
Is a named constant for dashed linestyle of hline function.
TYPE
integer
SEE ALSO
hline.style_solidhline.style_dotted
hline.style_dotted
Is a named constant for dotted linestyle of hline function.
TYPE
integer
SEE ALSO
hline.style_solidhline.style_dashed
hline.style_solid
Is a named constant for solid linestyle of hline function.
TYPE
integer
SEE ALSO
hline.style_dottedhline.style_dashed
hour
Current bar hour in exchange timezone.
TYPE
integer
SEE ALSO
hourtimeyearmonthweekofyeardayofmonthdayofweekminutesecond
iii
Intraday Intensity Index
TYPE
float
EXAMPLE
study('My Script')
plot(iii, color=color.yellow)
f_iii() =>
plot(f_iii())
input.bool
Is a named constant for bool input type of input function.
TYPE
string
SEE ALSO
input.integerinput.floatinput.stringinput.symbolinput.resolutioninput.sessioninput.sourceinput
input.float
Is a named constant for float input type of input function.
TYPE
string
SEE ALSO
input.boolinput.integerinput.stringinput.symbolinput.resolutioninput.sessioninput.sourceinput
input.integer
Is a named constant for integer input type of input function.
TYPE
string
SEE ALSO
input.boolinput.floatinput.stringinput.symbolinput.resolutioninput.sessioninput.sourceinput
input.resolution
Is a named constant for resolution input type of input function.
TYPE
string
SEE ALSO
input.boolinput.integerinput.floatinput.stringinput.symbolinput.sessioninput.sourceinput
input.session
Is a named constant for session input type of input function.
TYPE
string
SEE ALSO
input.boolinput.integerinput.floatinput.stringinput.symbolinput.resolutioninput.sourceinput
input.source
Is a named constant for source input type of input function.
TYPE
string
SEE ALSO
input.boolinput.integerinput.floatinput.stringinput.symbolinput.resolutioninput.sessioninput
input.string
Is a named constant for string input type of input function.
TYPE
string
SEE ALSO
input.boolinput.integerinput.floatinput.symbolinput.resolutioninput.sessioninput.sourceinput
input.symbol
Is a named constant for symbol input type of input function.
TYPE
string
SEE ALSO
input.boolinput.integerinput.floatinput.stringinput.resolutioninput.sessioninput.sourceinput
label.style_arrowdown
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightlabel.st
yle_label_centerlabel.style_squarelabel.style_diamond
label.style_arrowup
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrow
downlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightlab
el.style_label_centerlabel.style_squarelabel.style_diamond
label.style_circle
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_arrowuplabel.style_arro
wdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightla
bel.style_label_center label.style_squarelabel.style_diamond
label.style_cross
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_triangl
euplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowuplabel.style_arr
owdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightl
abel.style_label_centerlabel.style_squarelabel.style_diamond
label.style_diamond
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_arrowdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.s
tyle_label_rightlabel.style_label_centerlabel.style_square
label.style_flag
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_circlelabel.style_arrowuplabel.style_ar
rowdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_righ
tlabel.style_label_centerlabel.style_squarelabel.style_diamond
label.style_label_center
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_arrowdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.s
tyle_label_rightlabel.style_squarelabel.style_diamond
label.style_label_down
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_arrowdownlabel.style_label_uplabel.style_label_leftlabel.style_label_rightlabel.st
yle_label_centerlabel.style_squarelabel.style_diamond
label.style_label_left
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_arrowdownlabel.style_label_uplabel.style_label_downlabel.style_label_rightlabel.
style_label_centerlabel.style_squarelabel.style_diamond
label.style_label_right
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_arrowdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.s
tyle_label_centerlabel.style_squarelabel.style_diamond
label.style_label_up
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_arrowdownlabel.style_label_downlabel.style_label_leftlabel.style_label_rightlabel
.style_label_centerlabel.style_squarelabel.style_diamond
label.style_none
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_xcrosslabel.style_crosslabel.style_triangl
euplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowuplabel.style_arr
owdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightl
abel.style_label_centerlabel.style_squarelabel.style_diamond
label.style_square
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowu
plabel.style_arrowdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.s
tyle_label_rightlabel.style_label_centerlabel.style_diamond
label.style_triangledown
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangleuplabel.style_flaglabel.style_circlelabel.style_arrowuplabel.style_arrowdownl
abel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightlabel.styl
e_label_centerlabel.style_squarelabel.style_diamond
label.style_triangleup
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_xcrosslabel.style_crossla
bel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowuplabel.style_arrowdo
wnlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightlabel.
style_label_centerlabel.style_squarelabel.style_diamond
label.style_xcross
Label style for label.new and label.set_style functions
TYPE
string
SEE ALSO
label.newlabel.set_stylelabel.set_textalignlabel.style_nonelabel.style_crosslabel.style_triangle
uplabel.style_triangledownlabel.style_flaglabel.style_circlelabel.style_arrowuplabel.style_arro
wdownlabel.style_label_uplabel.style_label_downlabel.style_label_leftlabel.style_label_rightla
bel.style_label_center label.style_squarelabel.style_diamond
line.style_arrow_both
Line style for line.new and line.set_style functions. Solid line with arrows on both points
TYPE
string
SEE ALSO
line.newline.set_styleline.style_solidline.style_dottedline.style_dashedline.style_arrow_leftlin
e.style_arrow_right
line.style_arrow_left
Line style for line.new and line.set_style functions. Solid line with arrow on the first point
TYPE
string
SEE ALSO
line.newline.set_styleline.style_solidline.style_dottedline.style_dashedline.style_arrow_rightli
ne.style_arrow_both
line.style_arrow_right
Line style for line.new and line.set_style functions. Solid line with arrow on the second point
TYPE
string
SEE ALSO
line.newline.set_styleline.style_solidline.style_dottedline.style_dashedline.style_arrow_leftlin
e.style_arrow_both
line.style_dashed
Line style for line.new and line.set_style functions
TYPE
string
SEE ALSO
line.newline.set_styleline.style_solidline.style_dottedline.style_arrow_leftline.style_arrow_rig
htline.style_arrow_both
line.style_dotted
Line style for line.new and line.set_style functions
TYPE
string
SEE ALSO
line.newline.set_styleline.style_solidline.style_dashedline.style_arrow_leftline.style_arrow_rig
htline.style_arrow_both
line.style_solid
Line style for line.new and line.set_style functions
TYPE
string
SEE ALSO
line.newline.set_styleline.style_dottedline.style_dashedline.style_arrow_leftline.style_arrow_r
ightline.style_arrow_both
location.abovebar
Location value for plotshape, plotchar functions. Shape is plotted above main series bars.
TYPE
string
SEE ALSO
plotshapeplotcharlocation.belowbarlocation.toplocation.bottomlocation.absolute
location.absolute
Location value for plotshape, plotchar functions. Shape is plotted on chart using indicator value
as a price coordinate.
TYPE
string
SEE ALSO
plotshapeplotcharlocation.abovebarlocation.belowbarlocation.toplocation.bottom
location.belowbar
Location value for plotshape, plotchar functions. Shape is plotted below main series bars.
TYPE
string
SEE ALSO
plotshapeplotcharlocation.abovebarlocation.toplocation.bottomlocation.absolute
location.bottom
Location value for plotshape, plotchar functions. Shape is plotted near the bottom chart
border.
TYPE
string
SEE ALSO
plotshapeplotcharlocation.abovebarlocation.belowbarlocation.toplocation.absolute
location.top
Location value for plotshape, plotchar functions. Shape is plotted near the top chart border.
TYPE
string
SEE ALSO
plotshapeplotcharlocation.abovebarlocation.belowbarlocation.bottomlocation.absolute
low
Current low price.
TYPE
float
REMARKS
Previous values may be accessed with square brackets operator [], e.g. low[1], low[2].
SEE ALSO
openhighclosevolumetimehl2hlc3ohlc4
minute
Current bar minute in exchange timezone.
TYPE
integer
SEE ALSO
minutetimeyearmonthweekofyeardayofmonthdayofweekhoursecond
month
Current bar month in exchange timezone.
TYPE
integer
SEE ALSO
monthtimeyearweekofyeardayofmonthdayofweekhourminutesecond
na
Double.NaN value (Not a Number).
TYPE
na
EXAMPLE
//@version=4
study('My Script')
plot(nvi, color=color.yellow)
f_nvi() =>
nvi := prevNvi
else
result = nvi
plot(f_nvi())
obv
On Balance Volume
TYPE
float
EXAMPLE
study('My Script')
plot(obv, color=color.yellow)
f_obv() =>
plot(f_obv())
ohlc4
Is a shortcut for (open + high + low + close)/4
TYPE
float
SEE ALSO
openhighlowclosevolumetimehl2hlc3
open
Current open price.
TYPE
float
REMARKS
Previous values may be accessed with square brackets operator [], e.g. open[1], open[2].
SEE ALSO
highlowclosevolumetimehl2hlc3ohlc4
plot.style_area
Is a named constant for area style of plot function.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_linebrplot.style_steplineplot.style_histogramplot.style_areabrplot.styl
e_crossplot.style_columnsplot.style_circles
plot.style_areabr
Is a named constant for area style of plot function. Same as area but doesn't fill the breaks
(gaps) in data.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_linebrplot.style_steplineplot.style_histogramplot.style_crossplot.style
_areaplot.style_columnsplot.style_circles
plot.style_circles
Is a named constant for circles style of plot function.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_linebrplot.style_steplineplot.style_histogramplot.style_crossplot.style
_areaplot.style_areabrplot.style_columns
plot.style_columns
Is a named constant for columns style of plot function.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_linebrplot.style_steplineplot.style_histogramplot.style_crossplot.style
_areaplot.style_areabrplot.style_circles
plot.style_cross
Is a named constant for cross style of plot function.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_linebrplot.style_steplineplot.style_histogramplot.style_areaplot.style_
areabrplot.style_columnsplot.style_circles
plot.style_histogram
Is a named constant for histogram style of plot function.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_linebrplot.style_steplineplot.style_crossplot.style_areaplot.style_area
brplot.style_columnsplot.style_circles
plot.style_line
Is a named constant for line style of plot function.
TYPE
integer
SEE ALSO
plot.style_linebrplot.style_steplineplot.style_histogramplot.style_crossplot.style_areaplot.style
_areabrplot.style_columnsplot.style_circles
plot.style_linebr
Is a named constant for line style of plot function. Same as line but doesn't fill the breaks
(gaps) in data.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_steplineplot.style_histogramplot.style_crossplot.style_areaplot.style_
areabrplot.style_columnsplot.style_circles
plot.style_stepline
Is a named constant for stepline style of plot function.
TYPE
integer
SEE ALSO
plot.style_lineplot.style_linebrplot.style_histogramplot.style_crossplot.style_areaplot.style_ar
eabrplot.style_columnsplot.style_circles
pvi
Positive Volume Index
TYPE
float
EXAMPLE
//@version=4
study('My Script')
plot(pvi, color=color.yellow)
f_pvi() =>
pvi := prevPvi
else
result = pvi
plot(f_pvi())
pvt
Price-Volume Trend
TYPE
float
EXAMPLE
study('My Script')
plot(pvt, color=color.yellow)
f_pvt() =>
plot(f_pvt())
scale.left
Scale value for study function. Study is added to the left price scale.
TYPE
integer
SEE ALSO
study
scale.none
Scale value for study function. Study is added in 'No Scale' mode. Can be used only with
'overlay=true'.
TYPE
integer
SEE ALSO
study
scale.right
Scale value for study function. Study is added to the right price scale.
TYPE
integer
SEE ALSO
study
second
Current bar second in exchange timezone.
TYPE
integer
SEE ALSO
secondtimeyearmonthweekofyeardayofmonthdayofweekhourminute
session.extended
Constant for extended session type (with extended hours data).
TYPE
string
SEE ALSO
session.regularsyminfo.session
session.regular
Constant for regular session type (no extended hours data).
TYPE
string
SEE ALSO
session.extendedsyminfo.session
shape.arrowdown
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.arrowup
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.circle
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.cross
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.diamond
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.flag
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.labeldown
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.labelup
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.square
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.triangledown
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.triangleup
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
shape.xcross
Shape style for plotshape function.
TYPE
string
SEE ALSO
plotshape
size.auto
Size value for plotshape, plotchar functions. The size of the shape automatically adapts to the
size of the bars.
TYPE
string
SEE ALSO
plotshapeplotcharlabel.set_sizesize.tinysize.smallsize.normalsize.largesize.huge
size.huge
Size value for plotshape, plotchar functions. The size of the shape constantly huge.
TYPE
string
SEE ALSO
plotshapeplotcharlabel.set_sizesize.autosize.tinysize.smallsize.normalsize.large
size.large
Size value for plotshape, plotchar functions. The size of the shape constantly large.
TYPE
string
SEE ALSO
plotshapeplotcharlabel.set_sizesize.autosize.tinysize.smallsize.normalsize.huge
size.normal
Size value for plotshape, plotchar functions. The size of the shape constantly normal.
TYPE
string
SEE ALSO
plotshapeplotcharlabel.set_sizesize.autosize.tinysize.smallsize.largesize.huge
size.small
Size value for plotshape, plotchar functions. The size of the shape constantly small.
TYPE
string
SEE ALSO
plotshapeplotcharlabel.set_sizesize.autosize.tinysize.normalsize.largesize.huge
size.tiny
Size value for plotshape, plotchar functions. The size of the shape constantly tiny.
TYPE
string
SEE ALSO
plotshapeplotcharlabel.set_sizesize.autosize.smallsize.normalsize.largesize.huge
strategy.cash
If the number of contracts/shares/lots/units to buy/sell is not specified
for strategy.entry or strategy.order commands (or 'NaN' is specified), then strategy will
calculate the quantity to buy/sell at close of current bar using the amount of money specified
in the 'default_qty_value'.
TYPE
string
SEE ALSO
strategy
strategy.closedtrades
Number of trades, which were closed for the whole trading interval.
TYPE
integer
SEE ALSO
strategy.position_sizestrategy.opentradesstrategy.wintradesstrategy.losstradesstrategy.eventra
des
strategy.commission.cash_per_contract
Commission type for an order. Money displayed in the account currency per contract.
TYPE
string
SEE ALSO
strategy
strategy.commission.cash_per_order
Commission type for an order. Money displayed in the account currency per order.
TYPE
string
SEE ALSO
strategy
strategy.commission.percent
Commission type for an order. A percentage of the cash volume of order.
TYPE
string
SEE ALSO
strategy
strategy.direction.all
It allows strategy to open both long and short positions.
TYPE
string
SEE ALSO
strategy.risk.allow_entry_in
strategy.direction.long
It allows strategy to open only long positions.
TYPE
string
SEE ALSO
strategy.risk.allow_entry_in
strategy.direction.short
It allows strategy to open only short positions.
TYPE
string
SEE ALSO
strategy.risk.allow_entry_in
strategy.equity
Current equity ( strategy.initial_capital + strategy.netprofit + strategy.openprofit ).
TYPE
float
SEE ALSO
strategy.netprofitstrategy.openprofitstrategy.position_size
strategy.eventrades
Number of breakeven trades for the whole trading interval.
TYPE
integer
SEE ALSO
strategy.position_sizestrategy.opentradesstrategy.closedtradesstrategy.wintradesstrategy.losst
rades
strategy.fixed
If the number of contracts/shares/lots/units to buy/sell is not specified
for strategy.entry or strategy.order commands (or 'NaN' is specified), then the
'default_qty_value' is used to define the quantity.
TYPE
string
SEE ALSO
strategy
strategy.grossloss
Total currency value of all completed losing trades.
TYPE
float
SEE ALSO
strategy.netprofitstrategy.grossprofit
strategy.grossprofit
Total currency value of all completed winning trades.
TYPE
float
SEE ALSO
strategy.netprofitstrategy.grossloss
strategy.initial_capital
The amount of initial capital set in the strategy properties.
TYPE
float
SEE ALSO
strategy
strategy.long
Long position entry.
TYPE
bool
SEE ALSO
strategy.entrystrategy.exitstrategy.order
strategy.losstrades
Number of unprofitable trades for the whole trading interval.
TYPE
integer
SEE ALSO
strategy.position_sizestrategy.opentradesstrategy.closedtradesstrategy.wintradesstrategy.even
trades
strategy.max_contracts_held_all
Maximum number of contracts/shares/lots/units in one trade for the whole trading interval.
TYPE
float
SEE ALSO
strategy.position_sizestrategy.max_contracts_held_longstrategy.max_contracts_held_short
strategy.max_contracts_held_long
Maximum number of contracts/shares/lots/units in one long trade for the whole trading
interval.
TYPE
float
SEE ALSO
strategy.position_sizestrategy.max_contracts_held_all strategy.max_contracts_held_short
strategy.max_contracts_held_short
Maximum number of contracts/shares/lots/units in one short trade for the whole trading
interval.
TYPE
float
SEE ALSO
strategy.position_sizestrategy.max_contracts_held_all strategy.max_contracts_held_long
strategy.max_drawdown
Maximum equity drawdown value for the whole trading interval.
TYPE
float
SEE ALSO
strategy.netprofitstrategy.equity
strategy.netprofit
Total currency value of all completed trades.
TYPE
float
SEE ALSO
strategy.openprofitstrategy.position_sizestrategy.grossprofitstrategy.grossloss
strategy.oca.cancel
OCA type value for strategy's functions. The parameter determines that an order should belong
to an OCO group, where as soon as an order is filled, all other orders of the same group are
cancelled. Note: if more than 1 guaranteed-to-be-executed orders of the same OCA group are
placed at once, all those orders are filled.
TYPE
string
SEE ALSO
strategy.entrystrategy.exitstrategy.order
strategy.oca.none
OCA type value for strategy's functions. The parameter determines that an order should not
belong to any particular OCO group.
TYPE
string
SEE ALSO
strategy.entrystrategy.exitstrategy.order
strategy.oca.reduce
OCA type value for strategy's functions. The parameter determines that an order should belong
to an OCO group, where if X number of contracts of an order is filled, number of contracts for
each other order of the same OCO group is decreased by X. Note: if more than 1 guaranteed-to-
be-executed orders of the same OCA group are placed at once, all those orders are filled.
TYPE
string
SEE ALSO
strategy.entrystrategy.exitstrategy.order
strategy.openprofit
Current unrealized profit or loss for the open position.
TYPE
float
SEE ALSO
strategy.netprofitstrategy.position_size
strategy.opentrades
Number of market position entries, which were not closed and remain opened. If there is no
open market position, 0 is returned.
TYPE
integer
SEE ALSO
strategy.position_size
strategy.percent_of_equity
If the number of contracts/shares/lots/units to buy/sell is not specified
for strategy.entry or strategy.order commands (or 'NaN' is specified), then strategy will
calculate the quantity to buy/sell at close of current bar using the amount of money specified
by the 'default_qty_value' in % from current strategy.equity (in the range from 0 to 100).
TYPE
string
SEE ALSO
strategy
strategy.position_avg_price
Average entry price of current market position. If the market position is flat, 'NaN' is returned.
TYPE
float
SEE ALSO
strategy.position_size
strategy.position_entry_name
Name of the order that initially opened current market position.
TYPE
string
SEE ALSO
strategy.position_size
strategy.position_size
Direction and size of the current market position. If the value is > 0, the market position is
long. If the value is < 0, the market position is short. The absolute value is the number of
contracts/shares/lots/units in trade (position size).
TYPE
float
SEE ALSO
strategy.position_avg_price
strategy.short
Short position entry.
TYPE
bool
SEE ALSO
strategy.entrystrategy.exitstrategy.order
strategy.wintrades
Number of profitable trades for the whole trading interval.
TYPE
integer
SEE ALSO
strategy.position_sizestrategy.opentradesstrategy.closedtradesstrategy.losstradesstrategy.even
trades
syminfo.currency
Currency for the current symbol. Returns currency code: "USD", "EUR", etc.
TYPE
string
SEE ALSO
syminfo.tickercurrency.USDcurrency.EUR
syminfo.description
Description for the current symbol.
TYPE
string
SEE ALSO
syminfo.tickersyminfo.prefix
syminfo.mintick
Min tick value for the current symbol.
TYPE
float
SEE ALSO
syminfo.pointvalue
syminfo.pointvalue
Point value for the current symbol.
TYPE
float
SEE ALSO
syminfo.mintick
syminfo.prefix
Prefix of current symbol name (i.e. for 'CME_EOD:TICKER' prefix is 'CME_EOD').
TYPE
string
EXAMPLE
study('My Script')
plot(wad, color=color.yellow)
f_wad() =>
mom = change(close)
return = cum(gain)
plot(f_wad())
weekofyear
Week number of current bar time in exchange timezone.
TYPE
integer
SEE ALSO
weekofyeartimeyearmonthdayofmonthdayofweekhourminutesecond
wvad
Williams Variable Accumulation/Distribution
TYPE
float
EXAMPLE
study('My Script')
plot(wvad, color=color.yellow)
f_wvad() =>
norm = 0.0
sum = 0.0
for i = 0 to windowsize - 1
sum / norm
plot(pine_alma(close, 9, 0.85, 6))
RETURNS
Arnaud Legoux Moving Average.
ARGUMENTS
series (series) Series of values to process.
length (integer) Number of bars (length).
offset (float) Controls tradeoff between smoothness (closer to 1) and responsiveness (closer to
0).
sigma (float) Changes the smoothness of ALMA. The larger sigma the smoother ALMA.
SEE ALSO
smaemarmawmavwmaswma
asin
The asin function returns the arcsine (in radians) of number such that sin(asin(y)) = y for y in
range [-1, 1].
asin(x) → float
asin(x) → input float
asin(x) → const float
asin(x) → series[float]
RETURNS
The arcsine of a value; the returned angle is in the range [-Pi/2, Pi/2], or na if y is outside of
range [-1, 1].
atan
The atan function returns the arctangent (in radians) of number such that tan(atan(y)) = y for
any y.
atan(x) → float
atan(x) → input float
atan(x) → const float
atan(x) → series[float]
RETURNS
The arc tangent of a value; the returned angle is in the range [-Pi/2, Pi/2].
atr
Function atr (average true range) returns the RMA of true range. True range is max(high - low,
abs(high - close[1]), abs(low - close[1]))
atr(length) → series[float]
RETURNS
Average true range.
ARGUMENTS
length (integer) Length (number of bars back).
SEE ALSO
trrma
avg
Calculates average of all given series (elementwise).
avg(x1, x2, ..., x10) -> series[float]
RETURNS
Average.
SEE ALSO
sumcumsma
barcolor
Set color of bars.
barcolor(color, offset, editable, show_last, title) → void
EXAMPLE
study('My Script')
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)
plot(pineMiddle)
plot(pineUpper)
plot(pineLower)
RETURNS
Bollinger Bands.
ARGUMENTS
series (series) Series of values to process.
length (integer) Number of bars (length).
mult (float) Standard deviation factor
SEE ALSO
smastdevkc
bbw
Bollinger Bands Width. The Bollinger Band Width is the difference between the upper and the
lower Bollinger Bands divided by the middle band.
bbw(series, length, mult) → series[float]
EXAMPLE
//@version=4
study('My Script')
plot(f_bbw(close, 5, 4))
RETURNS
Bollinger Bands Width.
ARGUMENTS
series (series) Series of values to process.
length (integer) Number of bars (length).
mult (float) Standard deviation factor
SEE ALSO
bbsmastdev
bgcolor
Fill background of bars with specified color.
bgcolor(color, transp, offset, editable, show_last, title) → void
EXAMPLE
study('My Script')
plot(f_cmo(close, 5))
RETURNS
Chande Momentum Oscillator.
ARGUMENTS
series (series) Series of values to process.
length (integer) Number of bars (length).
SEE ALSO
rsistochsum
cog
The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.
cog(source, length) → series[float]
RETURNS
Center of Gravity.
ARGUMENTS
source (series) Series of values to process.
length (integer) Number of bars (length).
SEE ALSO
stoch
color
Casts na to color
color(x) → const color
color(x) → input color
color(x) → color
color(x) → series[color]
RETURNS
The value of the argument after casting to color.
SEE ALSO
floatintboolstringlinelabel
color.new
Function color applies the specified transparency to the given color.
color.new(color, transp) → const color
EXAMPLE
color.new(color.red, 50)
RETURNS
Color with specified transparency.
ARGUMENTS
color (color)
transp (integer) Possible values are from 0 (not transparent) to 100 (invisible).
REMARKS
Color with transparency overrides "transp" argument of plot function.
correlation
Correlation coefficient. Describes the degree to which two series tend to deviate from
their sma values.
correlation(source_a, source_b, length) → series[float]
RETURNS
Correlation coefficient.
ARGUMENTS
source_a (series) Source series.
source_b (series) Target series.
length (integer) Length (number of bars back).
SEE ALSO
security
cos
The cos function returns the trigonometric cosine of an angle.
cos(x) → float
cos(x) → input float
cos(x) → const float
cos(x) → series[float]
RETURNS
The trigonometric cosine of an angle.
ARGUMENTS
x Angle, in radians.
cross
cross(x, y) → series[bool]
RETURNS
1 if two series has crossed each other, otherwise 0.
ARGUMENTS
x (series)
y (series)
SEE ALSO
change
crossover
The `x`-series is defined as having crossed over `y`-series if the value of `x` is greater than
the value of `y` and the value of `x` was less than the value of `y` on the bar immediately
preceding the current bar.
crossover(x, y) → series[bool]
RETURNS
true if `x` crossed over `y` otherwise false
ARGUMENTS
x (float) Data series `x`.
y (float) Data series `y`.
crossunder
The `x`-series is defined as having crossed under `y`-series if the value of `x` is less than the
value of `y` and the value of `x` was greater than the value of `y` on the bar immediately
preceding the current bar.
crossunder(x, y) → series[bool]
RETURNS
true if `x` crossed under `y` otherwise false
ARGUMENTS
x (float) Data series `x`.
y (float) Data series `y`.
cum
Cumulative (total) sum of x. In other words it's a sum of all elements of x.
cum(x) → series[float]
RETURNS
Total sum series.
ARGUMENTS
x (series)
SEE ALSO
sum
dayofmonth
dayofmonth(time) → series[integer]
RETURNS
Day of month (in exchange timezone) for provided UNIX time.
ARGUMENTS
time (series) UNIX time in milliseconds.
REMARKS
UNIX time is the number of milliseconds that have elapsed since 00:00:00 UTC, 1 January 1970.
SEE ALSO
dayofmonthtimeyearmonthdayofweekhourminutesecond
dayofweek
dayofweek(time) → series[integer]
RETURNS
Day of week (in exchange timezone) for provided UNIX time.
ARGUMENTS
time (series) UNIX time in milliseconds.
REMARKS
UNIX time is the number of milliseconds that have elapsed since 00:00:00 UTC, 1 January 1970.
SEE ALSO
dayofweektimeyearmonthdayofmonthhourminutesecond
dev
Measure of difference between the series and it's sma
dev(source, length) → series[float]
RETURNS
Deviation of x for y bars back.
ARGUMENTS
source (series) Series of values to process.
length (integer) Number of bars (length).
SEE ALSO
variancestdev
dmi
The dmi function returns the directional movement index.
dmi(diLength, adxSmoothing) → [series[float], series[float], series[float]]
EXAMPLE
plot(ema(close, 15))
pine_ema(x, y) =>
alpha = 2 / (y + 1)
sum = 0.0
h1 = hline(20)
h2 = hline(10)
fill(h1, h2)
p1 = plot(open)
p2 = plot(close)
fill(p1, p2, color=color.green)
ARGUMENTS
hline1 (hline) The first hline object. Required argument.
hline2 (hline) The second hline object. Required argument.
plot1 (plot) The first plot object. Required argument.
plot2 (plot) The second plot object. Required argument.
color (color) Color of the plot. You can use constants like 'color=color.red' or 'color=#ff001a' as
well as complex expressions like 'color = close >= open ? color.green : color.red'. Optional
argument.
transp (input integer) Transparency of the filled background. Possible values are from 0 (not
transparent) to 100 (invisible). Optional argument.
title (const string) Title of the created fill object. Optional argument.
editable (const bool) If true then fill style will be editable in Format dialog. Default is true.
show_last (input integer) If set, defines the number of bars (from the last bar back to the
past) to fill on chart.
SEE ALSO
plotbarcolorbgcolorhline
financial
Requests financial series for symbol.
financial(symbol, financial_id, period, gaps) → series[float]
EXAMPLE
// You may fill the background between any two hlines with a fill() function:
h1 = hline(20)
h2 = hline(10)
fill(h1, h2)
RETURNS
An hline object, that can be used in fill
ARGUMENTS
price (input float) Price value at which the object will be rendered. Required argument.
title (const string) Title of the object.
color (input color) Color of the rendered line. Must be a constant value (not an expression).
Optional argument.
linestyle (input integer) Style of the rendered line. Possible values
are: hline.style_solid, hline.style_dotted, hline.style_dashed. Optional argument.
linewidth (input integer) Width of the rendered line, use values from 1 to 4. Default value is
1.
editable (const bool) If true then hline style will be editable in Format dialog. Default is true.
SEE ALSO
fill
hma
The hma function returns the Hull Moving Average.
hma(source, length) → series[float]
EXAMPLE
plot(offset(close, i))
plot(close, color=color.red)
kagi_tickerid = kagi(syminfo.tickerid, 3)
//@version=4
study('My Script')
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)
plot(pineMiddle)
plot(pineUpper)
plot(pineLower)
RETURNS
Keltner Channels.
ARGUMENTS
series (series) Series of values to process.
length (integer) Number of bars (length).
mult (float) Standard deviation factor
useTrueRange (bool) An optional parameter. Specifies if True Range is used; default is true. If
the value is false, the range will be calculated with the expression (high - low)
SEE ALSO
emaatrbb
kcw
Keltner Channels Width. The Keltner Channels Width is the difference between the upper and
the lower Keltner Channels divided by the middle channel.
kcw(series, length, mult) → series[float]
kcw(series, length, mult, useTrueRange) → series[float]
EXAMPLE
//@version=4
study('My Script')
plot(f_kcw(close, 5, 4, true))
RETURNS
Keltner Channels Width.
ARGUMENTS
series (series) Series of values to process.
length (integer) Number of bars (length).
mult (float) Standard deviation factor
useTrueRange (bool) An optional parameter. Specifies if True Range is used; default is true. If
the value is false, the range will be calculated with the expression (high - low)
SEE ALSO
kcemaatrbb
label
Casts na to label
label(x) → series[label]
RETURNS
The value of the argument after casting to label.
SEE ALSO
floatintboolcolorstringline
label.delete
Deletes the specified label object. If it has already been deleted, does nothing.
label.delete(id) → void
ARGUMENTS
id (label) Label object to delete
SEE ALSO
label.new
label.get_text
Returns the text of this label object
label.get_text(id) → series[string]
EXAMPLE
a = label.get_text(my_label)
label.new(time, close, text = a + " new", xloc=xloc.bar_time)
RETURNS
String object containing the text of this label
ARGUMENTS
id (label) Label object
SEE ALSO
label.new
label.get_x
Returns UNIX time or bar index (depending on the last xloc value set) of this label's position
label.get_x(id) → series[integer]
EXAMPLE
a = label.get_x(my_label)
plot(time - label.get_x(my_label)) //draws zero plot
RETURNS
UNIX timestamp (in milliseconds) or bar index
ARGUMENTS
id (label) Label object
SEE ALSO
label.new
label.get_y
Returns price of this label's position
label.get_y(id) → series[float]
RETURNS
Floating point value representing price
ARGUMENTS
id (label) Label object
SEE ALSO
label.new
label.new
Creates new label object
label.new(x, y, text, xloc, yloc, color, style, textcolor, size, textalign) →
series[label]
EXAMPLE
label.set_x(label1, 0)
label.set_color(label1, color.red)
label.set_size(label1, size.large)
RETURNS
Label ID object which may be passed to label.setXXX and label.getXXX functions
ARGUMENTS
x (series) Bar index (if xloc = xloc.bar_index) or bar UNIX time (if xloc = xloc.bar_time) of the
label position. Note that if xloc = xloc.bar_index then value of this argument should be less or
equal to the index of current bar.
y (series) Price of the label position. It is taken into account only if yloc=yloc.price
text (string) Label text. Default is empty string
xloc (string) See description of x argument. Possible values: xloc.bar_index and xloc.bar_time.
Default is xloc.bar_index
yloc (string) Possible values are yloc.price, yloc.abovebar, yloc.belowbar. If
yloc=yloc.price, y argument specifies the price of the label position. If yloc=yloc.abovebar,
label is located above bar. If yloc=yloc.belowbar, label is located below bar. Default
is yloc.price
color (color) Color of the label border and arrow
style (string) Label style. Possible
values: label.style_none, label.style_xcross, label.style_cross, label.style_triangleup, label.styl
e_triangledown, label.style_flag, label.style_circle, label.style_arrowup, label.style_arrowdow
n, label.style_label_up, label.style_label_down, label.style_label_left, label.style_label_right,
label.style_label_center, label.style_square, label.style_diamond. Default
is label.style_label_down
textcolor (color) Text color
size (string) Label size. Possible
values: size.auto, size.tiny, size.small, size.normal, size.large, size.huge. Default value
is size.normal.
textalign (string) Label text alignment. Possible
values: text.align_left, text.align_center, text.align_right. Default value is text.align_center.
SEE ALSO
label.deletelabel.set_xlabel.set_ylabel.set_xylabel.set_xloclabel.set_yloclabel.set_colorlabel.s
et_textcolorlabel.set_stylelabel.set_sizelabel.set_textalign
label.set_color
Sets label border and arrow color
label.set_color(id, color) → void
ARGUMENTS
id (label) Label object
color (color) New label border and arrow style
SEE ALSO
label.new
label.set_size
Sets arrow and text size of the specified label object.
label.set_size(id, size) → void
ARGUMENTS
id (label) Label object
size (string) Possible values: size.auto, size.tiny, size.small, size.normal, size.large, size.huge.
Default value is size.auto.
SEE ALSO
size.autosize.tinysize.smallsize.normalsize.largesize.hugelabel.new
label.set_style
Sets label style
label.set_style(id, style) → void
ARGUMENTS
id (label) Label object
style (string) New label style. Possible
values: label.style_none, label.style_xcross, label.style_cross, label.style_triangleup, label.styl
e_triangledown, label.style_flag, label.style_circle, label.style_arrowup, label.style_arrowdow
n, label.style_label_up, label.style_label_down, label.style_label_left, label.style_label_right,
label.style_label_center, label.style_square, label.style_diamond
SEE ALSO
label.new
label.set_text
Sets label text
label.set_text(id, text) → void
ARGUMENTS
id (label) Label object
text (string) New label text
SEE ALSO
label.new
label.set_textalign
Sets the alignment for the label text.
label.set_textalign(id, textalign) → void
ARGUMENTS
id (label) Label object
textalign (string) Label text alignment. Possible
values: text.align_left, text.align_center, text.align_right.
SEE ALSO
text.align_lefttext.align_centertext.align_rightlabel.new
label.set_textcolor
Sets color of the label text
label.set_textcolor(id, textcolor) → void
ARGUMENTS
id (label) Label object
textcolor (color) New text color
SEE ALSO
label.new
label.set_x
Sets bar index or bar time (depending on the xloc) of the label position
label.set_x(id, x) → void
ARGUMENTS
id (label) Label object
x (series) New bar index or bar time of the label position. Note that if xloc
= xloc.bar_index then value of this argument should be less or equal to the index of current
bar.
SEE ALSO
label.new
label.set_xloc
Sets x-location and new bar index/time value
label.set_xloc(id, x, xloc) → void
ARGUMENTS
id (label) Label object
x (series) New bar index or bar time of the label position
xloc (string) New x-location value
SEE ALSO
xloc.bar_indexxloc.bar_timelabel.new
label.set_xy
Sets bar index/time and price of the label position
label.set_xy(id, x, y) → void
ARGUMENTS
id (label) Label object
x (series) New bar index or bar time of the label position. Note that if xloc
= xloc.bar_index then value of this argument should be less or equal to the index of current
bar.
y (series) New price of the label position
SEE ALSO
label.new
label.set_y
Sets price of the label position
label.set_y(id, y) → void
ARGUMENTS
id (label) Label object
y (series) New price of the label position
SEE ALSO
label.new
label.set_yloc
Sets new y-location calculation algorithm
label.set_yloc(id, yloc) → void
ARGUMENTS
id (label) Label object
yloc (string) New y-location value
SEE ALSO
yloc.priceyloc.abovebaryloc.belowbarlabel.new
line
Casts na to line
line(x) → series[line]
RETURNS
The value of the argument after casting to line.
SEE ALSO
floatintboolcolorstringlabel
line.delete
Deletes the specified line object. If it has already been deleted, does nothing.
line.delete(id) → void
ARGUMENTS
id (line) Line object to delete
SEE ALSO
line.new
line.get_x1
Returns UNIX time or bar index (depending on the last xloc value set) of the first point of the
line
line.get_x1(id) → series[integer]
EXAMPLE
a = line.get_x1(my_line)
plot(time - line.get_x1(my_line)) //draws zero plot
RETURNS
UNIX timestamp (in milliseconds) or bar index
ARGUMENTS
id (line) Line object
SEE ALSO
line.new
line.get_x2
Returns UNIX time or bar index (depending on the last xloc value set) of the second point of the
line
line.get_x2(id) → series[integer]
RETURNS
UNIX timestamp (in milliseconds) or bar index
ARGUMENTS
id (line) Line object
SEE ALSO
line.new
line.get_y1
Returns price of the first point of the line
line.get_y1(id) → series[float]
RETURNS
Price value
ARGUMENTS
id (line) Line object
SEE ALSO
line.new
line.get_y2
Returns price of the second point of the line
line.get_y2(id) → series[float]
RETURNS
Price value
ARGUMENTS
id (line) Line object
SEE ALSO
line.new
line.new
Creates new line object
line.new(x1, y1, x2, y2, xloc, extend, color, style, width) → series[line]
EXAMPLE
line.set_x2(line1, 0)
line.set_color(line2, color.green)
line.set_width(line2, 5)
RETURNS
Line ID object which may be passed to line.setXXX and line.getXXX functions
ARGUMENTS
x1 (series) Bar index (if xloc = xloc.bar_index) or bar UNIX time (if xloc = xloc.bar_time) of the
first point of the line. Note that if xloc = xloc.bar_index then value of this argument should be
less or equal to the index of current bar.
y1 (series) Price of the first point of the line
x2 (series) Bar index (if xloc = xloc.bar_index) or bar UNIX time (if xloc = xloc.bar_time) of the
second point of the line. Note that if xloc = xloc.bar_index then value of this argument should
be less or equal to the index of current bar.
y2 (series) Price of the second point of the line
xloc (string) See description of x1 argument. Possible
values: xloc.bar_index and xloc.bar_time. Default is xloc.bar_index
extend (string) If extend=extend.none, draws segment starting at point (x1, y1) and ending at
point (x2, y2). If extend is equal to extend.right or extend.left, draws a ray starting at point
(x1, y1) or (x2, y2), respectively. If extend=extend.both, draws a straight line that goes
through these points. Default value is extend.none.
color (color) Line color
style (string) Line style. Possible
values: line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_left, line.style_a
rrow_right, line.style_arrow_both
width (integer) Line width in pixels
SEE ALSO
line.deleteline.set_x1line.set_y1line.set_xy1line.set_x2line.set_y2line.set_xy2line.set_xlocline
.set_colorline.set_extendline.set_styleline.set_width
line.set_color
Sets the line color
line.set_color(id, color) → void
ARGUMENTS
id (line) Line object
color (color) New line color
SEE ALSO
line.new
line.set_extend
Sets extending type of this line object. If extend=extend.none, draws segment starting at point
(x1, y1) and ending at point (x2, y2). If extend is equal to extend.right or extend.left, draws a
ray starting at point (x1, y1) or (x2, y2), respectively. If extend=extend.both, draws a straight
line that goes through these points.
line.set_extend(id, extend) → void
ARGUMENTS
id (line) Line object
extend (string) New extending type
SEE ALSO
extend.noneextend.rightextend.leftextend.bothline.new
line.set_style
Sets the line style
line.set_style(id, style) → void
ARGUMENTS
id (line) Line object
style (string) New line style
SEE ALSO
line.style_solidline.style_dottedline.style_dashedline.style_arrow_leftline.style_arrow_rightlin
e.style_arrow_bothline.new
line.set_width
Sets the line width
line.set_width(id, width) → void
ARGUMENTS
id (line) Line object
width (integer) New line width in pixels
SEE ALSO
line.new
line.set_x1
Sets bar index or bar time (depending on the xloc) of the first point
line.set_x1(id, x) → void
ARGUMENTS
id (line) Line object
x (series) Bar index or bar time. Note that if xloc = xloc.bar_index then value of this argument
should be less or equal to the index of current bar.
SEE ALSO
line.new
line.set_x2
Sets bar index or bar time (depending on the xloc) of the second point
line.set_x2(id, x) → void
ARGUMENTS
id (line) Line object
x (series) Bar index or bar time. Note that if xloc = xloc.bar_index then value of this argument
should be less or equal to the index of current bar.
SEE ALSO
line.new
line.set_xloc
Sets x-location and new bar index/time values
line.set_xloc(id, x1, x2, xloc) → void
ARGUMENTS
id (line) Line object
x1 (series) Bar index or bar time of the first point
x2 (series) Bar index or bar time of the second point
xloc (string) New x-location value
SEE ALSO
xloc.bar_indexxloc.bar_timeline.new
line.set_xy1
Sets bar index/time and price of the first point
line.set_xy1(id, x, y) → void
ARGUMENTS
id (line) Line object
x (series) Bar index or bar time. Note that if xloc = xloc.bar_index then value of this argument
should be less or equal to the index of current bar.
y (series) Price
SEE ALSO
line.new
line.set_xy2
Sets bar index/time and price of the second point
line.set_xy2(id, x, y) → void
ARGUMENTS
id (line) Line object
x (series) Bar index or bar time
y (series) Price
SEE ALSO
line.new
line.set_y1
Sets price of the first point
line.set_y1(id, y) → void
ARGUMENTS
id (line) Line object
y (series) Price
SEE ALSO
line.new
line.set_y2
Sets price of the second point
line.set_y2(id, y) → void
ARGUMENTS
id (line) Line object
y (series) Price
SEE ALSO
line.new
linebreak
Creates a ticker identifier for requesting Line Break values.
linebreak(symbol, number_of_lines) → string
EXAMPLE
linebreak_tickerid = linebreak(syminfo.tickerid, 3)
// Example 1
study('MACD')
plot(macdLine, color=color.blue)
plot(signalLine, color=color.orange)
// Example 2
// If you need only one value, use placeholders '_' like this:
study('MACD')
max(close, open)
max(close, max(open, 42))
RETURNS
The greatest of multiple given values.
SEE ALSO
min
max_bars_back
Function sets the maximum number of bars that is available for historical reference of a given
built-in or user variable. When operator '[]' is applied to a variable - it is a reference to a
historical value of that variable.
If an argument of an operator '[]' is a compile time constant value (e.g. 'v[10]', 'close[500]')
then there is no need to use 'max_bars_back' function for that variable. Pine Script compiler
will use that constant value as history buffer size.
If an argument of an operator '[]' is a value, calculated at runtime (e.g. 'v[i]' where 'i' - is a
series variable) then Pine Script attempts to autodetect the history buffer size at runtime.
Sometimes it fails and the script crashes at runtime because it eventually refers to historical
values that are out of the buffer. In that case you should use 'max_bars_back' to fix that
problem manually.
max_bars_back(var, num) → void
EXAMPLE
//@version=4
study('My Script')
d = depth()
v = close_()
max_bars_back(v, 500)
v[d]
else
v
plot(out)
RETURNS
void
ARGUMENTS
var (series, color, bool) Series variable identifier for which history buffer should be resized.
Possible values are: 'open', 'high', 'low', 'close', 'volume', 'time', or any user defined variable id.
num (integer) History buffer size which is the number of bars that could be referenced for
variable 'var'. This should be a literal integer.
REMARKS
At the moment 'max_bars_back' cannot be applied to built-ins like 'hl2', 'hlc3', 'ohlc4'. Please
use multiple 'max_bars_back' calls as workaround here (e.g. instead of a single
‘max_bars_bars(hl2, 100)’ call you should call the function twice: ‘max_bars_bars(high, 100),
max_bars_bars(low, 100)’).
If the study or strategy 'max_bars_back' parameter is used, all variables in the study are
affected. This may result in excessive memory usage and cause runtime problems. When
possible (i.e. when the cause is a variable rather than a function), please use
the max_bars_back function instead.
SEE ALSO
studystrategy
mfi
Money Flow Index. The Money Flow Index (MFI) is a technical oscillator that uses price and
volume for identifying overbought or oversold conditions in an asset.
mfi(series, length) → series[float]
EXAMPLE
//@version=4
study('My Script')
if na(lower)
float res = na
return = res
else
plot(f_mfi(close, 5))
RETURNS
Money Flow Index.
ARGUMENTS
series (series) Series of values to process.
length (integer) Number of bars (length).
SEE ALSO
rsisum
min
Returns the smallest of multiple values
min(x1, x2, ..., x10) -> const integer
min(x1, x2, ..., x10) -> input integer
min(x1, x2, ..., x10) -> integer
min(x1, x2, ..., x10) -> series[integer]
min(x1, x2, ..., x10) -> const float
min(x1, x2, ..., x10) -> input float
min(x1, x2, ..., x10) -> float
min(x1, x2, ..., x10) -> series[float]
EXAMPLE
min(close, open)
min(close, min(open, 42))
RETURNS
The smallest of multiple given values.
SEE ALSO
max
minute
minute(time) → series[integer]
RETURNS
Minute (in exchange timezone) for provided UNIX time.
ARGUMENTS
time (series) UNIX time in milliseconds.
REMARKS
UNIX time is the number of milliseconds that have elapsed since 00:00:00 UTC, 1 January 1970.
SEE ALSO
minutetimeyearmonthdayofmonthdayofweekhoursecond
mom
Momentum of x price and x price y bars ago. This is simply a difference x - x[y].
mom(source, length) → series[float]
RETURNS
Momentum of x price and x price y bars ago.
ARGUMENTS
source (series) Series of values to process.
length (integer) Offset from the current bar to the previous bar.
SEE ALSO
change
month
month(time) → series[integer]
RETURNS
Month (in exchange timezone) for provided UNIX time.
ARGUMENTS
time (series) UNIX time in milliseconds.
REMARKS
UNIX time is the number of milliseconds that have elapsed since 00:00:00 UTC, 1 January 1970.
SEE ALSO
monthtimeyeardayofmonthdayofweekhourminutesecond
na
Test value if it's a NaN.
na(x) → bool
na(x) → series[bool]
RETURNS
true if x is not a valid number (x is NaN), otherwise false.
SEE ALSO
nafixnannz
nz
Replaces NaN values with zeros (or given value) in a series.
nz(x, y) → integer
nz(x, y) → float
nz(x, y) → color
nz(x, y) → bool
nz(x, y) → series[integer]
nz(x, y) → series[float]
nz(x, y) → series[color]
nz(x, y) → series[bool]
nz(x) → integer
nz(x) → float
nz(x) → color
nz(x) → bool
nz(x) → series[integer]
nz(x) → series[float]
nz(x) → series[color]
nz(x) → series[bool]
EXAMPLE
nz(sma(close, 100))
RETURNS
Two args version: returns x if it's a valid (not NaN) number, otherwise y
One arg version: returns x if it's a valid (not NaN) number, otherwise 0
ARGUMENTS
x (series) Series of values to process.
y (float) Value that will be inserted instead of all NaN values in x series.
SEE ALSO
nanafixnan
offset
Shifts series x on the y bars to the right.
offset(source, offset) → series[bool]
offset(source, offset) → series[color]
offset(source, offset) → series[integer]
offset(source, offset) → series[float]
RETURNS
Shifted series.
ARGUMENTS
source (series) Series of values to process.
offset (integer) Number of bars to offset, must be a positive number. Negative offsets are not
supported.
REMARKS
If you need to shift the series to the left, use combination of offset and plot (with offset
argument).
SEE ALSO
plot
percentile_linear_interpolation
Calculates percentile using method of linear interpolation between the two nearest ranks.
percentile_linear_interpolation(source, length, percentage) → series[float]
RETURNS
z-th percentile of x series for y bars back.
ARGUMENTS
source (series) Series of values to process (source).
length (integer) Number of bars back (length).
percentage (float) Percentage, a number from range 0..100.
REMARKS
Note that a percentile calculated using this method will NOT always be a member of the input
data set.
SEE ALSO
percentile_nearest_rank
percentile_nearest_rank
Calculates percentile using method of Nearest Rank.
percentile_nearest_rank(source, length, percentage) → series[float]
RETURNS
z-th percentile of x series for y bars back.
ARGUMENTS
source (series) Series of values to process (source).
length (integer) Number of bars back (length).
percentage (float) Percentage, a number from range 0..100.
REMARKS
Using the Nearest Rank method on lengths less than 100 bars back can result in the same
number being used for more than one percentile.
A percentile calculated using the Nearest Rank method will always be a member of the input
data set.
The 100th percentile is defined to be the largest value in the input data set.
SEE ALSO
percentile_linear_interpolation
percentrank
Percent rank is the percents of how many previous values was less than or equal to the current
value of given series.
percentrank(source, length) → series[float]
RETURNS
Percent rank of x for y bars back.
ARGUMENTS
source (series) Series of values to process.
length (integer) Number of bars (length).
pivothigh
This function returns price of the pivot high point. It returns 'NaN', if there was no pivot high
point.
pivothigh(source, leftbars, rightbars) → series[float]
pivothigh(leftbars, rightbars) → series[float]
EXAMPLE
study("PivotHigh", overlay=true)
leftBars = input(2)
rightBars=input(2)
ph = pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_cross, linewidth=3, color= color.red, offset=-rightBars)
RETURNS
Price of the point or 'NaN'.
ARGUMENTS
source (series) An optional parameter. Data series to calculate the value. 'High' by defualt.
leftbars (series) Left strength.
rightbars (series) Right strength.
REMARKS
If parameters 'leftbars' or 'rightbars' are series you should use max_bars_back function for the
'source' variable.
pivotlow
This function returns price of the pivot low point. It returns 'NaN', if there was no pivot low
point.
pivotlow(source, leftbars, rightbars) → series[float]
pivotlow(leftbars, rightbars) → series[float]
EXAMPLE
study("PivotLow", overlay=true)
leftBars = input(2)
rightBars=input(2)
// You may fill the background between any two plots with a fill() function:
p1 = plot(open)
p2 = plot(close)
fill(p1, p2, color=color.green)
RETURNS
A plot object, that can be used in fill
ARGUMENTS
series (series) Series of data to be plotted. Required argument.
title (const string) Title of the plot.
color (color) Color of the plot. You can use constants like 'color=color.red' or 'color=#ff001a' as
well as complex expressions like 'color = close >= open ? color.green : color.red'. Optional
argument.
linewidth (input integer) Width of the plotted line, use values from 1 to 4. Default value is 1.
Not applicable to every style.
style (input integer) Type of the plot. Possible values
are: plot.style_line, plot.style_stepline, plot.style_histogram, plot.style_cross, plot.style_area,
plot.style_columns, plot.style_circles. Default value is plot.style_line.
transp (input integer) Transparency of the plot, applicable only to the plot.style_area style.
Possible values are from 0 (not transparent) to 100 (invisible). Optional argument.
trackprice (input bool) If true then a horizontal price line will be shown at the level of the last
study value. Default is false.
histbase (input float) Price value which will be considered as a start base point when rendering
plot with plot.style_histogram or plot.style_columns style. Default is 0.0.
offset (integer) Shifts the plot to the left or to the right on the given number of bars. Default
is 0.
join (input bool) If true then plot points will be joined with line, applicable only
to plot.style_cross and plot.style_circles styles. Default is false.
editable (const bool) If true then plot style will be editable in Format dialog. Default is true.
show_last (input integer) If set, defines the number of bars (from the last bar back to the
past) to plot on chart.
display (const integer) Controls where the plot is displayed. Possible values
are: display.none, display.all. Default is display.all
SEE ALSO
plotshapeplotcharplotarrowbarcolorbgcolorfill
plotarrow
Plots up and down arrows on the chart. Up arrow is drawn at every indicator positive value,
down arrow is drawn at every negative value. If indicator returns na then no arrow is drawn.
Arrows has different height, the more absolute indicator value the longer arrow is drawn.
plotarrow(series, title, colorup, colordown, transp, offset, minheight,
maxheight, editable, show_last, display) → void
EXAMPLE
plotbar(open, high, low, close, title='Title', color = open < close ? color.green :
color.red)
ARGUMENTS
open (series) Open series of data to be used as open values of bars. Required argument.
high (series) High series of data to be used as high values of bars. Required argument.
low (series) Low series of data to be used as low values of bars. Required argument.
close (series) Close series of data to be used as close values of bars. Required argument.
title (const string) Title of the plotbar. Optional argument.
color (color) Color of the ohlc bars. You can use constants like 'color=color.red' or
'color=#ff001a' as well as complex expressions like 'color = close >= open ? color.green :
color.red'. Optional argument.
editable (const bool) If true then plotbar style will be editable in Format dialog. Default is
true.
show_last (input integer) If set, defines the number of bars (from the last bar back to the
past) to plot on chart.
display (const integer) Controls where the plot is displayed. Possible values
are: display.none, display.all. Default is display.all
REMARKS
Even if one value of open, high, low or close equal NaN then bar no draw.
The maximal value of open, high, low or close will be set as 'high', and the minimal value will
be set as 'low'.
SEE ALSO
plotcandle
plotcandle
Plots candles on the chart.
plotcandle(open, high, low, close, title, color, wickcolor, editable,
show_last, bordercolor, display) → void
EXAMPLE
plotcandle(open, high, low, close, title='Title', color = open < close ? color.green
: color.red, wickcolor=color.black)
ARGUMENTS
open (series) Open series of data to be used as open values of candles. Required argument.
high (series) High series of data to be used as high values of candles. Required argument.
low (series) Low series of data to be used as low values of candles. Required argument.
close (series) Close series of data to be used as close values of candles. Required argument.
title (const string) Title of the plotcandles. Optional argument.
color (color) Color of the candles. You can use constants like 'color=color.red' or 'color=#ff001a'
as well as complex expressions like 'color = close >= open ? color.green : color.red'. Optional
argument.
wickcolor (input color) The color of the wick of candles. Must be an input or constant value.
An optional argument.
editable (const bool) If true then plotcandle style will be editable in Format dialog. Default is
true.
show_last (input integer) If set, defines the number of candles (from the last bar back to the
past) to plot on chart.
bordercolor (input color) The border color of candles. Must be an input or constant value. An
optional argument.
display (const integer) Controls where the plot is displayed. Possible values
are: display.none, display.all. Default is display.all
REMARKS
Even if one value of open, high, low or close equal NaN then bar no draw.
The maximal value of open, high, low or close will be set as 'high', and the minimal value will
be set as 'low'.
SEE ALSO
plotbar
plotchar
Plots visual shapes using any given one Unicode character on the chart.
plotchar(series, title, char, location, color, transp, offset, text,
textcolor, editable, size, show_last, display) → void
EXAMPLE
pow(close, 2)
RETURNS
x raised to the power of y. If x is a series, it is calculated elementwise.
ARGUMENTS
base Specify the base to use.
exponent (float) Specifies the exponent.
SEE ALSO
sqrtexp
renko
Creates a ticker identifier for requesting Renko values.
renko(symbol, style, param) → string
EXAMPLE
plot(rma(close, 15))
pine_rma(x, y) =>
alpha = y
sum = 0.0
plot(rsi(close, 7))
pine_rsi(x, y) =>
rs = rma(u, y) / rma(d, y)
res
plot(pine_rsi(close, 7))
RETURNS
Relative strength index.
ARGUMENTS
x (series)
y (integer, series)
REMARKS
If x is a series and y is integer then x is a source series and y is a length.
If x is a series and y is a series then x and y are considered to be 2 calculated MAs for upward
and downward changes.
SEE ALSO
rma
sar
Parabolic SAR (parabolic stop and reverse) is a method devised by J. Welles Wilder, Jr., to find
potential reversals in the market price direction of traded goods.
sar(start, inc, max) → series[float]
EXAMPLE
plot(sar(0.2, 0.2, .2), style=plot.style_cross, linewidth=3)
RETURNS
Parabolic SAR.
ARGUMENTS
start (float) Start.
inc (float) Increment.
max (float) Maximum.
second
second(time) → series[integer]
RETURNS
Second (in exchange timezone) for provided UNIX time.
ARGUMENTS
time (series) UNIX time in milliseconds.
REMARKS
UNIX time is the number of milliseconds that have elapsed since 00:00:00 UTC, 1 January 1970.
SEE ALSO
secondtimeyearmonthdayofmonthdayofweekhourminute
security
Request another symbol/resolution
security(symbol, resolution, expression, gaps, lookahead) → series[float]
security(symbol, resolution, expression, gaps, lookahead) → series[integer]
security(symbol, resolution, expression, gaps, lookahead) → series[bool]
security(symbol, resolution, expression, gaps, lookahead) → series[color]
EXAMPLE
plot(s)
plot(s1)
// To avoid difference in calculation on history/realtime you can request not latest values and
use merge strategy flags as follows:
plot(sma(close, 15))
pine_sma(x, y) =>
sum = 0.0
for i = 0 to y - 1
sum
plot(pine_sma(close, 15))
RETURNS
Simple moving average of x for y bars back.
ARGUMENTS
source (series) Series of values to process.
length (integer) Number of bars (length).
SEE ALSO
emarmawmavwmaswmaalma
sqrt
Square root of any x >= 0 is the unique y >= 0 such that y^2 = x
sqrt(x) → float
sqrt(x) → input float
sqrt(x) → const float
sqrt(x) → series[float]
RETURNS
The square root of x.
SEE ALSO
pow
stdev
stdev(source, length) → series[float]
RETURNS
Standard deviation.
ARGUMENTS
source (series) Series of values to process.
length (integer) Number of bars (length).
REMARKS
This is a biased estimation of standard deviation.
SEE ALSO
devvariance
stoch
Stochastic. It is calculated by a formula: 100 * (close - lowest(low, length)) / (highest(high,
length) - lowest(low, length))
stoch(source, high, low, length) → series[float]
RETURNS
Stochastic.
ARGUMENTS
source (series) Source series.
high (series) Series of high.
low (series) Series of low.
length (integer) Length (number of bars back).
SEE ALSO
cog
str.replace_all
Replaces each occurrence of the target string in the source string with the replacement string.
str.replace_all(source, target, replacement) → string
str.replace_all(source, target, replacement) → series[string]
RETURNS
Processed string.
ARGUMENTS
source (string) Source string
target (string) String to be replaced
replacement (string) String to be substituted for each occurrence of target string
strategy
The function sets a number of strategy properties.
strategy(title, shorttitle, overlay, format, precision, scale, pyramiding,
calc_on_order_fills, calc_on_every_tick, max_bars_back,
backtest_fill_limits_assumption, default_qty_type, default_qty_value,
initial_capital, currency, slippage, commission_type, commission_value,
process_orders_on_close, close_entries_rule) → void
EXAMPLE
strategy(title='MyStrategy')
strategy(title="MyStrategy", shorttitle="MS", pyramiding = 10)
ARGUMENTS
title (const string) study title that would be seen in Indicators/Strategies widget. Argument IS
REQUIRED.
shorttitle (const string) study short title that would be seen in the chart legend. Argument is
optional.
overlay (const bool) if true the study will be added as an overlay for the main series. If false -
it would be added on a separate chart pane. Default is false.
format (const string) type of formatting study values on the price axis. Possible values
are: format.inherit, format.price, format.volume. Default is format.inherit.
precision (const integer) number of digits after the floating point for study values on the price
axis. Must be a non negative integer and not greater than 16. If omitted, using formatting from
parent series. If format is format.inherit and this argument is set, then format
becomes format.price.
scale (const integer) price scale that the indicator should be attached to. Possible values
are: scale.right, scale.left, scale.none. Value scale.none can be applied only in combination
with 'overlay=true' setting. If omitted, using scale from main series.
pyramiding (const integer) Maximum number of entries allowed in the same direction. If the
value is 0, only one entry order in the same direction can be opened, any additional entry
order is rejected. The defualt value is 0.
calc_on_order_fills (const bool) Additional one time intrabar order calculation. If the
parameter is set to 'true', then the strategy is recalculated once intrabar after an order is filled
(not only at close of the bar). The default value is 'false'.
calc_on_every_tick (const bool) Additional intrabar strategy calculations. If the parameter is
'true', then the strategy will calculate on every tick in real-time, rather than on bars' closes.
The parameter does not affect strategy calculation on historical data. The default value is
'false'.
max_bars_back (const integer) Maximum number of bars available for a strategy for historical
reference. This parameter is applied to every built-in or user variable in the script if there is a
reference to historical data of a variable in the script code (‘[]’ operator is used). Variable
buffer sizes in the Pine Script are typically autodetected. This however is not possible in
certain cases which is why the parameter allows a user to manually set the lower bound of this
value. NOTE: using of the max_bars_back function instead of the parameter is optimal because
it applies to only one variable.
backtest_fill_limits_assumption (const integer) Limit order execution assumption. Limit
orders are filled intrabar only if market price exceeds the limit order level by the specified
number of in ticks.
default_qty_type (const string) Parameter to determine the number of
contracts/shares/lots/units to trade, if the 'qty' = 'NaN'. The allowed values
are: strategy.fixed (fixed quantity by default), strategy.cash (specified in currency of the
symbol and the amount is converted into quantity), strategy.percent_of_equity (% of currently
available equity).
default_qty_value (const float) Number of contracts/shares/lots/units if
'default_qty_type'=strategy.fixed is used; or amount of cash in currency of the symbol if
'default_qty_type'=strategy.cash is used; or number of percents of currently available equity if
'default_qty_type'=strategy.percent_of_equity is used.
currency (const string) Account currency for this strategy. Possible values
are: NONE, USD, EUR, AUD, GBP, NZD, CAD, CHF, HKD, JPY, NOK, SEK, SGD, TRY, ZAR
linktoseries (const bool) if true then the study will be always on the same pane and same
price scale as the main series. Should be used only in combination with 'overlay=true'. Default
is false.
slippage (const integer) Slippage for market and stop orders in points impairs the filling price
of market and stop-market orders for a specified number of points.
commission_type (const string) Commission type for an order. The allowed values
are: strategy.commission.percent (a percentage of the cash volume of
order), strategy.commission.cash_per_contract (money displayed in the account currency per
contract), strategy.commission.cash_per_order (money displayed in the account currency per
order).
commission_value (const float) Commission value for an order. Depending on the type
selected (commission_type) includes percentage or money.
process_orders_on_close (const bool) When set to `true`, generates an additional attempt to
execute orders after a bar closes and strategy calculations are completed. If the orders are
market orders, the broker emulator executes them before the next bar's open. If the orders are
conditional on price, they will only be filled if the price conditions are met. This option is
useful if you wish to close positions on the current bar. The default value is 'false'.
close_entries_rule (const string) Determines the order in which orders are closed. Allowed
values are: 'FIFO' or 'ANY'. FIFO (First-In, First-Out) means that when several trades are open,
the earliest trades must be closed first. This rule applies to stocks, futures and US forex (NFA
Compliance Rule 2-43b). 'ANY' means that trades may be closed in any order; this is allowed in
non-US forex. The default value is 'FIFO'.
REMARKS
Every strategy script must have one strategy call.
PineScript code that uses argument calc_on_every_tick=true could calculate differently on
history and real-time data.
When using non-standard types of chart as a basis for strategy, you need to realize that the
result will be different. The orders will be executed at the prices of this chart (e.g.for Heikin
Ashi it’ll take Heikin Ashi prices (the average ones) not the real market prices). Therefore we
highly recommend you to use standard chart type for strategies.
strategy.cancel
It is a command to cancel/deactivate pending orders by referencing their names, which were
generated by the functions: strategy.order, strategy.entry and strategy.exit.
strategy.cancel(id, when) → void
EXAMPLE
strategy.close("buy", when = open < close, qty_percent = 50, comment = "close buy
entry for 50%")
plot(strategy.position_size)
ARGUMENTS
id (string) A required parameter. The order identifier. It is possible to close an order by
referencing its identifier.
when (bool) An optional parameter. Condition of the command.
qty (float) An optional parameter. It is the number of contracts/shares/lots/units needed to
exit a trade. The default value is 'NaN'.
qty_percent (float) An optional parameter. Defines the percentage of entered
contracts/shares/lots/units needed to exit a trade. When its value is not NaN, its priority is
higher than that of the 'qty' parameter. Its value can range from 0 to 100. If 'qty' is NaN, the
default value of 'qty_percent' is 100.
comment (string) An optional parameter. Additional notes and commentary on the order.
strategy.close_all
It is a command to exit from current market position making it flat. If there is no open market
position by the moment the command is triggered, the command will not come into effect.
strategy.close_all(when, comment) → void
EXAMPLE
strategy.entry("enter long", true, 1, when = open > high[1]) // enter long by market if
current open great then previous high
strategy.entry("enter short", false, 1, when = open < low[1]) // enter short by market if
current open less then previous low
ARGUMENTS
id (string) A required parameter. The order identifier. It is possible to cancel or modify an
order by referencing its identifier.
long (bool) A required parameter. Market position direction: 'true' or 'strategy.long' is for long,
'false' or 'strategy.short' is for short.
qty (float) An optional parameter. Number of contracts/shares/lots/units to trade. The default
value is 'NaN'.
limit (float) An optional parameter. Limit price of the order. If it is specified, the order type is
either 'limit', or 'stop-limit'. 'NaN' should be specified for any other order type.
stop (float) An optional parameter. Stop price of the order. If it is specified, the order type is
either 'stop', or 'stop-limit'. 'NaN' should be specified for any other order type.
oca_name (string) An optional parameter. Name of the OCA group the order belongs to. If the
order should not belong to any particular OCA group, there should be an empty string.
oca_type (string) An optional parameter. Type of the OCA group. The allowed values
are: strategy.oca.none - the order should not belong to any particular OCA
group; strategy.oca.cancel - the order should belong to an OCA group, where as soon as an
order is filled, all other orders of the same group are cancelled; strategy.oca.reduce - the
order should belong to an OCA group, where if X number of contracts of an order is filled,
number of contracts for each other order of the same OCA group is decreased by X.
comment (string) An optional parameter. Additional notes and commentary on the order.
when (bool) An optional parameter. Condition of the order. The order is placed if condition is
'true'. If condition is 'false', nothing happens (the previously placed order with the same ID is
not cancelled). Default value is 'true'.
strategy.exit
It is a command to exit either a specific entry, or whole market position. If an order with the
same ID is already pending, it is possible to modify the order. If an entry order was not filled,
but an exit order is generated, the exit order will wait till entry order is filled and then the
exit order is placed. To deactivate an exit order, the
command strategy.cancel or strategy.cancel_all should be used. If the function strategy.exit is
called once, it exits a position only once. If you want to exit multiple times, the
command strategy.exit should be called multiple times. If you use a stop loss and a trailing
stop, their order type is 'stop', so only one of them is placed (the one that is supposed to be
filled first). If all the following parameters 'profit', 'limit', 'loss', 'stop', 'trail_points', 'trail_offset'
are 'NaN', the command will fail. To use market order to exit, the
command strategy.close or strategy.close_all should be used.
strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop,
trail_price, trail_points, trail_offset, oca_name, comment, when) → void
EXAMPLE
strategy.entry("long", true, 1, when = open > high[1]) // enter long by market if current
open great then previous high
strategy.exit("exit", "long", profit = 10, loss = 5) // generate full exit bracket (profit
10 points, loss 5 points per contract) from entry with name "long"
ARGUMENTS
id (string) A required parameter. The order identifier. It is possible to cancel or modify an
order by referencing its identifier.
from_entry (string) An optional parameter. The identifier of a specific entry order to exit from
it. To exit all entries an empty string should be used. The default values is empty string.
qty (float) An optional parameter. It is the number of contracts/shares/lots/units needed to
exit a trade. The default value is 'NaN'.
qty_percent (float) An optional parameter. Defines the percentage of entered
contracts/shares/lots/units needed to exit a trade. When its value is not NaN, its priority is
higher than that of the 'qty' parameter. Its value can range from 0 to 100. If 'qty' is NaN, the
default value of 'qty_percent' is 100.
profit (float) An optional parameter. Profit target (specified in ticks). If it is specified, a limit
order is placed to exit market position when the specified amount of profit (in ticks) is
reached. The default value is 'NaN'.
limit (float) An optional parameter. Profit target (requires a specific price). If it is specified, a
limit order is placed to exit market position at the specified price (or better). Priority of the
parameter 'limit' is higher than priority of the parameter 'profit' ('limit' is used instead of
'profit', if its value is not 'NaN'). The default value is 'NaN'.
loss (float) An optional parameter. Stop loss (specified in ticks). If it is specified, a stop order
is placed to exit market position when the specified amount of loss (in ticks) is reached. The
default value is 'NaN'.
stop (float) An optional parameter. Stop loss (requires a specific price). If it is specified, a stop
order is placed to exit market position at the specified price (or worse). Priority of the
parameter 'stop' is higher than priority of the parameter 'loss' ('stop' is used instead of 'loss', if
its value is not 'NaN'). The default value is 'NaN'.
trail_price (float) An optional parameter. Trailing stop activation level (requires a specific
price). If it is specified, a trailing stop order will be placed when the specified price level is
reached. The offset (in ticks) to determine initial price of the trailing stop order is specified in
the 'trail_offset' parameter: X ticks lower than activation level to exit long position; X ticks
higher than activation level to exit short position. The default value is 'NaN'.
trail_points (float) An optional parameter. Trailing stop activation level (profit specified in
ticks). If it is specified, a trailing stop order will be placed when the calculated price level
(specified amount of profit) is reached. The offset (in ticks) to determine initial price of the
trailing stop order is specified in the 'trail_offset' parameter: X ticks lower than activation level
to exit long position; X ticks higher than activation level to exit short position. The default
value is 'NaN'.
trail_offset (float) An optional parameter. Trailing stop price (specified in ticks). The offset in
ticks to determine initial price of the trailing stop order: X ticks lower than 'trail_price' or
'trail_points' to exit long position; X ticks higher than 'trail_price' or 'trail_points' to exit short
position. The default value is 'NaN'.
oca_name (string) An optional parameter. Name of the OCA group (oca_type
= strategy.oca.reduce) the profit target, the stop loss / the trailing stop orders belong to. If
the name is not specified, it will be generated automatically.
comment (string) An optional parameter. Additional notes and commentary on the order.
when (bool) An optional parameter. Condition of the order. The order is placed if condition is
'true'. If condition is 'false', nothing happens (the previously placed order with the same ID is
not cancelled). Default value is 'true'.
strategy.order
It is a command to place order. If an order with the same ID is already pending, it is possible to
modify the order. If there is no order with the specified ID, a new order is placed. To
deactivate order, the command strategy.cancel or strategy.cancel_all should be used. In
comparison to the function strategy.entry, the function strategy.order is not affected by
pyramiding. If both 'limit' and 'stop' parameters are 'NaN', the order type is market order.
strategy.order(id, long, qty, limit, stop, oca_name, oca_type, comment, when)
→ void
EXAMPLE
strategy.order("buy", true, 1, when = open > high[1]) // buy by market if current open
great then previous high
strategy.order("sell", false, 1, when = open < low[1]) // sell by market if current open
less then previous low
ARGUMENTS
id (string) A required parameter. The order identifier. It is possible to cancel or modify an
order by referencing its identifier.
long (bool) A required parameter. Order direction: 'true' or 'strategy.long' is for buy, 'false' or
'strategy.short' is for sell.
qty (float) An optional parameter. Number of contracts/shares/lots/units to trade. The default
value is 'NaN'.
limit (float) An optional parameter. Limit price of the order. If it is specified, the order type is
either 'limit', or 'stop-limit'. 'NaN' should be specified for any other order type.
stop (float) An optional parameter. Stop price of the order. If it is specified, the order type is
either 'stop', or 'stop-limit'. 'NaN' should be specified for any other order type.
oca_name (string) An optional parameter. Name of the OCA group the order belongs to. If the
order should not belong to any particular OCA group, there should be an empty string.
oca_type (string) An optional parameter. Type of the OCA group. The allowed values
are: strategy.oca.none - the order should not belong to any particular OCA
group; strategy.oca.cancel - the order should belong to an OCA group, where as soon as an
order is filled, all other orders of the same group are cancelled; strategy.oca.reduce - the
order should belong to an OCA group, where if X number of contracts of an order is filled,
number of contracts for each other order of the same OCA group is decreased by X.
comment (string) An optional parameter. Additional notes and commentary on the order.
when (bool) An optional parameter. Condition of the order. The order is placed if condition is
'true'. If condition is 'false', nothing happens (the previously placed order with the same ID is
not cancelled). Default value is 'true'.
strategy.risk.allow_entry_in
The purpose of this rule is to forbid short entries, only long etries will be placed. The rule
affects the following function: 'entry'.
strategy.risk.allow_entry_in(value) → void
EXAMPLE
strategy("risk.long_only Demo")
// ...
strategy("risk.max_intraday_filled_orders Demo")
// ...
strategy.risk.max_position_size(10)
study(title='MyScriptStudy')
study(title="MyScriptStudy", shorttitle="MSS", precision=6, overlay=true)
ARGUMENTS
title (const string) study title that would be seen in Indicators widget. Argument IS REQUIRED.
shorttitle (const string) study short title that would be seen in the chart legend. Argument is
optional.
overlay (const bool) if true the study will be added as an overlay for the main series. If false -
it would be added on a separate chart pane. Default is false.
format (const string) type of formatting study values on the price axis. Possible values
are: format.inherit, format.price, format.volume. Default is format.inherit.
precision (const integer) number of digits after the floating point for study values on the price
axis. Must be a non negative integer and not greater than 16. If omitted, using formatting from
parent series. If format is format.inherit and this argument is set, then format
becomes format.price.
scale (const integer) price scale that the indicator should be attached to. Possible values
are: scale.right, scale.left, scale.none. Value scale.none can be applied only in combination
with 'overlay=true' setting. If omitted, using scale from main series.
max_bars_back (const integer) Maximum number of bars available for a study for historical
reference. This parameter is applied to every built-in or user variable in the script if there is a
reference to historical data of a variable in the script code (‘[]’ operator is used). Variable
buffer sizes in the Pine Script are typically autodetected. This however is not possible in
certain cases which is why the parameter allows a user to manually set the lower bound of this
value. NOTE: using of the max_bars_back function instead of the parameter is optimal because
it applies to only one variable.
linktoseries (const bool) if true then the study will be always on the same pane and same
price scale as the main series. Should be used only in combination with 'overlay=true'. Default
is false.
REMARKS
Every script must have one study call.
sum
The sum function returns the sliding sum of last y values of x.
sum(source, length) → series[float]
RETURNS
Sum of x for y bars back.
ARGUMENTS
source (series) Series of values to process.
length (integer) Number of bars (length).
SEE ALSO
cumfor
supertrend
The Supertrend Indicator. The Supertrend is a trend following indicator.
supertrend(factor, atrPeriod) → [series[float], series[float]]
EXAMPLE
//@version=4
study("Supertrend", overlay=true)
plot(swma(close))
pine_swma(x) =>
t2 = heikinashi(t)
//@version=4
study("Time", overlay=true)
//@version=4
study("Time", overlay=true)
t1 = time(timeframe.period, "0000-0000")
bgcolor(t1 ? color.blue : na)
You can change that by specifying the days:
EXAMPLE
//@version=4
t1 = time(timeframe.period, "0000-0000:1234567")
bgcolor(t1 ? color.green : na)
RETURNS
UNIX time.
ARGUMENTS
resolution (string) Resolution.
session (string) Session specification. Optional argument, session of the symbol used by
default.
REMARKS
UNIX time is the number of milliseconds that have elapsed since 00:00:00 UTC, 1 January 1970.
SEE ALSO
time
timestamp
Function timestamp returns UNIX time of specified date and time.
timestamp(year, month, day, hour, minute, second) → integer
timestamp(timezone, year, month, day, hour, minute, second) → integer
timestamp(year, month, day, hour, minute, second) → series[integer]
timestamp(timezone, year, month, day, hour, minute, second) → series[integer]
EXAMPLE
//@version=4
study("My Script")
slow = sma(close, 7)
plot(vwma(close, 15))
pine_vwma(x, y) =>
plot(wma(close, 15))
norm = 0.0
sum = 0.0
for i = 0 to y - 1
weight = (y - i) * y
sum / norm
plot(pine_wma(close, 15))
RETURNS
Weighted moving average of x for y bars back.
ARGUMENTS
source (series) Series of values to process.
length (integer) Number of bars (length).
SEE ALSO
smaemarmavwmaswmaalma
wpr
Williams %R. The oscillator shows the current closing price in relation to the high and low of
the past 'length' bars.
wpr(length) → series[float]
EXAMPLE
//@version=4