
Pine Script has a number of predefined functions that can be used to perform various operations such as mathematical calculations, data analysis, and charting. Here are some examples of commonly used predefined functions in Pine Script:
Mathematical Functions:
abs(x)
: returns the absolute value of x.acos(x)
: returns the arc cosine of x.asin(x)
: returns the arc sine of x.atan(x)
: returns the arc tangent of x.ceil(x)
: returns the smallest integer that is greater than or equal to x.cos(x)
: returns the cosine of x.exp(x)
: returns e raised to the power of x.floor(x)
: returns the largest integer that is less than or equal to x.log(x)
: returns the natural logarithm (base e) of x.ln(x)
: returns the natural logarithm (base e) of x.max(x1, x2, ...)
: returns the maximum value among its arguments.min(x1, x2, ...)
: returns the minimum value among its arguments.pow(x, y)
: returns x raised to the power of y.round(x)
: returns x rounded to the nearest integer.sin(x)
: returns the sine of x.sqrt(x)
: returns the square root of x.tan(x)
: returns the tangent of x.
Technical Indicator Functions:
sma(source, length)
: returns the Simple Moving Average of thesource
data with a specifiedlength
.ema(source, length)
: returns the Exponential Moving Average of thesource
data with a specifiedlength
.macd(source, fast_length, slow_length, signal_length)
: returns the Moving Average Convergence Divergence of thesource
data with specifiedfast_length
,slow_length
andsignal_length
.rsi(source, length)
: returns the Relative Strength Index of thesource
data with a specifiedlength
.stoch(source, fast_length, slow_length)
: returns the Stochastic Oscillator of thesource
data with specifiedfast_length
andslow_length
.adx(source, length)
: returns the Average Directional Index of thesource
data with a specifiedlength
.cci(source, length)
: returns the Commodity Channel Index of thesource
data with a specifiedlength
.
Data Access Functions:
open
,high
,low
,close
,volume
: returns the open, high, low, close, and volume data of the current bar respectively.bar_index
: returns the index of the current bar.time
: returns the timestamp of the current bar.security(ticker, resolution, lookahead = barmerge.lookahead_on)
: returns the security with the specified ticker symbol, resolution, and lookahead mode.
Control Flow Functions:
input(def, type=input.type.real, title="")
: creates an input parameter with a default value, input type, and title.strategy.entry(id, strategy.long, qty=1, when=strategy.entry.at_market, comment="")
: creates a long entry order with an id, quantity, order type, and comment.strategy.exit(id, comment="")
: closes a position with a specified id and comment.
These are just a few examples of the many predefined functions available in Pine Script. Pine Script has a vast library of functions that can be used to perform various types of calculations, data analysis, and charting. It's worth noting that Pine Script is an open-source language and new functions are continuously being added by the community