May 17, 2017
More possibilities with compile time constants

Pine Script used to have 3 types of constants – literal, non-literal and serial. Now there’s one more, but let’s look at existing ones first.

The literal type includes fixed values such as 15.5, -2.
The non-literal type has a single value on all bars but isn’t a literal e.g. a ticker, interval, or sin(1).
The serial type constant represents numbers that have different values on different bars such as close, and time

Some functions (input, color) can only accept literals as certain arguments. We realized that it could be more convenient, so we added a new type of constants that can be calculated during compilation. In addition to literals, they include mathematical expressions that use other literals and constants.

Any type of Pine Script literal (integer, float, boolean, string) is the most specific type while the serial type is the most general one. The compilation-time constants take a spot between the literal and non-literal types. All of the functions that accepted literal as an argument will now accept compilation-time constants as well. There are several ways to call functions, as shown below.

```pi = acos(-1)
r = input(pi)

mins = input(24*60)```
```la = barmerge.lookahead_on
daily = security(tickerid, 'D', close, lookahead=la)
daily_low = security(tickerid, 'D', low, lookahead=la)```
```in_sma='SMA', in_ema='EMA', in_mixed='1/2 SMA + 1/2 EMA'
smoothing = input(in_sma, options=[in_sma, in_ema, in_mixed])

smoothed = na
if smoothing == in_sma
smoothed := sma(close, 7)

if smoothing == in_ema
smoothed := ema(close, 7)

if smoothing == in_mixed
smoothed := 0.5*sma(close, 7) + 0.5*ema(close, 7)```
{"ft_lang_label":"__label__en","ft_lang_prob":0.8458682,"math_prob":0.98417246,"size":1608,"snap":"2020-24-2020-29","text_gpt3_token_len":408,"char_repetition_ratio":0.13029926,"word_repetition_ratio":0.0,"special_character_ratio":0.25746268,"punctuation_ratio":0.15141957,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97237223,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-15T09:57:05Z\",\"WARC-Record-ID\":\"<urn:uuid:bf18ab45-039f-4b57-90a4-6332e034a628>\",\"Content-Length\":\"84654\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8db64701-8777-416d-9464-87b656bbb999>\",\"WARC-Concurrent-To\":\"<urn:uuid:8ee48a02-7205-4a99-9708-7a21efba0144>\",\"WARC-IP-Address\":\"13.249.39.100\",\"WARC-Target-URI\":\"https://www.tradingview.com/blog/en/possibilities-compile-time-constants-4127/\",\"WARC-Payload-Digest\":\"sha1:2YQHNB7N3L74MQRIBUDECJPAGNFZB44H\",\"WARC-Block-Digest\":\"sha1:L6AL6ZAPMC72T3M5WSC65VY6SABUHINZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593657163613.94_warc_CC-MAIN-20200715070409-20200715100409-00403.warc.gz\"}"}