CINXE.COM

Language / Type system

<!DOCTYPE html><html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><script> const url = window.location.href; const expectedUrl = url.replace( /^https:\/\/(?!beta)(\w+\.)?tradingview\.com/, 'https://www.tradingview.com', ); if (url !== expectedUrl) { window.location.replace(expectedUrl); } </script><meta name="astro-view-transitions-enabled" content="true"><meta name="astro-view-transitions-fallback" content="none"><link rel="icon" href="https://static.tradingview.com/static/images/favicon.ico"><link rel="icon" type="image/svg+xml" href="/pine-script-docs/favicon.svg"><title>Language / Type system</title><meta name="og:title" content="Language / Type system"><meta name="twitter:title" content="Language / Type system"><meta name="description" content="Everything you need to know about Pine Script™."><meta name="og:description" content="Everything you need to know about Pine Script™."><meta name="twitter:description" content="Everything you need to know about Pine Script™."><meta name="keywords" content="tradingview, pine, script, indicators, strategies"><meta name="og:image" content="/pine-script-docs/meta-image.png"><meta name="twitter:image" content="/pine-script-docs/meta-image.png"><meta name="og:image:width" content="1200"><meta name="og:image:height" content="630"><meta name="og:url" content="https://www.tradingview.com/pine-script-docs/language/type-system/"><meta name="twitter:url" content="https://www.tradingview.com/pine-script-docs/language/type-system/"><meta name="og:type" content="website"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:site" content="@TradingView"><link rel="canonical" href="https://www.tradingview.com/pine-script-docs/language/type-system/"><link rel="sitemap" href="/pine-script-docs/sitemap-index.xml"><link rel="stylesheet" href="/pine-script-docs/_astro/index.CI8A0IeF.css"> <link rel="stylesheet" href="/pine-script-docs/_astro/index.BL2bgAvq.css"> <style>.tv-spinner{display:none;position:absolute;margin:0 auto;border:0 solid rgb(149 152 161 / 20%);border-radius:50%;border-top-color:var(--tv-spinner-color, #2962ff);border-left-color:var(--tv-spinner-color, #2962ff);animation:tv-spinner-container-rotate .9s linear infinite}.tv-spinner-shown{display:block}.tv-spinner-size-large{top:calc(50% - 32px);left:calc(50% - 32px);width:56px;height:56px;border-width:4px}@keyframes tv-spinner-container-rotate{to{transform:rotate(360deg)}}:root{--page-background-color: #fff;background-color:var(--page-background-color)}:root[data-theme=dark]{--page-background-color: #000}body{background-color:var(--page-background-color)}#redirect-link{display:flex;position:absolute;inset:0;align-items:center;justify-content:center}#spinner{display:block;position:absolute;opacity:1;transition:opacity .2s} .twitter-tweet:not(.twitter-tweet-rendered){padding:var(--tc-padding, 1em);border:1px solid var(--tc-border-color, #cfd9de)}.twitter-tweet:not(.twitter-tweet-rendered)>:first-child{margin-top:0}.twitter-tweet:not(.twitter-tweet-rendered)>:last-child{margin-bottom:0}lite-youtube{background-color:#000;position:relative;display:block;contain:content;background-position:center center;background-size:cover;cursor:pointer;max-width:720px}lite-youtube:before{content:attr(data-title);display:block;position:absolute;top:0;background-image:linear-gradient(180deg,#000000ab,#0000008a 14%,#00000026 54%,#0000000d 72%,#0000 94%);height:99px;width:100%;font-family:YouTube Noto,Roboto,Arial,Helvetica,sans-serif;color:#eee;text-shadow:0 0 2px rgba(0,0,0,.5);font-size:18px;padding:25px 20px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;box-sizing:border-box}lite-youtube:hover:before{color:#fff}lite-youtube:after{content:"";display:block;padding-bottom:56.25%}lite-youtube>iframe{width:100%;height:100%;position:absolute;top:0;left:0;border:0}lite-youtube>.lty-playbtn{display:block;width:100%;height:100%;background:no-repeat center/68px 48px;background-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 68 48"><path d="M66.52 7.74c-.78-2.93-2.49-5.41-5.42-6.19C55.79.13 34 0 34 0S12.21.13 6.9 1.55c-2.93.78-4.63 3.26-5.42 6.19C.06 13.05 0 24 0 24s.06 10.95 1.48 16.26c.78 2.93 2.49 5.41 5.42 6.19C12.21 47.87 34 48 34 48s21.79-.13 27.1-1.55c2.93-.78 4.64-3.26 5.42-6.19C67.94 34.95 68 24 68 24s-.06-10.95-1.48-16.26z" fill="red"/><path d="M45 24 27 14v20" fill="white"/></svg>');position:absolute;cursor:pointer;z-index:1;filter:grayscale(100%);transition:filter .1s cubic-bezier(0,0,.2,1);border:0}lite-youtube:hover>.lty-playbtn,lite-youtube .lty-playbtn:focus{filter:none}lite-youtube.lyt-activated{cursor:unset}lite-youtube.lyt-activated:before,lite-youtube.lyt-activated>.lty-playbtn{opacity:0;pointer-events:none}.lyt-visually-hidden{clip:rect(0 0 0 0);clip-path:inset(50%);height:1px;overflow:hidden;position:absolute;white-space:nowrap;width:1px}lite-youtube>iframe{all:unset!important;width:100%!important;height:100%!important;position:absolute!important;inset:0!important;border:0!important}lite-vimeo{font-size:10px;background-color:#000;position:relative;display:block;contain:content;background-position:center center;background-size:cover}lite-vimeo:after{content:"";display:block;padding-bottom:56.25%}lite-vimeo>iframe{all:unset!important;width:100%!important;height:100%!important;position:absolute!important;inset:0!important;border:0!important}lite-vimeo>.ltv-playbtn{content:"";position:absolute;inset:0;width:100%;background:transparent;outline:0;border:0;cursor:pointer}lite-vimeo>.ltv-playbtn:before{width:6.5em;height:4em;background:#172322bf;opacity:.8;border-radius:.25rem;transition:all .2s cubic-bezier(0,0,.2,1)}lite-vimeo>.ltv-playbtn:focus:before{outline:auto}lite-vimeo:hover>.ltv-playbtn:before{background-color:#00adef;background-color:var(--ltv-color, #00adef);opacity:1}lite-vimeo>.ltv-playbtn:after{border-style:solid;border-width:1em 0 1em 1.7em;border-color:transparent transparent transparent #fff}lite-vimeo>.ltv-playbtn:before,lite-vimeo>.ltv-playbtn:after{content:"";position:absolute;top:50%;left:50%;transform:translate3d(-50%,-50%,0)}lite-vimeo.ltv-activated:before,lite-vimeo.ltv-activated>.ltv-playbtn{cursor:unset;opacity:0;pointer-events:none} </style><script type="module" src="/pine-script-docs/_astro/hoisted.6418KLaP.js"></script></head> <body> <div id="search-content-blur" hidden></div> <script> /* eslint-disable @typescript-eslint/typedef */ window.ThemeProvider = (() => { function getCurrent() { return ( // eslint-disable-next-line no-restricted-syntax typeof localStorage !== 'undefined' && localStorage.getItem('tv-docs-theme') ); } const storedTheme = getCurrent(); const theme = storedTheme || (window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'); document.documentElement.dataset.theme = theme === 'light' ? 'light' : 'dark'; document.documentElement.classList.toggle( 'theme-dark', theme === 'dark', ); // add support for ui-lib themes document.documentElement.classList.toggle( 'sl-theme-dark', theme === 'dark', ); // add support for shoelace themes return { updatePickers(themeArg = storedTheme || 'auto') { let currentTheme = themeArg; if (currentTheme === 'unknown') { currentTheme = getCurrent() || 'auto'; } document .querySelectorAll('docs-theme-select') .forEach((picker) => { const select = picker.querySelector('select'); if (select) select.value = currentTheme; /** @type {HTMLTemplateElement | null} */ const tmpl = document.querySelector(`#theme-icons`); const newIcon = tmpl && tmpl.content.querySelector('.' + currentTheme); if (newIcon) { const oldIcon = picker.querySelector('svg.label-icon'); if (oldIcon) { oldIcon.replaceChildren( ...newIcon.cloneNode(true).childNodes, ); } } }); }, }; })(); /* eslint-enable @typescript-eslint/typedef */ </script><template id="theme-icons"><svg width="16" height="16" viewBox="0 0 28 28" class="light" data-icon="theme/sun-28"> <symbol id="ai:local:theme/sun-28"><g fill="currentColor"><path d="M14 3h1.5v5H14V3Zm0 18h1.5v5H14v-5Zm12-5.5V14h-5v1.5h5ZM8 14v1.5H3V14h5Zm15.3-7-1-1-3.6 3.6 1.1 1 3.5-3.5ZM9.5 18.7l1.1 1.1-3.5 3.5-1-1 3.4-3.6ZM22 23.3l1-1-3.6-3.6-1 1.1 3.5 3.5ZM10.3 9.6l-1.1 1-3.5-3.5 1-1 3.6 3.5Z"/><path fill-rule="evenodd" d="M19 14.5a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Zm-1.5 0a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" clip-rule="evenodd"/></g></symbol><use xlink:href="#ai:local:theme/sun-28"></use> </svg><svg width="16" height="16" viewBox="0 0 28 28" class="dark" data-icon="theme/moon-28"> <symbol id="ai:local:theme/moon-28"><path fill="currentColor" fill-rule="evenodd" d="M21 7.02A9.23 9.23 0 0 0 15.2 5 9.1 9.1 0 0 0 6 14c0 4.97 4.12 9 9.2 9a9.33 9.33 0 0 0 5.8-2.02A7 7 0 0 1 14.36 14 7 7 0 0 1 21 7.02Zm-3.95-.3a7.91 7.91 0 0 0-1.85-.22A7.6 7.6 0 0 0 7.5 14a7.6 7.6 0 0 0 7.7 7.5 8 8 0 0 0 1.85-.22A8.46 8.46 0 0 1 12.86 14c0-3.1 1.69-5.8 4.19-7.28Z" clip-rule="evenodd"/></symbol><use xlink:href="#ai:local:theme/moon-28"></use> </svg><svg width="16" height="16" viewBox="0 0 28 28" class="auto" data-icon="theme/system-28"> <symbol id="ai:local:theme/system-28"><path fill="currentColor" d="M8 4h1v2H8V4Zm0 9v2h1v-2H8Zm6-3V9h-2v1h2ZM3 9v1h2V9H3Zm5.5 3a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5Zm4.2-6-.7-.7-1.4 1.4.7.7L12.7 6ZM5 13.7l-.7-.7 1.4-1.4.7.7L5 13.7Zm7.7-.7-.7.7-1.4-1.4.7-.7 1.4 1.4ZM4.3 6l.7-.7 1.4 1.4-.7.7L4.3 6Zm3 17 14-14 .8.7L8 23.7l-.7-.7Zm17.2-.1a3.5 3.5 0 0 1-3.4-5.9H21a4 4 0 1 0 3.5 5.9Z"/></symbol><use xlink:href="#ai:local:theme/system-28"></use> </svg></template> <div class="backdrop" data-mobile-menu-backdrop data-astro-cid-h2irkosh></div> <div class="menu-container" data-astro-cid-h2irkosh> <div class="header" data-astro-cid-h2irkosh> <div class="header-group" data-astro-cid-h2irkosh> <div id="version-select" data-astro-cid-kx7qoxgq> <label style="--sl-select-width: undefined; --sl-label-icon-size: 16px;" data-astro-cid-lmznfliq> <span class="sr-only" data-astro-cid-lmznfliq>Version</span> <select value="v6" data-has-border no-icon="true" data-astro-cid-lmznfliq> <option value="v6" selected="true" data-astro-cid-lmznfliq>Version 6</option><option value="v5" data-astro-cid-lmznfliq>Version 5</option><option value="v4" data-astro-cid-lmznfliq>Version 4</option><option value="v3" data-astro-cid-lmznfliq>Version 3</option> </select> <svg width="16" height="16" viewBox="0 0 24 24" class="icon caret" data-astro-cid-lmznfliq data-icon="theme/down-caret"> <symbol id="ai:local:theme/down-caret"><path fill="currentColor" d="M17 9.17a1 1 0 0 0-1.41 0L12 12.71 8.46 9.17a1 1 0 1 0-1.41 1.42l4.24 4.24a1.002 1.002 0 0 0 1.42 0L17 10.59a1.002 1.002 0 0 0 0-1.42Z"/></symbol><use xlink:href="#ai:local:theme/down-caret"></use> </svg> </label> </div> <docs-theme-select class="" data-astro-cid-3wpspbi7> <label style="--sl-select-width: 48px; --sl-label-icon-size: 28px;" data-astro-cid-lmznfliq> <span class="sr-only" data-astro-cid-lmznfliq>Theme</span> <svg width="28" height="28" viewBox="0 0 28 28" class="icon label-icon" data-button data-round data-astro-cid-lmznfliq data-icon="theme/system-28"> <use xlink:href="#ai:local:theme/system-28"></use> </svg> <select value="auto" data-button data-astro-cid-lmznfliq> <option value="dark" data-astro-cid-lmznfliq>&nbsp;&nbsp;Dark&nbsp;&nbsp;</option><option value="light" data-astro-cid-lmznfliq>&nbsp;&nbsp;Light&nbsp;&nbsp;</option><option value="auto" selected="true" data-astro-cid-lmznfliq>&nbsp;&nbsp;Auto&nbsp;&nbsp;</option> </select> </label> </docs-theme-select> <script> ThemeProvider.updatePickers('unknown'); </script> </div> <div class="header-group" data-astro-cid-h2irkosh> <div class="not-content" style="stroke-width:2px" data-astro-cid-pkzv2hgs> <button id="mobile-menu-back-button" title="Close menu" data-astro-cid-pkzv2hgs class="not-content stvb-base stvb-pointer stvb-gray stvb-medium stvb-primary stvb-icon"> <svg width="28" height="28" viewBox="0 0 28 28" data-astro-cid-h2irkosh data-icon="theme/arrow-back"> <symbol id="ai:local:theme/arrow-back"><g fill="none"><g clip-path="url(#a)"><path stroke="var(--arrow-fill-color, #131722)" d="m17 20-6-6 6-6"/></g><defs><clipPath id="a"><path fill="#fff" d="M28 28H0V0h28z"/></clipPath></defs></g></symbol><use xlink:href="#ai:local:theme/arrow-back"></use> </svg> </button> </div> </div> </div> <aside id="nav" class="keep-visible" style="--navbar-right-border-width: 0px" data-astro-cid-sa57sq6l> <div class="sidebar-viewport slick-scroll" data-astro-cid-sa57sq6l> <div class="sidebar" data-mobile data-astro-cid-sa57sq6l> <ul class="toc" aria-label="Docs sidebar" data-astro-cid-sa57sq6l> <li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/welcome" data-astro-cid-omxx3dey>Welcome to Pine Script™ v6</a></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Pine Script™ primer</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/primer/first-steps" data-astro-cid-omxx3dey>First steps</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/primer/first-indicator" data-astro-cid-omxx3dey>First indicator</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/primer/next-steps" data-astro-cid-omxx3dey>Next steps</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details open data-is-parent data-is-on-path data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Language</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/execution-model" data-astro-cid-omxx3dey>Execution model</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/time-series" data-astro-cid-omxx3dey>Time series</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/script-structure" data-astro-cid-omxx3dey>Script structure</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/identifiers" data-astro-cid-omxx3dey>Identifiers</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/operators" data-astro-cid-omxx3dey>Operators</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/variable-declarations" data-astro-cid-omxx3dey>Variable declarations</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/conditional-structures" data-astro-cid-omxx3dey>Conditional structures</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/loops" data-astro-cid-omxx3dey>Loops</a></li><li class="item" data-current data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/type-system" data-astro-cid-omxx3dey>Type system</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/built-ins" data-astro-cid-omxx3dey>Built-ins</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/user-defined-functions" data-astro-cid-omxx3dey>User-defined functions</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/objects" data-astro-cid-omxx3dey>Objects</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/enums" data-astro-cid-omxx3dey>Enums</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/methods" data-astro-cid-omxx3dey>Methods</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/arrays" data-astro-cid-omxx3dey>Arrays</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/matrices" data-astro-cid-omxx3dey>Matrices</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/maps" data-astro-cid-omxx3dey>Maps</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Concepts</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/alerts" data-astro-cid-omxx3dey>Alerts</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/backgrounds" data-astro-cid-omxx3dey>Backgrounds</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/bar-coloring" data-astro-cid-omxx3dey>Bar coloring</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/bar-plotting" data-astro-cid-omxx3dey>Bar plotting</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/bar-states" data-astro-cid-omxx3dey>Bar states</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/chart-information" data-astro-cid-omxx3dey>Chart information</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/colors" data-astro-cid-omxx3dey>Colors</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/fills" data-astro-cid-omxx3dey>Fills</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/inputs" data-astro-cid-omxx3dey>Inputs</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/levels" data-astro-cid-omxx3dey>Levels</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/libraries" data-astro-cid-omxx3dey>Libraries</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/lines-and-boxes" data-astro-cid-omxx3dey>Lines and boxes</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/non-standard-charts-data" data-astro-cid-omxx3dey>Non-standard charts data</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/other-timeframes-and-data" data-astro-cid-omxx3dey>Other timeframes and data</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/plots" data-astro-cid-omxx3dey>Plots</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/repainting" data-astro-cid-omxx3dey>Repainting</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/sessions" data-astro-cid-omxx3dey>Sessions</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/strategies" data-astro-cid-omxx3dey>Strategies</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/tables" data-astro-cid-omxx3dey>Tables</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/text-and-shapes" data-astro-cid-omxx3dey>Text and shapes</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/time" data-astro-cid-omxx3dey>Time</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/timeframes" data-astro-cid-omxx3dey>Timeframes</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Writing scripts</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/style-guide" data-astro-cid-omxx3dey>Style guide</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/debugging" data-astro-cid-omxx3dey>Debugging</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/profiling-and-optimization" data-astro-cid-omxx3dey>Profiling and optimization</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/publishing" data-astro-cid-omxx3dey>Publishing scripts</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/limitations" data-astro-cid-omxx3dey>Limitations</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>FAQ</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/general" data-astro-cid-omxx3dey>General</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/alerts" data-astro-cid-omxx3dey>Alerts</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/data-structures" data-astro-cid-omxx3dey>Data structures</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/functions" data-astro-cid-omxx3dey>Functions</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/indicators" data-astro-cid-omxx3dey>Indicators</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/other-data-and-timeframes" data-astro-cid-omxx3dey>Other data and timeframes</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/programming" data-astro-cid-omxx3dey>Programming</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/strings-and-formatting" data-astro-cid-omxx3dey>Strings and formatting</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/error-messages" data-astro-cid-omxx3dey>Error messages</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/release-notes" data-astro-cid-omxx3dey>Release notes</a></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Migration guides</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-6" data-astro-cid-omxx3dey>To Pine Script™ version 6</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-5" data-astro-cid-omxx3dey>To Pine Script™ version 5</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-4" data-astro-cid-omxx3dey>To Pine Script™ version 4</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-3" data-astro-cid-omxx3dey>To Pine Script™ version 3</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/where-can-i-get-more-information" data-astro-cid-omxx3dey>Where can I get more information?</a></li> </ul> <div class="toc-bottom" data-astro-cid-sa57sq6l></div> </div> </div> </aside> </div> <header class="header" data-astro-cid-d74r2unp> <nav role="navigation" aria-label="Main Navigation" data-astro-cid-d74r2unp> <mobile-menu-button id="mobile-menu-button-wc" data-astro-cid-oojooh3d> <!-- Annoyingly I need to wrap this. TODO: improve this --> <div id="mobile-menu-button-header" data-astro-cid-oojooh3d> <div class="not-content" style="" data-astro-cid-pkzv2hgs> <button title="Open navigation menu" data-astro-cid-pkzv2hgs class="not-content stvb-base stvb-pointer stvb-gray stvb-medium stvb-secondary stvb-icon stvb-icon-force-color stvb-force-no-border"> <svg width="28" height="28" viewBox="0 0 24 24" data-astro-cid-oojooh3d data-icon="theme/bars"> <symbol id="ai:local:theme/bars"><path fill="currentColor" d="M3 8h18a1 1 0 1 0 0-2H3a1 1 0 0 0 0 2Zm18 8H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2Zm0-5H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2Z"/></symbol><use xlink:href="#ai:local:theme/bars"></use> </svg> </button> </div> </div> </mobile-menu-button> <div data-hide-when-search data-astro-cid-d74r2unp> <div class="header-logo" data-astro-cid-tycb33lk> <a href="/pine-script-docs/" aria-label="Home button" data-astro-cid-tycb33lk> <div class="documentation-logo logo" data-astro-cid-tycb33lk><svg width="188" height="44" viewBox="0 0 188 44" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M26.9989 28.0001L18.4281 20.7531L11.3382 23.2611C10.402 23.5923 9.60771 22.5041 10.2085 21.7134L21.0877 7.39502C21.4749 6.88536 22.2346 6.86567 22.6478 7.35459L34.7627 21.6923C35.1531 22.1543 35.0472 22.8544 34.5376 23.1802L26.9989 28.0001ZM32.4978 22.1105L27.1641 25.5207L19.7195 19.2258C19.1767 18.7669 18.4312 18.6305 17.7611 18.8676L13.8245 20.2602L21.9253 9.59841L32.4978 22.1105Z" fill="currentColor"/> <path d="M33.432 28.0842L38.3592 34.7471C38.7427 35.2657 38.3724 36 37.7274 36H6.27248C5.62746 36 5.25722 35.2657 5.64074 34.7471L10.8523 27.6996C10.9484 27.5697 11.0822 27.4725 11.2356 27.4214L17.6878 25.2707C17.9285 25.1904 18.1932 25.2314 18.3984 25.3806L26.2854 31.1166C26.5445 31.3051 26.8922 31.3173 27.1639 31.1475L32.3838 27.885C32.7316 27.6677 33.1881 27.7544 33.432 28.0842Z" fill="currentColor"/> <path d="M59.56 13.96C63.016 13.96 65.536 16.456 65.536 19.696C65.536 22.936 63.016 25.432 59.56 25.432H57.376V31H53.896V13.96H59.56ZM59.512 22.168C61.096 22.168 62.152 21.088 62.152 19.696C62.152 18.304 61.096 17.224 59.512 17.224H57.376V22.168H59.512ZM70.8636 14.944C70.8636 16.096 69.9276 17.032 68.7516 17.032C67.6236 17.032 66.6636 16.096 66.6636 14.944C66.6636 13.792 67.6236 12.856 68.7516 12.856C69.9276 12.856 70.8636 13.792 70.8636 14.944ZM67.1196 31V19H70.4076V31H67.1196ZM73.0849 31V19H76.3729V20.368C76.9969 19.408 78.2449 18.736 79.8049 18.736C82.7089 18.736 84.4369 20.848 84.4369 23.968V31H81.1489V24.52C81.1489 22.792 80.4049 21.736 79.0369 21.736C77.5249 21.736 76.3729 22.84 76.3729 25.144V31H73.0849ZM86.2041 25C86.2041 21.448 88.8681 18.736 92.5161 18.736C95.6601 18.736 98.4201 20.752 98.4201 24.64C98.4201 24.928 98.4201 25.264 98.3721 25.768H89.3961C89.5881 27.376 91.0041 28.264 92.5881 28.264C94.0761 28.264 95.1561 27.568 95.6841 26.752L98.1321 28.576C97.0281 30.184 95.0841 31.264 92.5641 31.264C88.9881 31.264 86.2041 28.792 86.2041 25ZM92.4201 21.448C91.1961 21.448 89.8281 22.072 89.5161 23.536H95.1321C94.8441 22.12 93.6441 21.448 92.4201 21.448ZM104.412 28.24L107.076 26.008C107.916 27.28 109.38 28.024 110.772 28.024C112.14 28.024 113.052 27.352 113.052 26.368C113.052 25.408 112.356 24.736 110.676 24.16L109.236 23.656C106.5 22.696 105.036 21.112 105.036 18.784C105.036 15.568 107.484 13.672 110.796 13.672C112.884 13.672 114.708 14.392 116.172 16.024L113.868 18.4C113.052 17.416 111.996 16.936 110.82 16.936C109.644 16.936 108.54 17.44 108.54 18.448C108.54 19.48 109.38 19.936 111.18 20.584L112.548 21.088C115.044 22 116.604 23.584 116.604 26.152C116.58 29.2 114.156 31.288 110.628 31.288C107.916 31.288 105.636 30.112 104.412 28.24ZM129.859 27.808C128.827 29.872 126.667 31.264 124.171 31.264C120.619 31.264 117.811 28.624 117.811 25C117.811 21.376 120.619 18.736 124.171 18.736C126.667 18.736 128.827 20.128 129.859 22.192L127.003 23.728C126.523 22.624 125.491 21.808 124.171 21.808C122.443 21.808 121.123 23.152 121.123 25C121.123 26.848 122.443 28.192 124.171 28.192C125.491 28.192 126.523 27.376 127.003 26.272L129.859 27.808ZM131.482 31V19H134.77V20.92C135.178 19.744 136.402 18.856 137.746 18.856C138.082 18.856 138.442 18.88 138.85 19V22.336C138.346 22.168 137.89 22.072 137.362 22.072C135.802 22.072 134.77 23.296 134.77 25.264V31H131.482ZM144.215 14.944C144.215 16.096 143.279 17.032 142.103 17.032C140.975 17.032 140.015 16.096 140.015 14.944C140.015 13.792 140.975 12.856 142.103 12.856C143.279 12.856 144.215 13.792 144.215 14.944ZM140.471 31V19H143.759V31H140.471ZM146.436 36.016V19H149.724V20.344C150.276 19.576 151.548 18.736 153.204 18.736C156.396 18.736 158.844 21.592 158.844 25C158.844 28.408 156.396 31.264 153.204 31.264C151.548 31.264 150.276 30.424 149.724 29.656V36.016H146.436ZM155.508 25C155.508 23.128 154.284 21.736 152.484 21.736C150.684 21.736 149.46 23.128 149.46 25C149.46 26.872 150.684 28.264 152.484 28.264C154.284 28.264 155.508 26.872 155.508 25ZM168.407 30.88C167.879 31.048 167.231 31.144 166.319 31.144C163.775 31.144 161.735 29.728 161.735 26.8V21.88H159.311V19H161.735V15.664H165.023V19H168.407V21.88H165.023V26.152C165.023 27.616 165.647 28.192 167.063 28.192C167.591 28.192 168.023 28.12 168.407 27.976V30.88ZM177.626 22.648V13.96H179.978L181.874 16.888L183.746 13.96H186.122V22.648H183.698V18.184L181.874 20.968L180.026 18.136V22.648H177.626ZM171.386 22.648V16.456H169.058V13.96H176.258V16.456H173.93V22.648H171.386Z" fill="currentColor"/> </svg> </div> </a> </div> </div> <div class="flex" data-astro-cid-d74r2unp></div> <div class="flex" data-astro-cid-d74r2unp> <div class="search-container" data-astro-cid-fg37foga> <div class="search-wrapper" data-astro-cid-fg37foga> <input class="search-input" type="text" placeholder="Search docs" name="s" value="" data-astro-cid-fg37foga> <svg width="28" height="28" viewBox="0 0 28 28" class="search-button" data-astro-cid-fg37foga data-icon="theme/search"> <symbol id="ai:local:theme/search"><path fill="currentColor" fill-rule="evenodd" d="M18.5 12.5a6 6 0 1 1-12 0 6 6 0 0 1 12 0Zm-1.25 5.8a7.5 7.5 0 1 1 1.06-1.06l4.22 4.23.53.53L22 23.06l-.53-.53-4.22-4.22Z" clip-rule="evenodd"/></symbol><use xlink:href="#ai:local:theme/search"></use> </svg> <button class="search-clear" type="button" title="Reset" data-search-clear data-astro-cid-fg37foga>Clear</button> <span class="divider" data-astro-cid-fg37foga></span> <button class="search-close" type="button" title="Close" data-search-close data-astro-cid-fg37foga> <svg width="18" height="18" viewBox="0 0 18 18" data-astro-cid-fg37foga data-icon="theme/cross-18"> <use xlink:href="#ai:local:theme/cross-18"></use> </svg> </button> </div> <div id="search-results-wrapper" data-astro-cid-fg37foga> <aside id="search-results" hidden data-astro-cid-fg37foga> <!-- Don't use h1 because when built it will be used as the first heading on the page --> <div class="heading" data-astro-cid-fg37foga>Search results</div> <div id="search-results-contents" data-astro-cid-fg37foga></div> </aside> </div> </div> </div> <ul class="links" data-astro-cid-d74r2unp> </ul> <div class="flex" data-astro-cid-d74r2unp></div> <div data-hide-when-search data-astro-cid-d74r2unp> <div id="version-select" data-hideable="true" data-astro-cid-kx7qoxgq> <label style="--sl-select-width: undefined; --sl-label-icon-size: 16px;" data-astro-cid-lmznfliq> <span class="sr-only" data-astro-cid-lmznfliq>Version</span> <select value="v6" data-has-border no-icon="true" data-astro-cid-lmznfliq> <option value="v6" selected="true" data-astro-cid-lmznfliq>Version 6</option><option value="v5" data-astro-cid-lmznfliq>Version 5</option><option value="v4" data-astro-cid-lmznfliq>Version 4</option><option value="v3" data-astro-cid-lmznfliq>Version 3</option> </select> <svg width="16" height="16" viewBox="0 0 24 24" class="icon caret" data-astro-cid-lmznfliq data-icon="theme/down-caret"> <use xlink:href="#ai:local:theme/down-caret"></use> </svg> </label> </div> </div> <button id="search-button" data-astro-cid-6zeqadij> <svg width="28" height="28" viewBox="0 0 28 28" data-astro-cid-6zeqadij data-icon="theme/search"> <use xlink:href="#ai:local:theme/search"></use> </svg> </button> <script data-base-url="/pine-script-docs"> async function loadPageFind() { const base = document.currentScript.getAttribute('data-base-url'); const pageFindBundleUrl = `${base}/pagefind/`; const pagefind = await import(`${pageFindBundleUrl}pagefind.js`); await pagefind.options({ bundlePath: pageFindBundleUrl, }); window.pagefind = pagefind; } loadPageFind().catch(); </script> <docs-theme-select class="hide-with-breakpoint-568" data-astro-cid-3wpspbi7> <label style="--sl-select-width: 48px; --sl-label-icon-size: 28px;" data-astro-cid-lmznfliq> <span class="sr-only" data-astro-cid-lmznfliq>Theme</span> <svg width="28" height="28" viewBox="0 0 28 28" class="icon label-icon" data-button data-round data-astro-cid-lmznfliq data-icon="theme/system-28"> <use xlink:href="#ai:local:theme/system-28"></use> </svg> <select value="auto" data-button data-astro-cid-lmznfliq> <option value="dark" data-astro-cid-lmznfliq>&nbsp;&nbsp;Dark&nbsp;&nbsp;</option><option value="light" data-astro-cid-lmznfliq>&nbsp;&nbsp;Light&nbsp;&nbsp;</option><option value="auto" selected="true" data-astro-cid-lmznfliq>&nbsp;&nbsp;Auto&nbsp;&nbsp;</option> </select> </label> </docs-theme-select> <script> ThemeProvider.updatePickers('unknown'); </script> </nav> </header> <div id="image-lightbox" class="not-content" hidden data-astro-cid-kws7taxh> <div class="button-wrapper" data-astro-cid-kws7taxh> <div class="not-content" style="" data-astro-cid-pkzv2hgs> <button id="lightbox-close-button" title="Close image preview" data-astro-cid-pkzv2hgs class="not-content stvb-base stvb-pointer stvb-black stvb-medium stvb-secondary stvb-icon stvb-force-no-border"> <svg width="24" height="24" viewBox="0 0 18 18" data-astro-cid-kws7taxh data-icon="theme/cross-18"> <symbol id="ai:local:theme/cross-18"><g fill="none"><g clip-path="url(#a)"><path fill="currentColor" fill-rule="evenodd" d="M5.53 4.47 4.47 5.53 7.94 9l-3.47 3.47 1.06 1.06L9 10.06l3.47 3.47 1.06-1.06L10.06 9l3.47-3.47-1.06-1.06L9 7.94 5.53 4.47Z" clip-rule="evenodd"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h18v18H0z"/></clipPath></defs></g></symbol><use xlink:href="#ai:local:theme/cross-18"></use> </svg> </button> </div> </div> <img id="lightbox-image" src="" data-astro-cid-kws7taxh> </div> <div id="page-container" data-astro-cid-xgirumru> <aside id="nav" class="" style="" data-astro-cid-sa57sq6l> <div class="sidebar-viewport slick-scroll" data-astro-cid-sa57sq6l> <div class="sidebar" data-astro-cid-sa57sq6l> <ul class="toc" aria-label="Docs sidebar" data-astro-cid-sa57sq6l> <li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/welcome" data-astro-cid-omxx3dey>Welcome to Pine Script™ v6</a></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Pine Script™ primer</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <symbol id="ai:local:theme/right-caret"><path fill="currentColor" d="m14.83 11.29-4.24-4.24a1 1 0 1 0-1.42 1.41L12.71 12l-3.54 3.54a1 1 0 0 0 0 1.41 1 1 0 0 0 .71.29 1 1 0 0 0 .71-.29l4.24-4.24a1.002 1.002 0 0 0 0-1.42Z"/></symbol><use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/primer/first-steps" data-astro-cid-omxx3dey>First steps</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/primer/first-indicator" data-astro-cid-omxx3dey>First indicator</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/primer/next-steps" data-astro-cid-omxx3dey>Next steps</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details open data-is-parent data-is-on-path data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Language</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/execution-model" data-astro-cid-omxx3dey>Execution model</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/time-series" data-astro-cid-omxx3dey>Time series</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/script-structure" data-astro-cid-omxx3dey>Script structure</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/identifiers" data-astro-cid-omxx3dey>Identifiers</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/operators" data-astro-cid-omxx3dey>Operators</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/variable-declarations" data-astro-cid-omxx3dey>Variable declarations</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/conditional-structures" data-astro-cid-omxx3dey>Conditional structures</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/loops" data-astro-cid-omxx3dey>Loops</a></li><li class="item" data-current data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/type-system" data-astro-cid-omxx3dey>Type system</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/built-ins" data-astro-cid-omxx3dey>Built-ins</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/user-defined-functions" data-astro-cid-omxx3dey>User-defined functions</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/objects" data-astro-cid-omxx3dey>Objects</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/enums" data-astro-cid-omxx3dey>Enums</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/methods" data-astro-cid-omxx3dey>Methods</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/arrays" data-astro-cid-omxx3dey>Arrays</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/matrices" data-astro-cid-omxx3dey>Matrices</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/language/maps" data-astro-cid-omxx3dey>Maps</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Concepts</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/alerts" data-astro-cid-omxx3dey>Alerts</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/backgrounds" data-astro-cid-omxx3dey>Backgrounds</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/bar-coloring" data-astro-cid-omxx3dey>Bar coloring</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/bar-plotting" data-astro-cid-omxx3dey>Bar plotting</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/bar-states" data-astro-cid-omxx3dey>Bar states</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/chart-information" data-astro-cid-omxx3dey>Chart information</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/colors" data-astro-cid-omxx3dey>Colors</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/fills" data-astro-cid-omxx3dey>Fills</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/inputs" data-astro-cid-omxx3dey>Inputs</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/levels" data-astro-cid-omxx3dey>Levels</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/libraries" data-astro-cid-omxx3dey>Libraries</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/lines-and-boxes" data-astro-cid-omxx3dey>Lines and boxes</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/non-standard-charts-data" data-astro-cid-omxx3dey>Non-standard charts data</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/other-timeframes-and-data" data-astro-cid-omxx3dey>Other timeframes and data</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/plots" data-astro-cid-omxx3dey>Plots</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/repainting" data-astro-cid-omxx3dey>Repainting</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/sessions" data-astro-cid-omxx3dey>Sessions</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/strategies" data-astro-cid-omxx3dey>Strategies</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/tables" data-astro-cid-omxx3dey>Tables</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/text-and-shapes" data-astro-cid-omxx3dey>Text and shapes</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/time" data-astro-cid-omxx3dey>Time</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/concepts/timeframes" data-astro-cid-omxx3dey>Timeframes</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Writing scripts</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/style-guide" data-astro-cid-omxx3dey>Style guide</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/debugging" data-astro-cid-omxx3dey>Debugging</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/profiling-and-optimization" data-astro-cid-omxx3dey>Profiling and optimization</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/publishing" data-astro-cid-omxx3dey>Publishing scripts</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/writing/limitations" data-astro-cid-omxx3dey>Limitations</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>FAQ</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/general" data-astro-cid-omxx3dey>General</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/alerts" data-astro-cid-omxx3dey>Alerts</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/data-structures" data-astro-cid-omxx3dey>Data structures</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/functions" data-astro-cid-omxx3dey>Functions</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/indicators" data-astro-cid-omxx3dey>Indicators</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/other-data-and-timeframes" data-astro-cid-omxx3dey>Other data and timeframes</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/programming" data-astro-cid-omxx3dey>Programming</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/faq/strings-and-formatting" data-astro-cid-omxx3dey>Strings and formatting</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/error-messages" data-astro-cid-omxx3dey>Error messages</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/release-notes" data-astro-cid-omxx3dey>Release notes</a></li><li class="item" data-astro-cid-omxx3dey><details data-astro-cid-omxx3dey><summary data-astro-cid-omxx3dey><div class="summary-link" data-astro-cid-omxx3dey>Migration guides</div><div class="caret" data-astro-cid-omxx3dey><svg width="18" height="18" viewBox="0 0 24 24" class="icon" data-astro-cid-omxx3dey data-icon="theme/right-caret"> <use xlink:href="#ai:local:theme/right-caret"></use> </svg></div></summary><ul class="children" data-astro-cid-omxx3dey><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-6" data-astro-cid-omxx3dey>To Pine Script™ version 6</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-5" data-astro-cid-omxx3dey>To Pine Script™ version 5</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-4" data-astro-cid-omxx3dey>To Pine Script™ version 4</a></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/migration-guides/to-pine-version-3" data-astro-cid-omxx3dey>To Pine Script™ version 3</a></li></ul></details></li><li class="item" data-astro-cid-omxx3dey><a class="page-link" href="/pine-script-docs/where-can-i-get-more-information" data-astro-cid-omxx3dey>Where can I get more information?</a></li> </ul> <div class="toc-bottom" data-astro-cid-sa57sq6l></div> </div> </div> </aside> <main class="main-pane" data-page-type="md" data-astro-cid-xgirumru> <a id="top" data-astro-cid-xgirumru></a> <main class="content" data-toc-shown data-astro-cid-ju3wuhkz> <div class="content-width" data-astro-cid-xgirumru> <div class="breadcrumbs" data-pagefind-ignore data-astro-cid-wlavna2o> <a href="/pine-script-docs" aria-label="Return back to the documentation home page." data-astro-cid-wlavna2o> <span data-astro-cid-wlavna2o>User Manual</span> </a> <span class="divider" data-astro-cid-wlavna2o>/</span> <a href="/pine-script-docs/language/execution-model" data-astro-cid-wlavna2o>Language</a> <span class="divider" data-astro-cid-wlavna2o>/</span> <span class="current-item" data-astro-cid-wlavna2o>Type system</span> </div> </div> <div id="slot-container" data-astro-cid-xgirumru> <h1 id="type-system" class="md-heading"><a href="#type-system">Type system<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h1> <h2 id="introduction" class="md-heading"><a href="#introduction">Introduction<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h2> <p>The Pine Script™ type system determines the compatibility of a script’s values with various functions and operations. While it’s possible to write simple scripts without knowing anything about the type system, a reasonable understanding of it is necessary to achieve any degree of proficiency with the language, and an in-depth knowledge of its subtleties allows programmers to harness its full potential.</p> <p>Pine Script™ uses <a href="/pine-script-docs/language/type-system/#types">types</a> to classify all values, and it uses <a href="/pine-script-docs/language/type-system/#qualifiers">qualifiers</a> to determine whether values and references are constant, established on the first script execution, or dynamic across executions. This system applies to all Pine values and references, including literals, variables, expressions, function returns, and function arguments.</p> <p>The type system closely intertwines with Pine’s <a href="/pine-script-docs/language/execution-model/">execution model</a> and <a href="/pine-script-docs/language/time-series/">time series</a> concepts. Understanding all three is essential for making the most of the power of Pine Script™.</p> <aside aria-label="Notice!" class="tv-informer not-content" style="--informer-header-color:#FF9800;--informer-back-color-light:#FFF3E0;--informer-back-color-dark:#33261A"><div class="tv-informer-icon"><svg viewBox="0 0 18 18" width="18" height="18"><path fill-rule="evenodd" d="M9 17A8 8 0 1 0 9 1a8 8 0 0 0 0 16ZM9 4c-.79 0-1.38.7-1.25 1.48l.67 4.03a.59.59 0 0 0 1.16 0l.67-4.03A1.27 1.27 0 0 0 9 4Zm0 8a1 1 0 1 0 0 2 1 1 0 0 0 0-2Z" fill="currentColor"></path></svg></div><div class="tv-informer-content"><p><span class="tv-informer-header">Notice!</span>For the sake of brevity, we often use “type” to refer to a “qualified type”.</p></div></aside> <h2 id="qualifiers" class="md-heading"><a href="#qualifiers">Qualifiers<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h2> <p>Pine Script™ <em>qualifiers</em> identify when values are accessible to a script:</p> <ul> <li>Values and references qualified as <a href="/pine-script-docs/language/type-system/#const">const</a> are established at compile time (i.e., when saving the script in the Pine Editor or adding it to the chart).</li> <li>Values qualified as <a href="/pine-script-docs/language/type-system/#input">input</a> are established at input time (i.e., when confirming values based on user input, primarily from the “Settings/Inputs” tab).</li> <li>Values qualified as <a href="/pine-script-docs/language/type-system/#simple">simple</a> are established at bar zero (i.e., the first script execution).</li> <li>Values qualified as <a href="/pine-script-docs/language/type-system/#series">series</a> can change throughout the script’s executions.</li> </ul> <p>Pine Script™ bases the dominance of type qualifiers on the following hierarchy: <strong>const &lt; input &lt; simple &lt; series</strong>, where “const” is the <em>weakest</em> qualifier and “series” is the <em>strongest</em>. The qualifier hierarchy translates to this rule: whenever a variable, function, or operation is compatible with a specific qualified type, values with <em>weaker</em> qualifiers are also allowed.</p> <p>Scripts always qualify their expressions’ returned types based on the <em>dominant qualifier</em> in their calculations. For example, evaluating an expression that involves “input” and “series” values will return a value qualified as “series”. Furthermore, scripts <strong>cannot</strong> change a value’s qualifier to one that’s <em>lower</em> on the hierarchy. If a value acquires a <em>stronger</em> qualifier (e.g., a value initially inferred as “simple” becomes “series” later in the script’s executions), that state is irreversible.</p> <p>It’s important to note that “series” values are the <strong>only</strong> ones that can change across script executions, including those from various built-ins, such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_close">close</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_volume">volume</a>, as well as the results of expressions involving “series” values. All values qualified as “const”, “input”, or “simple” remain consistent across all script executions.</p> <h3 id="const" class="md-heading"><a href="#const">const<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Values or references qualified as “const” are established at <em>compile time</em>, before the script starts its executions. Compilation initially occurs when saving a script in the Pine Editor, which does not require it to run on a chart. Values or references with the “const” qualifier <em>never change</em> between script executions, not even on the first execution.</p> <p>All <em>literal</em> values and the results returned by expressions involving only values qualified as “const” automatically adopt the “const” qualifier.</p> <p>These are some examples of literal values:</p> <ul> <li><em>literal int</em>: <code dir="auto">1</code>, <code dir="auto">-1</code>, <code dir="auto">42</code></li> <li><em>literal float</em>: <code dir="auto">1.</code>, <code dir="auto">1.0</code>, <code dir="auto">3.14</code>, <code dir="auto">6.02E-23</code>, <code dir="auto">3e8</code></li> <li><em>literal bool</em>: <code dir="auto">true</code>, <code dir="auto">false</code></li> <li><em>literal color</em>: <code dir="auto">#FF55C6</code>, <code dir="auto">#FF55C6ff</code></li> <li><em>literal string</em>: <code dir="auto">&quot;A text literal&quot;</code>, <code dir="auto">&quot;Embedded single quotes &#39;text&#39;&quot;</code>, <code dir="auto">&#39;Embedded double quotes &quot;text&quot;&#39;</code></li> </ul> <p>Our <a href="/pine-script-docs/writing/style-guide/">Style guide</a> recommends using uppercase SNAKE_CASE to name “const” variables for readability. While not a requirement, one can also use the <a href="https://www.tradingview.com/pine-script-reference/v6/#kw_var">var</a> keyword when declaring “const” variables so the script only initializes them on the <em>first bar</em> of the dataset. See <a href="/pine-script-docs/language/variable-declarations/#var">this section</a> of our User Manual for more information.</p> <p>Below is an example that uses “const” values within the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_indicator">indicator()</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_plot">plot()</a> functions, which both require a value of the “const string” qualified type as their <code dir="auto">title</code> argument:</p> <div class="pine-colorizer not-content">//@version=6 // The following global variables are all of the &quot;const string&quot; qualified type: //@variable The title of the indicator. INDICATOR_TITLE = &quot;const demo&quot; //@variable The title of the first plot. var PLOT1_TITLE = &quot;High&quot; //@variable The title of the second plot. const string PLOT2_TITLE = &quot;Low&quot; //@variable The title of the third plot. PLOT3_TITLE = &quot;Midpoint between &quot; + PLOT1_TITLE + &quot; and &quot; + PLOT2_TITLE indicator(INDICATOR_TITLE, overlay = true) plot(high, PLOT1_TITLE) plot(low, PLOT2_TITLE) plot(hl2, PLOT3_TITLE)</div> <p>The following example will raise a compilation error since it uses <a href="https://www.tradingview.com/pine-script-reference/v6/#var_syminfo.ticker">syminfo.ticker</a>, which returns a “simple” value because it depends on chart information that’s only accessible after the script’s first execution:</p> <div class="pine-colorizer not-content">//@version=6 //@variable The title in the `indicator()` call. var NAME = &quot;My indicator for &quot; + syminfo.ticker indicator(NAME, &quot;&quot;, true) // Causes an error because `NAME` is qualified as a &quot;simple string&quot;. plot(close)</div> <p>The <a href="https://www.tradingview.com/pine-script-reference/v6/#type_const">const</a> keyword allows the declaration of variables and parameters with constant <em>value assignments</em>. Declaring a variable with this keyword instructs the script to forbid using <em>reassignment</em> and <em>compound assignment</em> operations on it. For example, this script declares the <code dir="auto">myVar</code> variable with the keyword, then attempts to assign a new “float” value to the variable with the addition assignment operator (<a href="https://www.tradingview.com/pine-script-reference/v6/#op_+=">+=</a>), resulting in a compilation error:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Cannot reassign const demo&quot;) //@variable A &quot;float&quot; variable declared as `const`, preventing reassignment. const float myVar = 0.0 myVar += 1.0 // Causes an error. Reassignment and compound assignments are not allowed on `const` variables. plot(myVar)</div> <p>It’s crucial to note that declaring a variable with the <a href="https://www.tradingview.com/pine-script-reference/v6/#type_const">const</a> keyword forces it to maintain a constant reference to the value returned by a specific expression, but that <em>does not</em> necessarily define the nature of the assigned value. For example, a script can declare a <a href="https://www.tradingview.com/pine-script-reference/v6/#type_const">const</a> variable that maintains a constant reference to an expression returning the <em>ID</em> of a <em>special type</em>. Although the script cannot <em>reassign</em> the variable, the assigned ID is a “series” value:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Constant reference to &#39;series&#39; ID demo&quot;) //@variable A `label` variable declared as `const`, preventing reassignment. // Although the reference is constant, the ID of the `label` is a &quot;series&quot; value. const label myVar = label.new(bar_index, close)</div> <h3 id="input" class="md-heading"><a href="#input">input<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Most values qualified as “input” are established after initialization via the <code dir="auto">input.*()</code> functions. These functions produce values that users can modify within the “Inputs” tab of the script’s settings. When one changes any of the values in this tab, the script <em>restarts</em> from the beginning of the chart’s history to ensure its inputs are consistent throughout its executions. Some of Pine’s built-in variables, such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_chart.bg_color">chart.bg_color</a> also use the “input” qualifier, even though <code dir="auto">input.*()</code> functions do not return them, since the script receives their values at <em>input time</em>.</p> <aside aria-label="Notice!" class="tv-informer not-content" style="--informer-header-color:#FF9800;--informer-back-color-light:#FFF3E0;--informer-back-color-dark:#33261A"><div class="tv-informer-icon"><svg viewBox="0 0 18 18" width="18" height="18"><path fill-rule="evenodd" d="M9 17A8 8 0 1 0 9 1a8 8 0 0 0 0 16ZM9 4c-.79 0-1.38.7-1.25 1.48l.67 4.03a.59.59 0 0 0 1.16 0l.67-4.03A1.27 1.27 0 0 0 9 4Zm0 8a1 1 0 1 0 0 2 1 1 0 0 0 0-2Z" fill="currentColor"></path></svg></div><div class="tv-informer-content"><p><span class="tv-informer-header">Notice!</span>The <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.source">input.source()</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.enum">input.enum()</a> functions are exceptions in the <code dir="auto">input.*()</code> namespace, as they <em>do not</em> return values qualified as “input”. The <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.source">input.source()</a> function returns “series” values since built-in variables such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_open">open</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_close">close</a>, as well as the values from another script’s plots, have the “series” qualifier. The <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.enum">input.enum()</a> function returns a “simple” result because all values belonging to <a href="/pine-script-docs/language/type-system/#types">enums</a> are available on the first script execution. See this manual’s <a href="/pine-script-docs/concepts/inputs/">Inputs</a> page for more information.</p></div></aside> <p>The following script plots the value of a <code dir="auto">sourceInput</code> from the <code dir="auto">symbolInput</code> and <code dir="auto">timeframeInput</code> context. The <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_request.security">request.security()</a> call is valid in this script since its <code dir="auto">symbol</code> and <code dir="auto">timeframe</code> parameters allow “simple string” arguments, meaning they can also accept “input string” values because the “input” qualifier is <em>lower</em> on the hierarchy:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;input demo&quot;, overlay = true) //@variable The symbol to request data from. Qualified as &quot;input string&quot;. symbolInput = input.symbol(&quot;AAPL&quot;, &quot;Symbol&quot;) //@variable The timeframe of the data request. Qualified as &quot;input string&quot;. timeframeInput = input.timeframe(&quot;D&quot;, &quot;Timeframe&quot;) //@variable The source of the calculation. Qualified as &quot;series float&quot;. sourceInput = input.source(close, &quot;Source&quot;) //@variable The `sourceInput` value from the requested context. Qualified as &quot;series float&quot;. requestedSource = request.security(symbolInput, timeframeInput, sourceInput) plot(requestedSource)</div> <h3 id="simple" class="md-heading"><a href="#simple">simple<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Values qualified as “simple” are available on the first script execution, and they remain consistent across subsequent executions.</p> <p>Users can explicitly define variables and parameters that accept “simple” values by including the <code dir="auto">simple</code> keyword in their declaration.</p> <p>Many built-in variables return “simple” qualified values because they depend on information that a script can only obtain once it starts running on the chart. Additionally, many built-in functions require “simple” arguments that do not change over time. Wherever a script allows “simple” values, it can also accept values qualified as “input” or “const”.</p> <p>This script highlights the background to warn users that they’re using a non-standard chart type. It uses the value of <a href="https://www.tradingview.com/pine-script-reference/v6/#var_chart.is_standard">chart.is_standard</a> to calculate the <code dir="auto">isNonStandard</code> variable, then uses that variable’s value to calculate a <code dir="auto">warningColor</code> that also references a “simple” value. The <code dir="auto">color</code> parameter of <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_bgcolor">bgcolor()</a> allows a “series color” argument, meaning it can also accept a “simple color” value since “simple” is lower on the hierarchy:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;simple demo&quot;, overlay = true) //@variable Is `true` when the current chart is non-standard. Qualified as &quot;simple bool&quot;. isNonStandard = not chart.is_standard //@variable Is orange when the the current chart is non-standard. Qualified as &quot;simple color&quot;. simple color warningColor = isNonStandard ? color.new(color.orange, 70) : na // Colors the chart&#39;s background to warn that it&#39;s a non-standard chart type. bgcolor(warningColor, title = &quot;Non-standard chart color&quot;)</div> <h3 id="series" class="md-heading"><a href="#series">series<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Values qualified as “series” provide the most flexibility in scripts since they can change across executions.</p> <p>Users can explicitly define variables and parameters that accept “series” values by including the <code dir="auto">series</code> keyword in their declarations.</p> <p>Built-in variables such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_open">open</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_high">high</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_low">low</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_close">close</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_volume">volume</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_time">time</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_bar_index">bar_index</a>, and the result from any expression using such built-ins, are qualified as “series”. The result of any function or operation that returns a dynamic value will always be a “series”, as will the results from using the history-referencing operator <a href="https://www.tradingview.com/pine-script-reference/v6/#op_%5B%5D">[]</a> to access historical values. Wherever a script allows “series” values, it will also accept values with any other qualifier, as “series” is the <em>highest</em> qualifier on the hierarchy.</p> <p>This script displays the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_ta.highest">highest</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_ta.lowest">lowest</a> value of a <code dir="auto">sourceInput</code> over <code dir="auto">lengthInput</code> bars. The values assigned to the <code dir="auto">highest</code> and <code dir="auto">lowest</code> variables are of the “series float” qualified type, as they can change throughout the script’s execution:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;series demo&quot;, overlay = true) //@variable The source value to calculate on. Qualified as &quot;series float&quot;. series float sourceInput = input.source(close, &quot;Source&quot;) //@variable The number of bars in the calculation. Qualified as &quot;input int&quot;. lengthInput = input.int(20, &quot;Length&quot;) //@variable The highest `sourceInput` value over `lengthInput` bars. Qualified as &quot;series float&quot;. series float highest = ta.highest(sourceInput, lengthInput) //@variable The lowest `sourceInput` value over `lengthInput` bars. Qualified as &quot;series float&quot;. lowest = ta.lowest(sourceInput, lengthInput) plot(highest, &quot;Highest source&quot;, color.green) plot(lowest, &quot;Lowest source&quot;, color.red)</div> <h2 id="types" class="md-heading"><a href="#types">Types<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h2> <p>Pine Script™ <em>types</em> classify values and determine the functions and operations they’re compatible with. They include:</p> <ul> <li>The fundamental types: <a href="/pine-script-docs/language/type-system/#int">int</a>, <a href="/pine-script-docs/language/type-system/#float">float</a>, <a href="/pine-script-docs/language/type-system/#bool">bool</a>, <a href="/pine-script-docs/language/type-system/#color">color</a>, and <a href="/pine-script-docs/language/type-system/#string">string</a></li> <li>The special types: <a href="/pine-script-docs/language/type-system/#plot-and-hline">plot</a>, <a href="/pine-script-docs/language/type-system/#plot-and-hline">hline</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">line</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">linefill</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">box</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">polyline</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">label</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">table</a>, <a href="/pine-script-docs/language/type-system/#chart-points">chart.point</a>, <a href="/pine-script-docs/language/type-system/#collections">array</a>, <a href="/pine-script-docs/language/type-system/#collections">matrix</a>, and <a href="/pine-script-docs/language/type-system/#collections">map</a></li> <li><a href="/pine-script-docs/language/type-system/#user-defined-types">User-defined types (UDTs)</a></li> <li><a href="/pine-script-docs/language/type-system/#enum-types">Enums</a></li> <li><a href="/pine-script-docs/language/type-system/#void">void</a></li> </ul> <p>Fundamental types refer to the underlying nature of a value, e.g., a value of 1 is of the “int” type, 1.0 is of the “float” type, “AAPL” is of the “string” type, etc. Special types and user-defined types utilize <em>IDs</em> that refer to objects of a specific type. For example, a value of the “label” type contains an ID that acts as a <em>pointer</em> referring to a “label” object. The “void” type refers to the output from a function or <a href="/pine-script-docs/language/methods/">method</a> that does not return a usable value.</p> <p>Pine Script™ can automatically convert values from some types into others. The auto-casting rules are: <strong>int → float → bool</strong>. See the <a href="/pine-script-docs/language/type-system/#type-casting">Type casting</a> section of this page for more information.</p> <p>In most cases, Pine Script™ can automatically determine a value’s type. However, we can also use type keywords to <em>explicitly</em> specify types for readability and for code that requires explicit definitions (e.g., declaring a variable assigned to <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>). For example:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Types demo&quot;, overlay = true) //@variable A value of the &quot;const string&quot; type for the `ma` plot&#39;s title. string MA_TITLE = &quot;MA&quot; //@variable A value of the &quot;input int&quot; type. Controls the length of the average. int lengthInput = input.int(100, &quot;Length&quot;, minval = 2) //@variable A &quot;series float&quot; value representing the last `close` that crossed over the `ma`. var float crossValue = na //@variable A &quot;series float&quot; value representing the moving average of `close`. float ma = ta.sma(close, lengthInput) //@variable A &quot;series bool&quot; value that&#39;s `true` when the `close` crosses over the `ma`. bool crossUp = ta.crossover(close, ma) //@variable A &quot;series color&quot; value based on whether `close` is above or below its `ma`. color maColor = close &gt; ma ? color.lime : color.fuchsia // Update the `crossValue`. if crossUp crossValue := close plot(ma, MA_TITLE, maColor) plot(crossValue, &quot;Cross value&quot;, style = plot.style_circles) plotchar(crossUp, &quot;Cross Up&quot;, &quot;▲&quot;, location.belowbar, size = size.small)</div> <h3 id="int" class="md-heading"><a href="#int">int<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Values of the “int” type represent integers, i.e., whole numbers without any fractional quantities.</p> <p>Integer literals are numeric values written in <em>decimal</em> notation. For example:</p> <div class="pine-colorizer not-content">1 -1 750</div> <p>Built-in variables such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_bar_index">bar_index</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_time">time</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_timenow">timenow</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_dayofmonth">dayofmonth</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_strategy.wintrades">strategy.wintrades</a> all return values of the “int” type.</p> <h3 id="float" class="md-heading"><a href="#float">float<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Values of the “float” type represent floating-point numbers, i.e., numbers that can contain whole and fractional quantities.</p> <p>Floating-point literals are numeric values written with a <code dir="auto">.</code> delimiter. They may also contain the symbol <code dir="auto">e</code> or <code dir="auto">E</code> (which means “10 raised to the power of X”, where X is the number after the <code dir="auto">e</code> or <code dir="auto">E</code> symbol). For example:</p> <div class="pine-colorizer not-content">3.14159 // Rounded value of Pi (π) - 3.0 6.02e23 // 6.02 * 10^23 (a very large value) 1.6e-19 // 1.6 * 10^-19 (a very small value)</div> <p>The internal precision of “float” values in Pine Script™ is 1e-16.</p> <p>Built-in variables such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_close">close</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_hlcc4">hlcc4</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_volume">volume</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_ta.vwap">ta.vwap</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_strategy.position_size">strategy.position_size</a> all return values of the “float” type.</p> <h3 id="bool" class="md-heading"><a href="#bool">bool<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Values of the “bool” type represent the truth value of a comparison or condition, which scripts can use in <a href="/pine-script-docs/language/conditional-structures/">conditional structures</a> and other expressions.</p> <p>There are only two literals that represent boolean values:</p> <div class="pine-colorizer not-content">true // true value false // false value</div> <p>A <code dir="auto">bool</code> variable can never be <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>, and any <a href="/pine-script-docs/language/conditional-structures">conditional structure</a> that can return <code dir="auto">na</code> will return <code dir="auto">false</code> instead. For example, an <a href="https://www.tradingview.com/pine-script-reference/v6/#kw_if">if</a> condition returns <code dir="auto">bool</code> values, when the condition is not met and the <code dir="auto">else</code> block is not specified, it will returns <code dir="auto">false</code>.</p> <p>Built-in variables such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_barstate.isfirst">barstate.isfirst</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_chart.is_heikinashi">chart.is_heikinashi</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_session.ismarket">session.ismarket</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_timeframe.isdaily">timeframe.isdaily</a> all return values of the “bool” type.</p> <h3 id="color" class="md-heading"><a href="#color">color<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Color literals have the following format: <code dir="auto">#RRGGBB</code> or <code dir="auto">#RRGGBBAA</code>. The letter pairs represent <em>hexadecimal</em> values between <code dir="auto">00</code> and <code dir="auto">FF</code> (0 to 255 in decimal) where:</p> <ul> <li><code dir="auto">RR</code>, <code dir="auto">GG</code> and <code dir="auto">BB</code> pairs respectively represent the values for the color’s red, green and blue components.</li> <li><code dir="auto">AA</code> is an optional value for the color’s opacity (or <em>alpha</em> component) where <code dir="auto">00</code> is invisible and <code dir="auto">FF</code> opaque. When the literal does not include an <code dir="auto">AA</code> pair, the script treats it as fully opaque (the same as using <code dir="auto">FF</code>).</li> <li>The hexadecimal letters in the literals can be uppercase or lowercase.</li> </ul> <p>These are examples of “color” literals:</p> <div class="pine-colorizer not-content">#000000 // black color #FF0000 // red color #00FF00 // green color #0000FF // blue color #FFFFFF // white color #808080 // gray color #3ff7a0 // some custom color #FF000080 // 50% transparent red color #FF0000ff // same as #FF0000, fully opaque red color #FF000000 // completely transparent red color</div> <p>Pine Script™ also has <a href="/pine-script-docs/concepts/colors/#constant-colors">built-in color constants</a>, including <a href="https://www.tradingview.com/pine-script-reference/v6/#const_color%7Bdot%7Dgreen">color.green</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#const_color%7Bdot%7Dred">color.red</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#const_color%7Bdot%7Dorange">color.orange</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#const_color%7Bdot%7Dblue">color.blue</a> (the default color in <code dir="auto">plot*()</code> functions and many of the default color-related properties in <a href="/pine-script-docs/language/type-system/#drawing-types">drawing types</a>), etc.</p> <p>When using built-in color constants, it is possible to add transparency information to them via the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_color.new">color.new()</a> function.</p> <p>Note that when specifying red, green or blue components in <code dir="auto">color.*()</code> functions, we use “int” or “float” arguments with values between 0 and 255. When specifying transparency, we use a value between 0 and 100, where 0 means fully opaque and 100 means completely transparent. For example:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Shading the chart&#39;s background&quot;, overlay = true) //@variable A &quot;const color&quot; value representing the base for each day&#39;s color. color BASE_COLOR = color.rgb(0, 99, 165) //@variable A &quot;series int&quot; value that modifies the transparency of the `BASE_COLOR` in `color.new()`. int transparency = 50 + int(40 * dayofweek / 7) // Color the background using the modified `BASE_COLOR`. bgcolor(color.new(BASE_COLOR, transparency))</div> <p>See the User Manual’s page on <a href="/pine-script-docs/concepts/colors/">colors</a> for more information on using colors in scripts.</p> <h3 id="string" class="md-heading"><a href="#string">string<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Values of the “string” type represent sequences of letters, numbers, symbols, spaces, and other characters.</p> <p>String literals in Pine are characters enclosed in single or double quotation marks. For example:</p> <div class="pine-colorizer not-content">&quot;This is a string literal using double quotes.&quot; &#39;This is a string literal using single quotes.&#39;</div> <p>Single and double quotation marks are functionally equivalent in Pine Script™. A “string” enclosed within double quotation marks can contain any number of single quotation marks and vice versa:</p> <div class="pine-colorizer not-content">&quot;It&#39;s an example&quot; &#39;The &quot;Star&quot; indicator&#39;</div> <p>Scripts can <em>escape</em> the enclosing delimiter in a “string” using the backslash character (<code dir="auto">\</code>). For example:</p> <div class="pine-colorizer not-content">&#39;It\&#39;s an example&#39; &quot;The \&quot;Star\&quot; indicator&quot;</div> <p>We can create “string” values containing the new line escape character (<code dir="auto">\n</code>) for displaying multi-line text with <code dir="auto">plot*()</code> and <code dir="auto">log.*()</code> functions and objects of <a href="/pine-script-docs/language/type-system/#drawing-types">drawing types</a>. For example:</p> <div class="pine-colorizer not-content">&quot;This\nString\nHas\nOne\nWord\nPer\nLine&quot;</div> <p>We can use the <a href="https://www.tradingview.com/pine-script-reference/v6/#op_+">+</a> operator to concatenate “string” values:</p> <div class="pine-colorizer not-content">&quot;This is a &quot; + &quot;concatenated string.&quot;</div> <p>The built-ins in the <code dir="auto">str.*()</code> namespace create “string” values using specialized operations. For instance, this script creates a <em>formatted string</em> to represent “float” price values and displays the result using a label:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Formatted string demo&quot;, overlay = true) //@variable A &quot;series string&quot; value representing the bar&#39;s OHLC data. string ohlcString = str.format(&quot;Open: {0}\nHigh: {1}\nLow: {2}\nClose: {3}&quot;, open, high, low, close) // Draw a label containing the `ohlcString`. label.new(bar_index, high, ohlcString, textcolor = color.white)</div> <p>See our User Manual’s page on <a href="/pine-script-docs/concepts/text-and-shapes/">Text and shapes</a> for more information about displaying “string” values from a script.</p> <p>Built-in variables such as <a href="https://www.tradingview.com/pine-script-reference/v6/#var_syminfo.tickerid">syminfo.tickerid</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#var_syminfo.currency">syminfo.currency</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_timeframe.period">timeframe.period</a> return values of the “string” type.</p> <h3 id="plot-and-hline" class="md-heading"><a href="#plot-and-hline">plot and hline<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Pine Script™‘s <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_plot">plot()</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_hline">hline()</a> functions return IDs that respectively reference instances of the “plot” and “hline” types. These types display calculated values and horizontal levels on the chart, and one can assign their IDs to variables for use with the built-in <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_fill">fill()</a> function.</p> <p>For example, this script plots two EMAs on the chart and fills the space between them using a <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_fill">fill()</a> call:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;plot fill demo&quot;, overlay = true) //@variable A &quot;series float&quot; value representing a 10-bar EMA of `close`. float emaFast = ta.ema(close, 10) //@variable A &quot;series float&quot; value representing a 20-bar EMA of `close`. float emaSlow = ta.ema(close, 20) //@variable The plot of the `emaFast` value. emaFastPlot = plot(emaFast, &quot;Fast EMA&quot;, color.orange, 3) //@variable The plot of the `emaSlow` value. emaSlowPlot = plot(emaSlow, &quot;Slow EMA&quot;, color.gray, 3) // Fill the space between the `emaFastPlot` and `emaSlowPlot`. fill(emaFastPlot, emaSlowPlot, color.new(color.purple, 50), &quot;EMA Fill&quot;)</div> <p>It’s important to note that unlike other special types, there is no <code dir="auto">plot</code> or <code dir="auto">hline</code> keyword in Pine to explicitly declare a variable’s type as “plot” or “hline”.</p> <p>Users can control where their scripts’ plots display via the variables in the <code dir="auto">display.*</code> namespace and a <code dir="auto">plot*()</code> function’s <code dir="auto">force_overlay</code> parameter. Additionally, one script can use the values from another script’s plots as <em>external inputs</em> via the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.source">input.source()</a> function (see our User Manual’s section on <a href="/pine-script-docs/concepts/inputs/#source-input">source inputs</a>).</p> <h3 id="drawing-types" class="md-heading"><a href="#drawing-types">Drawing types<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Pine Script™ drawing types allow scripts to create custom drawings on charts. They include the following: <a href="https://www.tradingview.com/pine-script-reference/v6/#type_line">line</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#type_linefill">linefill</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#type_box">box</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#type_polyline">polyline</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#type_label">label</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#type_table">table</a>.</p> <p>Each type also has a namespace containing all the built-ins that create and manage drawing instances. For example, the following <code dir="auto">*.new()</code> constructors create new objects of these types in a script: <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_line.new">line.new()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_linefill.new">linefill.new()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_box.new">box.new()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_polyline.new">polyline.new()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_label.new">label.new()</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_table.new">table.new()</a>.</p> <p>Each of these functions returns an <em>ID</em> which is a reference that uniquely identifies a drawing object. IDs are always qualified as “series”, meaning their qualified types are “series line”, “series label”, etc. Drawing IDs act like pointers, as each ID references a specific instance of a drawing in all the functions from that drawing’s namespace. For instance, the ID of a line returned by a <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_line.new">line.new()</a> call is used later to refer to that specific object once it’s time to delete it with <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_line.delete">line.delete()</a>.</p> <h3 id="chart-points" class="md-heading"><a href="#chart-points">Chart points<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Chart points are special types that represent coordinates on the chart. Scripts use the information from <a href="https://www.tradingview.com/pine-script-reference/v6/#type_chart.point">chart.point</a> objects to determine the chart locations of <a href="/pine-script-docs/concepts/lines-and-boxes/#lines">lines</a>, <a href="/pine-script-docs/concepts/lines-and-boxes/#boxes">boxes</a>, <a href="/pine-script-docs/concepts/lines-and-boxes/#polylines">polylines</a>, and <a href="/pine-script-docs/concepts/text-and-shapes/#labels">labels</a>.</p> <p>Objects of this type contain three <em>fields</em>: <code dir="auto">time</code>, <code dir="auto">index</code>, and <code dir="auto">price</code>. Whether a drawing instance uses the <code dir="auto">time</code> or <code dir="auto">price</code> field from a <a href="https://www.tradingview.com/pine-script-reference/v6/#type_chart.point">chart.point</a> as an x-coordinate depends on the drawing’s <code dir="auto">xloc</code> property.</p> <p>We can use any of the following functions to create chart points in a script:</p> <ul> <li><a href="https://www.tradingview.com/pine-script-reference/v6/#fun_chart.point.new">chart.point.new()</a> - Creates a new <a href="https://www.tradingview.com/pine-script-reference/v6/#type_chart.point">chart.point</a> with a specified <code dir="auto">time</code>, <code dir="auto">index</code>, and <code dir="auto">price</code>.</li> <li><a href="https://www.tradingview.com/pine-script-reference/v6/#fun_chart.point.now">chart.point.now()</a> - Creates a new <a href="https://www.tradingview.com/pine-script-reference/v6/#type_chart.point">chart.point</a> with a specified <code dir="auto">price</code> y-coordinate. The <code dir="auto">time</code> and <code dir="auto">index</code> fields contain the <a href="https://www.tradingview.com/pine-script-reference/v6/#var_time">time</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#var_bar_index">bar_index</a> of the bar the function executes on.</li> <li><a href="https://www.tradingview.com/pine-script-reference/v6/#fun_chart.point.from_index">chart.point_from_index()</a> - Creates a new <a href="https://www.tradingview.com/pine-script-reference/v6/#type_chart.point">chart.point</a> with an <code dir="auto">index</code> x-coordinate and <code dir="auto">price</code> y-coordinate. The <code dir="auto">time</code> field of the resulting instance is <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>, meaning it will not work with drawing objects that use an <code dir="auto">xloc</code> value of <a href="https://www.tradingview.com/pine-script-reference/v6/#var_xloc.bar_time">xloc.bar_time</a>.</li> <li><a href="https://www.tradingview.com/pine-script-reference/v6/#fun_chart.point.from_time">chart.point.from_time()</a> - Creates a new <a href="https://www.tradingview.com/pine-script-reference/v6/#type_chart.point">chart.point</a> with a <code dir="auto">time</code> x-coordinate and <code dir="auto">price</code> y-coordinate. The <code dir="auto">index</code> field of the resulting instance is <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>, meaning it will not work with drawing objects that use an <code dir="auto">xloc</code> value of <a href="https://www.tradingview.com/pine-script-reference/v6/#var_xloc.bar_index">xloc.bar_index</a>.</li> <li><a href="https://www.tradingview.com/pine-script-reference/v6/#fun_chart.point.copy">chart.point.copy()</a> - Creates a new <a href="https://www.tradingview.com/pine-script-reference/v6/#type_chart.point">chart.point</a> containing the same <code dir="auto">time</code>, <code dir="auto">index</code>, and <code dir="auto">price</code> information as the <code dir="auto">id</code> in the function call.</li> </ul> <p>This example draws lines connecting the previous bar’s <a href="https://www.tradingview.com/pine-script-reference/v6/#var_high">high</a> to the current bar’s <a href="https://www.tradingview.com/pine-script-reference/v6/#var_low">low</a> on each chart bar. It also displays labels at both points of each line. The line and labels get their information from the <code dir="auto">firstPoint</code> and <code dir="auto">secondPoint</code> variables, which reference chart points created using <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_chart.point.from_index">chart.point_from_index()</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_chart.point.now">chart.point.now()</a>:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Chart points demo&quot;, overlay = true) //@variable A new `chart.point` at the previous `bar_index` and `high`. firstPoint = chart.point.from_index(bar_index - 1, high[1]) //@variable A new `chart.point` at the current bar&#39;s `low`. secondPoint = chart.point.now(low) // Draw a new line connecting coordinates from the `firstPoint` and `secondPoint`. // This line uses the `index` fields from the points as x-coordinates. line.new(firstPoint, secondPoint, color = color.purple, width = 3) // Draw a label at the `firstPoint`. Uses the point&#39;s `index` field as its x-coordinate. label.new( firstPoint, str.tostring(firstPoint.price), color = color.green, style = label.style_label_down, textcolor = color.white ) // Draw a label at the `secondPoint`. Uses the point&#39;s `index` field as its x-coordinate. label.new( secondPoint, str.tostring(secondPoint.price), color = color.red, style = label.style_label_up, textcolor = color.white )</div> <h3 id="collections" class="md-heading"><a href="#collections">Collections<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>Collections in Pine Script™ (<a href="/pine-script-docs/language/arrays/">arrays</a>, <a href="/pine-script-docs/language/matrices/">matrices</a>, and <a href="/pine-script-docs/language/maps/">maps</a>) utilize reference IDs, much like other special types (e.g., labels). The type of the ID defines the type of <em>elements</em> the collection will contain. In Pine, we specify array, matrix, and map types by appending a <a href="/pine-script-docs/language/type-system/#type-templates">type template</a> to the <a href="https://www.tradingview.com/pine-script-reference/v6/#type_array">array</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#type_matrix">matrix</a>, or <a href="https://www.tradingview.com/pine-script-reference/v6/#type_map">map</a> keywords:</p> <ul> <li><code dir="auto">array&lt;int&gt;</code> defines an array containing “int” elements.</li> <li><code dir="auto">array&lt;label&gt;</code> defines an array containing “label” IDs.</li> <li><code dir="auto">array&lt;UDT&gt;</code> defines an array containing IDs referencing objects of a <a href="/pine-script-docs/language/type-system/#user-defined-types">user-defined type (UDT)</a>.</li> <li><code dir="auto">matrix&lt;float&gt;</code> defines a matrix containing “float” elements.</li> <li><code dir="auto">matrix&lt;UDT&gt;</code> defines a matrix containing IDs referencing objects of a <a href="/pine-script-docs/language/type-system/#user-defined-types">user-defined type (UDT)</a>.</li> <li><code dir="auto">map&lt;string, float&gt;</code> defines a map containing “string” keys and “float” values.</li> <li><code dir="auto">map&lt;int, UDT&gt;</code> defines a map containing “int” keys and IDs of <a href="/pine-script-docs/language/type-system/#user-defined-types">user-defined type (UDT)</a> instances as values.</li> </ul> <p>For example, one can declare an “int” array with a single element value of 10 in any of the following, equivalent ways:</p> <div class="pine-colorizer not-content">a1 = array.new&lt;int&gt;(1, 10) array&lt;int&gt; a2 = array.new&lt;int&gt;(1, 10) a3 = array.from(10) array&lt;int&gt; a4 = array.from(10)</div> <p>Note that:</p> <ul> <li>The <code dir="auto">int[]</code> syntax can also specify an array of “int” elements, but its use is discouraged. No equivalent exists to specify the types of matrices or maps in that way.</li> <li>Type-specific built-ins exist for arrays, such as <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_array%7Bdot%7Dnew_int">array.new_int()</a>, but the more generic <a href="https://www.tradingview.com/pine-script-reference/v6/#type_array">array.new&lt;type&gt;</a> form is preferred, which would be <code dir="auto">array.new&lt;int&gt;()</code> to create an array of “int” elements.</li> </ul> <h3 id="user-defined-types" class="md-heading"><a href="#user-defined-types">User-defined types<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>The <a href="https://www.tradingview.com/pine-script-reference/v6/#kw_type">type</a> keyword allows the creation of <em>user-defined types</em> (UDTs) from which scripts can create <a href="/pine-script-docs/language/objects/">objects</a>. UDTs are composite types; they contain an arbitrary number of <em>fields</em> that can be of any type, including other user-defined types.</p> <p>The syntax to declare a user-defined type is:</p> <div class="expressive-code not-content"><link rel="stylesheet" href="/pine-script-docs/_astro/ec.dtidy.css"/><script type="module" src="/pine-script-docs/_astro/ec.qopfj.js"></script><figure class="frame"><figcaption class="header"></figcaption><pre data-language="text"><code><div class="ec-line"><div class="code"><span style="--0:#e1e4e8;--1:#24292e">[export ]type &lt;UDT_identifier&gt;</span></div></div><div class="ec-line"><div class="code"><span class="indent"><span style="--0:#e1e4e8;--1:#24292e"> </span></span><span style="--0:#e1e4e8;--1:#24292e">&lt;field_type&gt; &lt;field_name&gt;[ = &lt;value&gt;]</span></div></div><div class="ec-line"><div class="code"><span class="indent"><span style="--0:#e1e4e8;--1:#24292e"> </span></span><span style="--0:#e1e4e8;--1:#24292e">...</span></div></div></code></pre></figure></div> <p>where:</p> <ul> <li><a href="https://www.tradingview.com/pine-script-reference/v6/#kw_export">export</a> is the keyword that a <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_library">library</a> script uses to export the user-defined type. To learn more about exporting UDTs, see our User Manual’s <a href="/pine-script-docs/concepts/libraries/#user-defined-types-and-objects">Libraries</a> page.</li> <li><code dir="auto">&lt;UDT_identifier&gt;</code> is the name of the user-defined type.</li> <li><code dir="auto">&lt;field_type&gt;</code> is the type of the field.</li> <li><code dir="auto">&lt;field_name&gt;</code> is the name of the field.</li> <li><code dir="auto">&lt;value&gt;</code> is an optional default value for the field, which the script will assign to it when creating new objects of that UDT. If one does not provide a value, the field’s default is <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>. The same rules as those governing the default values of parameters in function signatures apply to the default values of fields. For example, a UDT’s default values cannot use results from the history-referencing operator <a href="https://www.tradingview.com/pine-script-reference/v6/#op_%5B%5D">[]</a> or expressions.</li> </ul> <p>This example declares a <code dir="auto">pivotPoint</code> UDT with an “int” <code dir="auto">pivotTime</code> field and a “float” <code dir="auto">priceLevel</code> field that will respectively hold time and price information about a calculated pivot:</p> <div class="pine-colorizer not-content"> //@type A user-defined type containing pivot information. //@field pivotTime Contains time information about the pivot. //@field priceLevel Contains price information about the pivot. type pivotPoint int pivotTime float priceLevel</div> <p>User-defined types support <em>type recursion</em>, i.e., the fields of a UDT can reference objects of the same UDT. Here, we’ve added a <code dir="auto">nextPivot</code> field to our previous <code dir="auto">pivotPoint</code> type that references another <code dir="auto">pivotPoint</code> instance:</p> <div class="pine-colorizer not-content"> //@type A user-defined type containing pivot information. //@field pivotTime Contains time information about the pivot. //@field priceLevel Contains price information about the pivot. //@field nextPivot A `pivotPoint` instance containing additional pivot information. type pivotPoint int pivotTime float priceLevel pivotPoint nextPivot</div> <p>Scripts can use two built-in methods to create and copy UDTs: <code dir="auto">new()</code> and <code dir="auto">copy()</code>. See our User Manual’s page on <a href="/pine-script-docs/language/objects/">Objects</a> to learn more about working with UDTs.</p> <h3 id="enum-types" class="md-heading"><a href="#enum-types">Enum types<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>The <a href="https://www.tradingview.com/pine-script-reference/v6/#kw_enum">enum</a> keyword allows the creation of an <em>enum</em>, otherwise known as an <em>enumeration</em>, <em>enumerated type</em>, or <em>enum type</em>. An enum is a unique type construct containing distinct, named fields representing <em>members</em> (i.e., possible values) of the type. Enums allow programmers to control the values accepted by variables, conditional expressions, and <a href="/pine-script-docs/language/type-system/#collections">collections</a>, and they facilitate convenient dropdown <a href="/pine-script-docs/concepts/inputs/#enum-input">input</a> creation with the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.enum">input.enum()</a> function.</p> <p>The syntax to declare an enum is as follows:</p> <div class="expressive-code not-content"><figure class="frame"><figcaption class="header"></figcaption><pre data-language="text"><code><div class="ec-line"><div class="code"><span style="--0:#e1e4e8;--1:#24292e">[export ]enum &lt;enumName&gt;</span></div></div><div class="ec-line"><div class="code"><span class="indent"><span style="--0:#e1e4e8;--1:#24292e"> </span></span><span style="--0:#e1e4e8;--1:#24292e">&lt;field_1&gt;[ = &lt;title_1&gt;]</span></div></div><div class="ec-line"><div class="code"><span class="indent"><span style="--0:#e1e4e8;--1:#24292e"> </span></span><span style="--0:#e1e4e8;--1:#24292e">&lt;field_2&gt;[ = &lt;title_2&gt;]</span></div></div><div class="ec-line"><div class="code"><span class="indent"><span style="--0:#e1e4e8;--1:#24292e"> </span></span><span style="--0:#e1e4e8;--1:#24292e">...</span></div></div><div class="ec-line"><div class="code"><span class="indent"><span style="--0:#e1e4e8;--1:#24292e"> </span></span><span style="--0:#e1e4e8;--1:#24292e">&lt;field_N&gt;[ = &lt;title_N&gt;]</span></div></div></code></pre></figure></div> <p>where:</p> <ul> <li><a href="https://www.tradingview.com/pine-script-reference/v6/#kw_export">export</a> is the optional keyword allowing a <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_library">library</a> to export the enum for use in other scripts. See <a href="/pine-script-docs/concepts/libraries/#enum-types">this section</a> to learn more about exporting enum types.</li> <li><code dir="auto">&lt;enumName&gt;</code> is the name of the enum type. Scripts can use the enum’s name as the type keyword in <a href="/pine-script-docs/language/variable-declarations/">variable declarations</a> and <a href="/pine-script-docs/language/type-system/#type-templates">type templates</a>.</li> <li><code dir="auto">&lt;field_*&gt;</code> is the name of an enum field, representing a named member (value) of the <code dir="auto">enumName</code> type. Each field must have a unique name that does not match the name or title of any other field in the enum. To retrieve an enum member, reference its field name using dot notation syntax (i.e., <code dir="auto">enumName.fieldName</code>).</li> <li><code dir="auto">&lt;title_*&gt;</code> is a “const string” title assigned to a field. If one does not specify a title, the field’s title is the “string” representation of its name. The <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.enum">input.enum()</a> function displays field titles within its dropdown in the script’s “Settings/Inputs” tab. Users can also retrieve a field’s title with the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_str.tostring">str.tostring()</a> function. As with field names, each field’s title must not match the name or title of any other field in the enum.</li> </ul> <p>This example declares an <code dir="auto">maChoice</code> enum. Each field within this declaration represents a distinct member of the <code dir="auto">maChoice</code> enum type:</p> <div class="pine-colorizer not-content">//@enum An enumeration of named values for moving average selection. //@field sma Selects a Simple Moving Average. //@field ema Selects an Exponential Moving Average. //@field wma Selects a Weighted Moving Average. //@field hma Selects a Hull Moving Average. enum maChoice sma = &quot;Simple Moving Average&quot; ema = &quot;Exponential Moving Average&quot; wma = &quot;Weighted Moving Average&quot; hma = &quot;Hull Moving Average&quot;</div> <p>Note that:</p> <ul> <li>All the enum’s possible values are available upon the <em>first</em> script execution and do not change across subsequent executions. Hence, they automatically adopt the <a href="/pine-script-docs/language/type-system/#simple">simple</a> qualifier.</li> </ul> <p>The script below uses the <code dir="auto">maChoice</code> enum within an <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_input.enum">input.enum()</a> call to create a <em>dropdown</em> input in the “Settings/Inputs” tab that displays all the field titles. The <code dir="auto">maInput</code> value represents the member of the enum that corresponds to the user-selected title. The script uses the selected member within a <a href="https://www.tradingview.com/pine-script-reference/v6/#kw_switch">switch</a> structure to determine the built-in moving average it calculates:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Enum types demo&quot;, overlay = true) //@enum An enumeration of named values for moving average selection. //@field sma Selects a Simple Moving Average. //@field ema Selects an Exponential Moving Average. //@field wma Selects a Weighted Moving Average. //@field hma Selects a Hull Moving Average. enum maChoice sma = &quot;Simple Moving Average&quot; ema = &quot;Exponential Moving Average&quot; wma = &quot;Weighted Moving Average&quot; hma = &quot;Hull Moving Average&quot; //@variable The `maChoice` member representing a selected moving average name. maChoice maInput = input.enum(maChoice.sma, &quot;Moving average type&quot;) //@variable The length of the moving average. int lengthInput = input.int(20, &quot;Length&quot;, 1, 4999) //@variable The moving average selected by the `maInput`. float selectedMA = switch maInput maChoice.sma =&gt; ta.sma(close, lengthInput) maChoice.ema =&gt; ta.ema(close, lengthInput) maChoice.wma =&gt; ta.wma(close, lengthInput) maChoice.hma =&gt; ta.hma(close, lengthInput) // Plot the `selectedMA`. plot(selectedMA, &quot;Selected moving average&quot;, color.teal, 3)</div> <p>See the <a href="/pine-script-docs/language/enums/">Enums</a> page and the <a href="/pine-script-docs/concepts/inputs/#enum-input">Enum input</a> section of the <a href="/pine-script-docs/concepts/inputs/">Inputs</a> page to learn more about using enums and enum inputs.</p> <h3 id="void" class="md-heading"><a href="#void">void<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h3> <p>There is a “void” type in Pine Script™. Functions having only side-effects and returning no usable result return the “void” type. An example of such a function is <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_alert">alert()</a>; it does something (triggers an alert event), but it returns no usable value.</p> <p>Scripts cannot use “void” results in expressions or assign them to variables. No <code dir="auto">void</code> keyword exists in Pine Script™ since one cannot declare a variable of the “void” type.</p> <h2 id="na-value" class="md-heading"><a href="#na-value">`na` value<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h2> <p>There is a special value in Pine Script™ called <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>, which is an acronym for <em>not available</em>. We use <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> to represent an undefined value from a variable or expression. It is similar to <code dir="auto">null</code> in Java and <code dir="auto">None</code> in Python.</p> <p>Scripts can automatically cast <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> values to almost any type. However, in some cases, the compiler cannot infer the type associated with an <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> value because more than one type-casting rule may apply. For example:</p> <div class="pine-colorizer not-content">// Compilation error! myVar = na</div> <p>The above line of code causes a compilation error because the compiler cannot determine the nature of the <code dir="auto">myVar</code> variable, i.e., whether the variable will reference numeric values for plotting, string values for setting text in a label, or other values for some other purpose later in the script’s execution.</p> <p>To resolve such errors, we must explicitly declare the type associated with the variable. Suppose the <code dir="auto">myVar</code> variable will reference “float” values in subsequent script iterations. We can resolve the error by declaring the variable with the <a href="https://www.tradingview.com/pine-script-reference/v6/#type_float">float</a> keyword:</p> <div class="pine-colorizer not-content">float myVar = na</div> <p>or by explicitly casting the <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> value to the “float” type via the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_float">float()</a> function:</p> <div class="pine-colorizer not-content">myVar = float(na)</div> <p>To test if the value from a variable or expression is <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>, we call the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_na">na()</a> function, which returns <code dir="auto">true</code> if the value is undefined. For example:</p> <div class="pine-colorizer not-content">//@variable Is 0 if the `myVar` is `na`, `close` otherwise. float myClose = na(myVar) ? 0 : close</div> <p>Do not use the <code dir="auto">==</code> comparison operator to test for <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> values, as scripts cannot determine the equality of an undefined value:</p> <div class="pine-colorizer not-content">//@variable Returns the `close` value. The script cannot compare the equality of `na` values, as they&#39;re undefined. float myClose = myVar == na ? 0 : close</div> <p>Best coding practices often involve handling <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> values to prevent undefined values in calculations.</p> <p>We can ensure the expression also returns an actionable value on the first bar by replacing the undefined past value with a value from the current bar. This line of code uses the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_nz">nz()</a> function to replace the past bar’s <a href="https://www.tradingview.com/pine-script-reference/v6/#var_close">close</a> with the current bar’s <a href="https://www.tradingview.com/pine-script-reference/v6/#var_open">open</a> when the value is <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>:</p> <div class="pine-colorizer not-content">//@variable Is `true` when the `close` exceeds the last bar&#39;s `close` (or the current `open` if the value is `na`). bool risingClose = close &gt; nz(close[1], open)</div> <p>Protecting scripts against <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> instances helps to prevent undefined values from propagating in a calculation’s results. For example, this script declares an <code dir="auto">allTimeHigh</code> variable on the first bar. It then uses the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_math.max">math.max()</a> between the <code dir="auto">allTimeHigh</code> and the bar’s <a href="https://www.tradingview.com/pine-script-reference/v6/#var_high">high</a> to update the <code dir="auto">allTimeHigh</code> throughout its execution:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;na protection demo&quot;, overlay = true) //@variable The result of calculating the all-time high price with an initial value of `na`. var float allTimeHigh = na // Reassign the value of the `allTimeHigh`. // Returns `na` on all bars because `math.max()` can&#39;t compare the `high` to an undefined value. allTimeHigh := math.max(allTimeHigh, high) plot(allTimeHigh) // Plots `na` on all bars.</div> <p>This script plots a value of <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> on all bars, as we have not included any <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> protection in the code. To fix the behavior and plot the intended result (i.e., the all-time high of the chart’s prices), we can use <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_nz">nz()</a> to replace <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> values in the <code dir="auto">allTimeHigh</code> series:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;na protection demo&quot;, overlay = true) //@variable The result of calculating the all-time high price with an initial value of `na`. var float allTimeHigh = na // Reassign the value of the `allTimeHigh`. // We&#39;ve used `nz()` to prevent the initial `na` value from persisting throughout the calculation. allTimeHigh := math.max(nz(allTimeHigh), high) plot(allTimeHigh)</div> <h2 id="type-templates" class="md-heading"><a href="#type-templates">Type templates<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h2> <p>Type templates specify the data types that collections (<a href="/pine-script-docs/language/arrays/">arrays</a>, <a href="/pine-script-docs/language/matrices/">matrices</a>, and <a href="/pine-script-docs/language/maps/">maps</a>) can contain.</p> <p>Templates for <a href="/pine-script-docs/language/arrays/">arrays</a> and <a href="/pine-script-docs/language/matrices/">matrices</a> consist of a single type identifier surrounded by angle brackets, e.g., <code dir="auto">&lt;int&gt;</code>, <code dir="auto">&lt;label&gt;</code>, and <code dir="auto">&lt;PivotPoint&gt;</code> (where <code dir="auto">PivotPoint</code> is a <a href="/pine-script-docs/language/type-system/#user-defined-types">user-defined type (UDT)</a>).</p> <p>Templates for <a href="/pine-script-docs/language/maps/">maps</a> consist of two type identifiers enclosed in angle brackets, where the first specifies the type of <em>keys</em> in each key-value pair, and the second specifies the <em>value</em> type. For example, <code dir="auto">&lt;string, float&gt;</code> is a type template for a map that holds <code dir="auto">string</code> keys and <code dir="auto">float</code> values.</p> <p>Users can construct type templates from:</p> <ul> <li>Fundamental types: <a href="/pine-script-docs/language/type-system/#int">int</a>, <a href="/pine-script-docs/language/type-system/#float">float</a>, <a href="/pine-script-docs/language/type-system/#bool">bool</a>, <a href="/pine-script-docs/language/type-system/#color">color</a>, and <a href="/pine-script-docs/language/type-system/#string">string</a></li> <li>The following special types: <a href="/pine-script-docs/language/type-system/#drawing-types">line</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">linefill</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">box</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">polyline</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">label</a>, <a href="/pine-script-docs/language/type-system/#drawing-types">table</a>, and <a href="/pine-script-docs/language/type-system/#chart-points">chart.point</a></li> <li><a href="/pine-script-docs/language/type-system/#user-defined-types">User-defined types (UDTs)</a></li> <li><a href="/pine-script-docs/language/type-system/#enum-types">Enum types</a></li> </ul> <p>Note that:</p> <ul> <li><a href="/pine-script-docs/language/maps/">Maps</a> can use any of these types as <em>values</em>, but they can only accept fundamental types or <a href="/pine-script-docs/language/type-system/#enum-types">enum types</a> as <em>keys</em>.</li> </ul> <p>Scripts use type templates to declare variables that reference collections, and when creating new collection instances. For example:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Type templates demo&quot;) //@variable A variable initially assigned to `na` that accepts arrays of &quot;int&quot; values. array&lt;int&gt; intArray = na //@variable An empty matrix that holds &quot;float&quot; values. floatMatrix = matrix.new&lt;float&gt;() //@variable An empty map that holds &quot;string&quot; keys and &quot;color&quot; values. stringColorMap = map.new&lt;string, color&gt;()</div> <h2 id="type-casting" class="md-heading"><a href="#type-casting">Type casting<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h2> <p>Pine Script™ includes an automatic type-casting mechanism that <em>casts</em> (converts) <strong>“int”</strong> values to <strong>“float”</strong> when necessary. Variables or expressions requiring “float” values can also use “int” values because any integer can be represented as a floating point number with its fractional part equal to 0.</p> <p>It’s sometimes necessary to cast one type to another when auto-casting rules do not suffice. For such cases, the following type-casting functions are available: <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_int">int()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_float">float()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_bool">bool()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_color">color()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_string">string()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_line">line()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_linefill">linefill()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_label">label()</a>, <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_box">box()</a>, and <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_table">table()</a>.</p> <p>The example below shows a code that tries to use a “const float” value as the <code dir="auto">length</code> argument in the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_ta.sma">ta.sma()</a> function call. The script will fail to compile, as it cannot automatically convert the “float” value to the required “int” type:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Explicit casting demo&quot;, overlay = true) //@variable The length of the SMA calculation. Qualified as &quot;const float&quot;. float LENGTH = 10.0 float sma = ta.sma(close, LENGTH) // Compilation error. The `length` parameter requires an &quot;int&quot; value. plot(sma)</div> <p>The code raises the following error: <em>“Cannot call ‘ta.sma’ with argument ‘length’=‘LENGTH’. An argument of ‘const float’ type was used but a ‘series int’ is expected.”</em></p> <p>The compiler is telling us that the code is using a “float” value where an “int” is required. There is no auto-casting rule to cast a “float” to an “int”, so we must do the job ourselves. In this version of the code, we’ve used the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_int">int()</a> function to explicitly convert our “float” <code dir="auto">LENGTH</code> value to the “int” type within the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_ta.sma">ta.sma()</a> call:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;explicit casting demo&quot;) //@variable The length of the SMA calculation. Qualified as &quot;const float&quot;. float LENGTH = 10.0 float sma = ta.sma(close, int(LENGTH)) // Compiles successfully since we&#39;ve converted the `LENGTH` to &quot;int&quot;. plot(sma)</div> <p>Explicit type casting is also handy when declaring variables assigned to <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a>, as explained in the <a href="/pine-script-docs/language/type-system/#na-value">previous section</a>.</p> <p>For example, once could explicitly declare a variable with a value of <a href="https://www.tradingview.com/pine-script-reference/v6/#var_na">na</a> as a “label” type in either of the following, equivalent ways:</p> <div class="pine-colorizer not-content">// Explicitly specify that the variable references &quot;label&quot; objects: label myLabel = na // Explicitly cast the `na` value to the &quot;label&quot; type: myLabel = label(na)</div> <h2 id="tuples" class="md-heading"><a href="#tuples">Tuples<span class="icon icon-link" aria-hidden="true"><svg width="28" height="28" viewBox="0 0 28 28"><g fill="currentColor" clip-path="url(#a)"><path d="M14.908 5.558a5.326 5.326 0 1 1 7.533 7.533l-3.236 3.236-1.061-1.061 3.236-3.236a3.826 3.826 0 1 0-5.411-5.411l-3.236 3.236-1.06-1.06 3.235-3.237ZM5.56 14.907a5.326 5.326 0 0 0 7.532 7.533l3.236-3.236-1.061-1.061-3.236 3.236a3.826 3.826 0 1 1-5.411-5.411l3.236-3.236-1.061-1.06-3.236 3.235Z"></path><path d="m16.346 10.592-5.753 5.753 1.061 1.06 5.753-5.752-1.06-1.06Z"></path></g><defs><clippath id="a"><path fill="#fff" d="M0 0h28v28H0z"></path></clippath></defs></svg></span></a></h2> <p>A <em>tuple</em> is a comma-separated set of expressions enclosed in brackets. When a function, <a href="/pine-script-docs/language/methods/">method</a>, or other local block returns more than one value, scripts return those values in the form of a tuple.</p> <p>For example, the following <a href="/pine-script-docs/language/user-defined-functions/">user-defined function</a> returns the sum and product of two “float” values:</p> <div class="pine-colorizer not-content">//@function Calculates the sum and product of two values. calcSumAndProduct(float a, float b) =&gt; //@variable The sum of `a` and `b`. float sum = a + b //@variable The product of `a` and `b`. float product = a * b // Return a tuple containing the `sum` and `product`. [sum, product]</div> <p>When we call this function later in the script, we use a <em>tuple declaration</em> to declare multiple variables corresponding to the values returned by the function call:</p> <div class="pine-colorizer not-content">// Declare a tuple containing the sum and product of the `high` and `low`, respectively. [hlSum, hlProduct] = calcSumAndProduct(high, low)</div> <p>Keep in mind that unlike declaring single variables, we cannot explicitly define the types the tuple’s variables (<code dir="auto">hlSum</code> and <code dir="auto">hlProduct</code> in this case), will contain. The compiler automatically infers the types associated with the variables in a tuple.</p> <p>In the above example, the resulting tuple contains values of the same type (“float”). However, it’s important to note that tuples can contain values of <em>multiple types</em>. For example, the <code dir="auto">chartInfo()</code> function below returns a tuple containing “int”, “float”, “bool”, “color”, and “string” values:</p> <div class="pine-colorizer not-content">//@function Returns information about the current chart. chartInfo() =&gt; //@variable The first visible bar&#39;s UNIX time value. int firstVisibleTime = chart.left_visible_bar_time //@variable The `close` value at the `firstVisibleTime`. float firstVisibleClose = ta.valuewhen(ta.cross(time, firstVisibleTime), close, 0) //@variable Is `true` when using a standard chart type, `false` otherwise. bool isStandard = chart.is_standard //@variable The foreground color of the chart. color fgColor = chart.fg_color //@variable The ticker ID of the current chart. string symbol = syminfo.tickerid // Return a tuple containing the values. [firstVisibleTime, firstVisibleClose, isStandard, fgColor, symbol]</div> <p>Tuples are especially handy for requesting multiple values in one <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_request.security">request.security()</a> call.</p> <p>For instance, this <code dir="auto">roundedOHLC()</code> function returns a tuple containing OHLC values rounded to the nearest prices that are divisible by the symbol’s <a href="https://www.tradingview.com/pine-script-reference/v6/#var_syminfo.mintick">minimum tick</a> value. We call this function as the <code dir="auto">expression</code> argument in <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_request.security">request.security()</a> to request a tuple containing daily OHLC values:</p> <div class="pine-colorizer not-content">//@function Returns a tuple of OHLC values, rounded to the nearest tick. roundedOHLC() =&gt; [math.round_to_mintick(open), math.round_to_mintick(high), math.round_to_mintick(low), math.round_to_mintick(close)] [op, hi, lo, cl] = request.security(syminfo.tickerid, &quot;D&quot;, roundedOHLC())</div> <p>We can also achieve the same result by directly passing a tuple of rounded values as the <code dir="auto">expression</code> in the <a href="https://www.tradingview.com/pine-script-reference/v6/#fun_request.security">request.security()</a> call:</p> <div class="pine-colorizer not-content">[op, hi, lo, cl] = request.security( syminfo.tickerid, &quot;D&quot;, [math.round_to_mintick(open), math.round_to_mintick(high), math.round_to_mintick(low), math.round_to_mintick(close)] )</div> <p>Local blocks of <a href="/pine-script-docs/language/conditional-structures/">conditional structures</a>, including <a href="https://www.tradingview.com/pine-script-reference/v6/#kw_if">if</a> and <a href="https://www.tradingview.com/pine-script-reference/v6/#kw_switch">switch</a> statements, can return tuples. For example:</p> <div class="pine-colorizer not-content">[v1, v2] = if close &gt; open [high, close] else [close, low]</div> <p>and:</p> <div class="pine-colorizer not-content">[v1, v2] = switch close &gt; open =&gt; [high, close] =&gt; [close, low]</div> <p>However, ternaries cannot contain tuples, as the return values in a ternary statement are not considered local blocks:</p> <div class="pine-colorizer not-content">// Not allowed. [v1, v2] = close &gt; open ? [high, close] : [close, low]</div> <p>Note that all items within a tuple returned from a function are qualified as “simple” or “series”, depending on its contents. If a tuple contains a “series” value, all other elements within the tuple will also adopt the “series” qualifier. For example:</p> <div class="pine-colorizer not-content">//@version=6 indicator(&quot;Qualified types in tuples demo&quot;) makeTicker(simple string prefix, simple string ticker) =&gt; tId = prefix + &quot;:&quot; + ticker // simple string source = close // series float [tId, source] // Both variables are series now. [tId, source] = makeTicker(&quot;BATS&quot;, &quot;AAPL&quot;) // Error cannot call &#39;request.security&#39; with &#39;series string&#39; tId. r = request.security(tId, &quot;&quot;, source) plot(r)</div> </div> <div class="pagination-buttons not-content" data-astro-cid-xgirumru> <a href="/pine-script-docs/language/loops" class="pagination-card" data-pagefind-ignore data-astro-cid-assl6cvf> <p data-astro-cid-assl6cvf>Previous</p> <h4 class="pagination-card-header" data-astro-cid-assl6cvf> <svg width="28" height="28" viewBox="0 0 28 28" data-astro-cid-assl6cvf data-icon="theme/arrow-back"> <use xlink:href="#ai:local:theme/arrow-back"></use> </svg> Loops </h4> </a> <a href="/pine-script-docs/language/built-ins" class="pagination-card" data-pagefind-ignore data-astro-cid-assl6cvf> <p data-astro-cid-assl6cvf>Next</p> <h4 class="pagination-card-header" data-astro-cid-assl6cvf> Built-ins <svg width="28" height="28" viewBox="0 0 28 28" data-astro-cid-assl6cvf data-icon="theme/arrow"> <symbol id="ai:local:theme/arrow"><path fill="none" stroke="var(--arrow-fill-color, #131722)" d="m11 8 6 6-6 6"/></symbol><use xlink:href="#ai:local:theme/arrow"></use> </svg> </h4> </a> </div> </main> <div id="toc" data-pagefind-ignore="all" data-astro-cid-oor6cujd><aside class="document-toc-container ml-4 w-48" data-astro-cid-oor6cujd><section id="toc-scroll-section" class="slick-scroll" data-astro-cid-oor6cujd><header data-astro-cid-oor6cujd><h2 class="toc-header" data-astro-cid-oor6cujd>On this page</h2></header><ul class="" id="toc-entries" data-astro-cid-oor6cujd><a href="#introduction" aria-current="true" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-current data-astro-cid-oor6cujd>Introduction</li></a><a href="#qualifiers" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Qualifiers</li></a><a href="#const" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>const</li></a><a href="#input" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>input</li></a><a href="#simple" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>simple</li></a><a href="#series" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>series</li></a><a href="#types" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Types</li></a><a href="#int" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>int</li></a><a href="#float" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>float</li></a><a href="#bool" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>bool</li></a><a href="#color" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>color</li></a><a href="#string" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>string</li></a><a href="#plot-and-hline" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>plot and hline</li></a><a href="#drawing-types" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Drawing types</li></a><a href="#chart-points" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Chart points</li></a><a href="#collections" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Collections</li></a><a href="#user-defined-types" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>User-defined types</li></a><a href="#enum-types" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Enum types</li></a><a href="#void" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>void</li></a><a href="#na-value" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>&#96na&#96 value</li></a><a href="#type-templates" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Type templates</li></a><a href="#type-casting" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Type casting</li></a><a href="#tuples" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Tuples</li></a></ul></section><div class="toc-bottom-fade" data-astro-cid-oor6cujd></div><div class="back-top-space" data-astro-cid-oor6cujd><div class="not-content" style="" data-astro-cid-pkzv2hgs> <a id="back-top-button" title="Back to top" href="#top" data-astro-cid-pkzv2hgs class="floating-button not-content stvb-base stvb-pointer stvb-gray stvb-medium stvb-secondary stvb-icon stvb-icon-force-color stvb-force-no-border"> <svg width="18" height="18" viewBox="0 0 18 18" data-astro-cid-oor6cujd data-icon="theme/arrow-up"> <symbol id="ai:local:theme/arrow-up"><g fill="none"><g clip-path="url(#a)"><path fill="currentColor" fill-rule="evenodd" d="m9 3.5.5.44 4 3.5-1 1.12-2.75-2.4V14h-1.5V6.15L5.49 8.56l-.98-1.12 4-3.5L9 3.5Z" clip-rule="evenodd"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h18v18H0z"/></clipPath></defs></g></symbol><use xlink:href="#ai:local:theme/arrow-up"></use> </svg> </a> </div> </div></aside></div> </main> </div> <footer data-astro-cid-b6pf7ola> <div class="footer-content" data-astro-cid-b6pf7ola> <ul data-astro-cid-b6pf7ola> <li data-astro-cid-b6pf7ola> <a href="https://www.tradingview.com/chat/#BfmVowG1TZkKO235" data-astro-cid-b6pf7ola>Pine Q&amp;A chat</a> </li><li data-astro-cid-b6pf7ola> <a href="https://stackoverflow.com/questions/tagged/pine-script" data-astro-cid-b6pf7ola>Stack Overflow</a> ↗ </li><li data-astro-cid-b6pf7ola> <a href="https://t.me/PineCodersQA" data-astro-cid-b6pf7ola>Telegram</a> ↗ </li><li data-astro-cid-b6pf7ola> <a href="https://www.reddit.com/r/TradingView/" data-astro-cid-b6pf7ola>Reddit</a> ↗ </li> </ul> <div class="flex" data-astro-cid-b6pf7ola></div> <div class="copyright" data-astro-cid-b6pf7ola>Copyright © 2024 TradingView, Inc.</div> </div> </footer> </body></html>

Pages: 1 2 3 4 5 6 7 8 9 10