CINXE.COM

Migration_guides / To Pine Script™ version 5

<!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>Migration_guides / To Pine Script™ version 5</title><meta name="og:title" content="Migration_guides / To Pine Script™ version 5"><meta name="twitter:title" content="Migration_guides / To Pine Script™ version 5"><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/migration-guides/to-pine-version-5/"><meta name="twitter:url" content="https://www.tradingview.com/pine-script-docs/migration-guides/to-pine-version-5/"><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/migration-guides/to-pine-version-5/"><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 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-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 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>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-current 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 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-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 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>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-current 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/migration-guides/to-pine-version-6" data-astro-cid-wlavna2o>Migration guides</a> <span class="divider" data-astro-cid-wlavna2o>/</span> <span class="current-item" data-astro-cid-wlavna2o>To Pine Script™ version 5</span> </div> </div> <div id="slot-container" data-astro-cid-xgirumru> <h1 id="to-pine-script-version-5" class="md-heading"><a href="#to-pine-script-version-5">To Pine Script™ version 5<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>This guide documents the <strong>changes</strong> made to Pine Script™ from v4 to v5. It will guide you in the adaptation of existing Pine scripts to Pine Script™ v5. See our <a href="/pine-script-docs/release-notes/#october-2021">Release notes</a> for a list of the <strong>new</strong> features in Pine Script™ v5.</p> <p>The most frequent adaptations required to convert older scripts to v5 are:</p> <ul> <li>Changing <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_study">study()</a> for <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_indicator">indicator()</a> (the function’s signature has not changed).</li> <li>Renaming built-in function calls to include their new namespace (e.g., <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_highest">highest()</a> in v4 becomes <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_ta%7Bdot%7Dhighest">ta.highest()</a> in v5).</li> <li>Restructuring inputs to use the more specialized <code dir="auto">input.*()</code> functions.</li> <li>Eliminating uses of the deprecated <code dir="auto">transp</code> parameter by using <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_color%7Bdot%7Dnew">color.new()</a> to simultaneously define color and transparency for use with the <code dir="auto">color</code> parameter.</li> <li>If you used the <code dir="auto">resolution</code> and <code dir="auto">resolution_gaps</code> parameters in v4’s <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_study">study()</a>, they will require changing to <code dir="auto">timeframe</code> and <code dir="auto">timeframe_gaps</code> in v5’s <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_indicator">indicator()</a>.</li> </ul> <h2 id="v4-to-v5-converter" class="md-heading"><a href="#v4-to-v5-converter">v4 to v5 converter<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 Editor includes a utility to automatically convert v4 scripts to v5. To access it, open a script with <code dir="auto">//@version=4</code> in it and select the “Convert to v5” option in the “More” menu identified by three dots at the top-right of the Editor’s pane:</p> <p><img src="/pine-script-docs/_astro/v4_to_v5_convert_button.B6QYFNWm_1b9vBk.webp" alt="image" width="1232" height="816" loading="lazy" decoding="async"></p> <p>Not all scripts can be automatically converted from v4 to v5. If you want to convert the script manually or if your indicator returns a compilation error after conversion, use the following sections to determine how to complete the conversion. A list of some errors you can encounter during the automatic conversion and how to fix them can be found in the <a href="/pine-script-docs/migration-guides/to-pine-version-5#common-script-conversion-errors">Common script conversion errors</a> section of this guide.</p> <h2 id="renamed-functions-and-variables" class="md-heading"><a href="#renamed-functions-and-variables">Renamed functions and variables<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>For clarity and consistency, many built-in functions and variables were renamed in v5. The inclusion of v4 function names in a new namespace is the cause of most changes. For example, the <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_sma">sma()</a> function in v4 is moved to the <code dir="auto">ta.</code> namespace in v5: <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_ta%7Bdot%7Dsma">ta.sma()</a>. Remembering the new namespaces is not necessary; if you type the older name of a function without its namespace in the Editor and press the ‘Auto-complete’ hotkey (<code dir="auto">Ctrl</code> + <code dir="auto">Space</code>, or <code dir="auto">Cmd</code> on MacOS), a popup showing matching suggestions appears:</p> <p><img src="/pine-script-docs/_astro/v5_autocomplete.R-4HP09V_Z1R3GAs.webp" alt="image" width="956" height="521" loading="lazy" decoding="async"></p> <p>Not counting functions moved to new namespaces, only two functions have been renamed:</p> <ul> <li><code dir="auto">study()</code> is now <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_indicator">indicator()</a>.</li> <li><code dir="auto">tickerid()</code> is now <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_ticker%7Bdot%7Dnew">ticker.new()</a>.</li> </ul> <p>The full list of renamed functions and variables can be found in the <a href="/pine-script-docs/migration-guides/to-pine-version-5#all-variable-function-and-parameter-name-changes">All variable, function, and parameter name changes</a> section of this guide.</p> <h2 id="renamed-function-parameters" class="md-heading"><a href="#renamed-function-parameters">Renamed function parameters<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 parameter names of some built-in functions were changed to improve the nomenclature. This has no bearing on most scripts, but if you used these parameter names when calling functions, they will require adaptation. For example, we have standardized all mentions:</p> <div class="pine-colorizer not-content">// Valid in v4. Not valid in v5. timev4 = time(resolution = &quot;1D&quot;) // Valid in v5. timev5 = time(timeframe = &quot;1D&quot;) // Valid in v4 and v5. timeBoth = time(&quot;1D&quot;)</div> <p>The full list of renamed function parameters can be found in the <a href="/pine-script-docs/migration-guides/to-pine-version-5#all-variable-function-and-parameter-name-changes">All variable, function, and parameter name changes</a> section of this guide.</p> <h2 id="removed-an-rsi-overload" class="md-heading"><a href="#removed-an-rsi-overload">Removed an `rsi()` overload<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>In v4, the <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_rsi">rsi()</a> function had two different overloads:</p> <ul> <li><code dir="auto">rsi(series float, simple int)</code> for the normal RSI calculation, and</li> <li><code dir="auto">rsi(series float, series float)</code> for an overload used in the MFI indicator, which did a calculation equivalent to <code dir="auto">100.0 - (100.0 / (1.0 + arg1 / arg2))</code>.</li> </ul> <p>This caused a single built-in function to behave in two very different ways, and it was difficult to distinguish which one applied because it depended on the type of the second argument. As a result, a number of indicators misused the function and were displaying incorrect results. To avoid this, the second overload was removed in v5.</p> <p>The <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_ta%7Bdot%7Drsi">ta.rsi()</a> function in v5 only accepts a “simple int” argument for its <code dir="auto">length</code> parameter. If your v4 code used the now deprecated overload of the function with a <code dir="auto">float</code> second argument, you can replace the whole <code dir="auto">rsi()</code> call with the following formula, which is equivalent:</p> <div class="pine-colorizer not-content">100.0 - (100.0 / (1.0 + arg1 / arg2))</div> <p>Note that when your v4 code used a “series int” value as the second argument to <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_rsi">rsi()</a>, it was automatically cast to “series float” and the second overload of the function was used. While this was syntactically correct, it most probably did <strong>not</strong> yield the result you expected. In v5, <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_ta%7Bdot%7Drsi">ta.rsi()</a> requires a “simple int” for the argument to <code dir="auto">length</code>, which precludes dynamic (or “series”) lengths. The reason for this is that RSI calculations use the <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_ta%7Bdot%7Drma">ta.rma()</a> moving average, which is similar to <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_ta%7Bdot%7Dema">ta.ema()</a> in that it relies on a length-dependent recursive process using the values of previous bars. This makes it impossible to achieve correct results with a “series” length that could vary bar to bar.</p> <p>If your v4 code used a length that was “const int”, “input int” or “simple int”, no changes are required.</p> <h2 id="reserved-keywords" class="md-heading"><a href="#reserved-keywords">Reserved keywords<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 number of words are reserved and cannot be used for variable or function names. They are: <code dir="auto">catch</code>, <code dir="auto">class</code>, <code dir="auto">do</code>, <code dir="auto">ellipse</code>, <code dir="auto">in</code>, <code dir="auto">is</code>, <code dir="auto">polygon</code>, <code dir="auto">range</code>, <code dir="auto">return</code>, <code dir="auto">struct</code>, <code dir="auto">text</code>, <code dir="auto">throw</code>, <code dir="auto">try</code>. If your v4 indicator uses any of these, rename your variable or function for the script to work in v5.</p> <h2 id="removed-iff-and-offset" class="md-heading"><a href="#removed-iff-and-offset">Removed `iff()` and `offset()`<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 <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_iff">iff()</a> and <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_offset">offset()</a> functions have been removed. Code using the <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_iff">iff()</a> function can be rewritten using the ternary operator:</p> <div class="pine-colorizer not-content">// iff(&lt;condition&gt;, &lt;return_when_true&gt;, &lt;return_when_false&gt;) // Valid in v4, not valid in v5 barColorIff = iff(close &gt;= open, color.green, color.red) // &lt;condition&gt; ? &lt;return_when_true&gt; : &lt;return_when_false&gt; // Valid in v4 and v5 barColorTernary = close &gt;= open ? color.green : color.red</div> <p>Note that the ternary operator is evaluated “lazily”; only the required value is calculated (depending on the condition’s evaluation to <code dir="auto">true</code> or <code dir="auto">false</code>). This is different from <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_iff">iff()</a>, which always evaluated both values but returned only the relevant one.</p> <p>Some functions require evaluation on every bar to correctly calculate, so you will need to make special provisions for these by pre-evaluating them before the ternary:</p> <div class="pine-colorizer not-content">// `iff()` in v4: `highest()` and `lowest()` are calculated on every bar v1 = iff(close &gt; open, highest(10), lowest(10)) plot(v1) // In v5: forced evaluation on every bar prior to the ternary statement. h1 = ta.highest(10) l1 = ta.lowest(10) v1 = close &gt; open ? h1 : l1 plot(v1)</div> <p>The <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_offset">offset()</a> function was deprecated because the more readable <a href="https://www.tradingview.com/pine-script-reference/v5/#op_%5B%5D">[]</a> operator is equivalent:</p> <div class="pine-colorizer not-content">// Valid in v4. Not valid in v5. prevClosev4 = offset(close, 1) // Valid in v4 and v5. prevClosev5 = close[1]</div> <h2 id="split-of-input-into-several-functions" class="md-heading"><a href="#split-of-input-into-several-functions">Split of `input()` into several functions<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 v4 <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_input">input()</a> function was becoming crowded with a plethora of overloads and parameters. We split its functionality into different functions to clear that space and provide a more robust structure to accommodate the additions planned for inputs. Each new function uses the name of the <code dir="auto">input.*</code> type of the v4 <code dir="auto">input()</code> call it replaces. E.g., there is now a specialized <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_input%7Bdot%7Dfloat">input.float()</a> function replacing the v4 <code dir="auto">input(1.0, type = input.float)</code> call. Note that you can still use <code dir="auto">input(1.0)</code> in v5, but because only <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_input%7Bdot%7Dfloat">input.float()</a> allows for parameters such as <code dir="auto">minval</code>, <code dir="auto">maxval</code>, etc., it is more powerful. Also note that <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_input%7Bdot%7Dint">input.int()</a> is the only specialized input function that does not use its equivalent v4 <code dir="auto">input.integer</code> name. The <code dir="auto">input.*</code> constants have been removed because they were used as arguments for the <code dir="auto">type</code> parameter, which was deprecated.</p> <p>To convert, for example, a v4 script using an input of type <code dir="auto">input.symbol</code>, the <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_input%7Bdot%7Dsymbol">input.symbol()</a> function must be used in v5:</p> <div class="pine-colorizer not-content">// Valid in v4. Not valid in v5. aaplTicker = input(&quot;AAPL&quot;, type = input.symbol) // Valid in v5 aaplTicker = input.symbol(&quot;AAPL&quot;)</div> <p>The <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_input">input()</a> function persists in v5, but in a simpler form, with less parameters. It has the advantage of automatically detecting input types “bool/color/int/float/string/source” from the argument used for <code dir="auto">defval</code>:</p> <div class="pine-colorizer not-content">// Valid in v4 and v5. // While &quot;AAPL&quot; is a valid symbol, it is only a string here because `input.symbol()` is not used. tickerString = input(&quot;AAPL&quot;, title = &quot;Ticker string&quot;)</div> <h2 id="some-function-parameters-now-require-built-in-arguments" class="md-heading"><a href="#some-function-parameters-now-require-built-in-arguments">Some function parameters now require built-in arguments<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>In v4, built-in constants such as <code dir="auto">plot.style_area</code> used as arguments when calling Pine Script™ functions corresponded to pre-defined values of a specific type. For example, the value of <code dir="auto">barmerge.lookahead_on</code> was <code dir="auto">true</code>, so you could use <code dir="auto">true</code> instead of the named constant when supplying an argument to the <code dir="auto">lookahead</code> parameter in a <a href="https://www.tradingview.com/pine-script-reference/v4/#fun_security">security()</a> function call. We found this to be a common source of confusion, which caused unsuspecting programmers to produce code yielding unintended results.</p> <p>In v5, the use of correct built-in named constants as arguments to function parameters requiring them is mandatory:</p> <div class="pine-colorizer not-content">// Not valid in v5: `true` is used as an argument for `lookahead`. request.security(syminfo.tickerid, &quot;1D&quot;, close, lookahead = true) // Valid in v5: uses a named constant instead of `true`. request.security(syminfo.tickerid, &quot;1D&quot;, close, lookahead = barmerge.lookahead_on) // Would compile in v4 because `plot.style_columns` was equal to 5. // Won&#39;t compile in v5. a = 2 * plot.style_columns plot(a)</div> <p>To convert your script from v4 to v5, make sure you use the correct named built-in constants as function arguments.</p> <h2 id="deprecated-the-transp-parameter" class="md-heading"><a href="#deprecated-the-transp-parameter">Deprecated the `transp` parameter<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 <code dir="auto">transp=</code> parameter used in the signature of many v4 plotting functions was deprecated because it interfered with RGB functionality. Transparency must now be specified along with the color as an argument to parameters such as <code dir="auto">color</code>, <code dir="auto">textcolor</code>, etc. The <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_color%7Bdot%7Dnew">color.new()</a> or <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_color%7Bdot%7Drgb">color.rgb()</a> functions will be needed in those cases to join a color and its transparency.</p> <p>Note that in v4, the <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_bgcolor">bgcolor()</a> and <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_fill">fill()</a> functions had an optional <code dir="auto">transp</code> parameter that used a default value of 90. This meant that the code below could display Bollinger Bands with a semi-transparent fill between two bands and a semi-transparent backround color where bands cross price, even though no argument is used for the <code dir="auto">transp</code> parameter in its <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_bgcolor">bgcolor()</a> and <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_fill">fill()</a> calls:</p> <div class="pine-colorizer not-content">//@version=4 study(&quot;Bollinger Bands&quot;, overlay = true) [middle, upper, lower] = bb(close, 5, 4) plot(middle, color=color.blue) p1PlotID = plot(upper, color=color.green) p2PlotID = plot(lower, color=color.green) crossUp = crossover(high, upper) crossDn = crossunder(low, lower) // Both `fill()` and `bgcolor()` have a default `transp` of 90 fill(p1PlotID, p2PlotID, color = color.green) bgcolor(crossUp ? color.green : crossDn ? color.red : na)</div> <p>In v5 we need to explictly mention the 90 transparency with the color, yielding:</p> <div class="pine-colorizer not-content">//@version=5 indicator(&quot;Bollinger Bands&quot;, overlay = true) [middle, upper, lower] = ta.bb(close, 5, 4) plot(middle, color=color.blue) p1PlotID = plot(upper, color=color.green) p2PlotID = plot(lower, color=color.green) crossUp = ta.crossover(high, upper) crossDn = ta.crossunder(low, lower) var TRANSP = 90 // We use `color.new()` to explicitly pass transparency to both functions fill(p1PlotID, p2PlotID, color = color.new(color.green, TRANSP)) bgcolor(crossUp ? color.new(color.green, TRANSP) : crossDn ? color.new(color.red, TRANSP) : na)</div> <h2 id="changed-the-default-session-days-for-time-and-time_close" class="md-heading"><a href="#changed-the-default-session-days-for-time-and-time_close">Changed the default session days for `time()` and `time_close()`<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 default set of days for <code dir="auto">session</code> strings used in the <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_time">time()</a> and <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_time_close">time_close()</a> functions, and returned by <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_input%7Bdot%7Dsession">input.session()</a>, has changed from <code dir="auto">&quot;23456&quot;</code> (Monday to Friday) to <code dir="auto">&quot;1234567&quot;</code> (Sunday to Saturday):</p> <div class="pine-colorizer not-content">// On symbols that are traded during weekends, this will behave differently in v4 and v5. t0 = time(&quot;1D&quot;, &quot;1000-1200&quot;) // v5 equivalent of the behavior of `t0` in v4. t1 = time(&quot;1D&quot;, &quot;1000-1200:23456&quot;) // v5 equivalent of the behavior of `t0` in v5. t2 = time(&quot;1D&quot;, &quot;1000-1200:1234567&quot;)</div> <p>This change in behavior should not have much impact on scripts running on conventional markets that are closed during weekends. If it is important for you to ensure your session definitions preserve their v4 behavior in v5 code, add <code dir="auto">&quot;:23456&quot;</code> to your session strings. See this manual’s page on <a href="/pine-script-docs/concepts/sessions/">Sessions</a> for more information.</p> <h2 id="strategyexit-now-must-do-something" class="md-heading"><a href="#strategyexit-now-must-do-something">`strategy.exit()` now must do something<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>Gone are the days when the <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_strategy%7Bdot%7Dexit">strategy.exit()</a> function was allowed to loiter. Now it must actually have an effect on the strategy by using at least one of the following parameters: <code dir="auto">profit</code>, <code dir="auto">limit</code>, <code dir="auto">loss</code>, <code dir="auto">stop</code>, or one of the following pairs: <code dir="auto">trail_offset</code> combined with either <code dir="auto">trail_price</code> or <code dir="auto">trail_points</code>. When uses of <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_strategy%7Bdot%7Dexit">strategy.exit()</a> not meeting these criteria trigger an error while converting a strategy to v5, you can safely eliminate these lines, as they didn’t do anything in your code anyway.</p> <h2 id="common-script-conversion-errors" class="md-heading"><a href="#common-script-conversion-errors">Common script conversion errors<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> <h3 id="invalid-argument-stylelinestyle-in-plothline-call" class="md-heading"><a href="#invalid-argument-stylelinestyle-in-plothline-call">Invalid argument ‘style’/‘linestyle’ in ‘plot’/‘hline’ call<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>To make this work, you need to change the “int” arguments used for the <code dir="auto">style</code> and <code dir="auto">linestyle</code> arguments in <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_plot">plot()</a> and <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_hline">hline()</a> for built-in constants:</p> <div class="pine-colorizer not-content">// Will cause an error during conversion plotStyle = input(1) hlineStyle = input(1) plot(close, style = plotStyle) hline(100, linestyle = hlineStyle) // Will work in v5 //@version=5 indicator(&quot;&quot;) plotStyleInput = input.string(&quot;Line&quot;, options = [&quot;Line&quot;, &quot;Stepline&quot;, &quot;Histogram&quot;, &quot;Cross&quot;, &quot;Area&quot;, &quot;Columns&quot;, &quot;Circles&quot;]) hlineStyleInput = input.string(&quot;Solid&quot;, options = [&quot;Solid&quot;, &quot;Dashed&quot;, &quot;Dotted&quot;]) plotStyle = plotStyleInput == &quot;Line&quot; ? plot.style_line : plotStyleInput == &quot;Stepline&quot; ? plot.style_stepline : plotStyleInput == &quot;Histogram&quot; ? plot.style_histogram : plotStyleInput == &quot;Cross&quot; ? plot.style_cross : plotStyleInput == &quot;Area&quot; ? plot.style_area : plotStyleInput == &quot;Columns&quot; ? plot.style_columns : plot.style_circles hlineStyle = hlineStyleInput == &quot;Solid&quot; ? hline.style_solid : hlineStyleInput == &quot;Dashed&quot; ? hline.style_dashed : hline.style_dotted plot(close, style = plotStyle) hline(100, linestyle = hlineStyle)</div> <p>See the <a href="/pine-script-docs/migration-guides/to-pine-version-5#some-function-parameters-now-require-built-in-arguments">Some function parameters now require built-in arguments</a> section of this guide for more information.</p> <h3 id="undeclared-identifier-inputinput_name" class="md-heading"><a href="#undeclared-identifier-inputinput_name">Undeclared identifier ‘input.%input_name%’<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>To fix this issue, remove the <code dir="auto">input.*</code> constants from your code:</p> <div class="pine-colorizer not-content">// Will cause an error during conversion _integer = input.integer _bool = input.bool i1 = input(1, &quot;Integer&quot;, _integer) i2 = input(true, &quot;Boolean&quot;, _bool) // Will work in v5 i1 = input.int(1, &quot;Integer&quot;) i2 = input.bool(true, &quot;Boolean&quot;)</div> <p>See the User Manual’s page on <a href="/pine-script-docs/concepts/inputs/">Inputs</a>, and the <a href="/pine-script-docs/migration-guides/to-pine-version-5#some-function-parameters-now-require-built-in-arguments">Some function parameters now require built-in arguments</a> section of this guide for more information.</p> <h3 id="invalid-argument-when-in-strategyclose-call" class="md-heading"><a href="#invalid-argument-when-in-strategyclose-call">Invalid argument ‘when’ in ‘strategy.close’ call<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>This is caused by a confusion between <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_strategy%7Bdot%7Dentry">strategy.entry()</a> and <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_strategy%7Bdot%7Dclose">strategy.close()</a>.</p> <p>The second parameter of <a href="https://www.tradingview.com/pine-script-reference/v5/#fun_strategy%7Bdot%7Dclose">strategy.close()</a> is <code dir="auto">when</code>, which expects a “bool” argument. In v4, it was allowed to use <code dir="auto">strategy.long</code> an argument because it was a “bool”. With v5, however, named built-in constants must be used as arguments, so <code dir="auto">strategy.long</code> is no longer allowed as an argument to the <code dir="auto">when</code> parameter.</p> <p>The <code dir="auto">strategy.close(&quot;Short&quot;, strategy.long)</code> call in this code is equivalent to <code dir="auto">strategy.close(&quot;Short&quot;)</code>, which is what must be used in v5:</p> <div class="pine-colorizer not-content">// Will cause an error during conversion if (longCondition) strategy.close(&quot;Short&quot;, strategy.long) strategy.entry(&quot;Long&quot;, strategy.long) // Will work in v5: if (longCondition) strategy.close(&quot;Short&quot;) strategy.entry(&quot;Long&quot;, strategy.long)</div> <p>See the <a href="/pine-script-docs/migration-guides/to-pine-version-5#some-function-parameters-now-require-built-in-arguments">Some function parameters now require built-in arguments</a> section of this guide for more information.</p> <h3 id="cannot-call-inputint-with-argument-minvalvalue-an-argument-of-literal-float-type-was-used-but-a-const-int-is-expected" class="md-heading"><a href="#cannot-call-inputint-with-argument-minvalvalue-an-argument-of-literal-float-type-was-used-but-a-const-int-is-expected">Cannot call ‘input.int’ with argument ‘minval’=‘%value%‘. An argument of ‘literal float’ type was used but a ‘const int’ is expected<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>In v4, it was possible to pass a “float” argument to <code dir="auto">minval</code> when an “int” value was being input. This is no longer possible in v5; “int” values are required for “int” inputs:</p> <div class="pine-colorizer not-content">// Works in v4, will break on conversion because minval is a &#39;float&#39; value int_input = input(1, &quot;Integer&quot;, input.integer, minval = 1.0) // Works in v5 int_input = input.int(1, &quot;Integer&quot;, minval = 1)</div> <p>See the User Manual’s page on <a href="/pine-script-docs/concepts/inputs/">Inputs</a>, and the <a href="/pine-script-docs/migration-guides/to-pine-version-5#some-function-parameters-now-require-built-in-arguments">Some function parameters now require built-in arguments</a> section of this guide for more information.</p> <h2 id="all-variable-function-and-parameter-name-changes" class="md-heading"><a href="#all-variable-function-and-parameter-name-changes">All variable, function, and parameter name changes<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> <h3 id="removed-functions-and-variables" class="md-heading"><a href="#removed-functions-and-variables">Removed functions and variables<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> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">input.bool</code> input</td><td>Replaced by <code dir="auto">input.bool()</code></td></tr><tr><td><code dir="auto">input.color</code> input</td><td>Replaced by <code dir="auto">input.color()</code></td></tr><tr><td><code dir="auto">input.float</code> input</td><td>Replaced by <code dir="auto">input.float()</code></td></tr><tr><td><code dir="auto">input.integer</code> input</td><td>Replaced by <code dir="auto">input.int()</code></td></tr><tr><td><code dir="auto">input.resolution</code> input</td><td>Replaced by <code dir="auto">input.timeframe()</code></td></tr><tr><td><code dir="auto">input.session</code> input</td><td>Replaced by <code dir="auto">input.session()</code></td></tr><tr><td><code dir="auto">input.source</code> input</td><td>Replaced by <code dir="auto">input.source()</code></td></tr><tr><td><code dir="auto">input.string</code> input</td><td>Replaced by <code dir="auto">input.string()</code></td></tr><tr><td><code dir="auto">input.symbol</code> input</td><td>Replaced by <code dir="auto">input.symbol()</code></td></tr><tr><td><code dir="auto">input.time</code> input</td><td>Replaced by <code dir="auto">input.time()</code></td></tr><tr><td><code dir="auto">iff()</code></td><td>Use the <code dir="auto">?:</code> operator instead</td></tr><tr><td><code dir="auto">offset()</code></td><td>Use the <code dir="auto">[]</code> operator instead</td></tr></tbody></table> <h3 id="renamed-functions-and-parameters" class="md-heading"><a href="#renamed-functions-and-parameters">Renamed functions and parameters<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> <h4 id="no-namespace-change" class="md-heading"><a href="#no-namespace-change">No namespace change<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></h4> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">study(&lt;...&gt;, resolution, resolution_gaps, &lt;...&gt;)</code></td><td><code dir="auto">indicator(&lt;...&gt;, timeframe, timeframe_gaps, &lt;...&gt;)</code></td></tr><tr><td><code dir="auto">strategy.entry(long)</code></td><td><code dir="auto">strategy.entry(direction)</code></td></tr><tr><td><code dir="auto">strategy.order(long)</code></td><td><code dir="auto">strategy.order(direction)</code></td></tr><tr><td><code dir="auto">time(resolution)</code></td><td><code dir="auto">time(timeframe)</code></td></tr><tr><td><code dir="auto">time_close(resolution)</code></td><td><code dir="auto">time_close(timeframe)</code></td></tr><tr><td><code dir="auto">nz(x, y)</code></td><td><code dir="auto">nz(source, replacement)</code></td></tr></tbody></table> <h4 id="ta-namespace-for-technical-analysis-functions-and-variables" class="md-heading"><a href="#ta-namespace-for-technical-analysis-functions-and-variables">”ta” namespace for technical analysis functions and variables<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></h4> <h5 id="indicator-functions-and-variables" class="md-heading"><a href="#indicator-functions-and-variables">Indicator functions and variables<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></h5> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">accdist</code></td><td><code dir="auto">ta.accdist</code></td></tr><tr><td><code dir="auto">alma()</code></td><td><code dir="auto">ta.alma()</code></td></tr><tr><td><code dir="auto">atr()</code></td><td><code dir="auto">ta.atr()</code></td></tr><tr><td><code dir="auto">bb()</code></td><td><code dir="auto">ta.bb()</code></td></tr><tr><td><code dir="auto">bbw()</code></td><td><code dir="auto">ta.bbw()</code></td></tr><tr><td><code dir="auto">cci()</code></td><td><code dir="auto">ta.cci()</code></td></tr><tr><td><code dir="auto">cmo()</code></td><td><code dir="auto">ta.cmo()</code></td></tr><tr><td><code dir="auto">cog()</code></td><td><code dir="auto">ta.cog()</code></td></tr><tr><td><code dir="auto">dmi()</code></td><td><code dir="auto">ta.dmi()</code></td></tr><tr><td><code dir="auto">ema()</code></td><td><code dir="auto">ta.ema()</code></td></tr><tr><td><code dir="auto">hma()</code></td><td><code dir="auto">ta.hma()</code></td></tr><tr><td><code dir="auto">iii</code></td><td><code dir="auto">ta.iii</code></td></tr><tr><td><code dir="auto">kc()</code></td><td><code dir="auto">ta.kc()</code></td></tr><tr><td><code dir="auto">kcw()</code></td><td><code dir="auto">ta.kcw()</code></td></tr><tr><td><code dir="auto">linreg()</code></td><td><code dir="auto">ta.linreg()</code></td></tr><tr><td><code dir="auto">macd()</code></td><td><code dir="auto">ta.macd()</code></td></tr><tr><td><code dir="auto">mfi()</code></td><td><code dir="auto">ta.mfi()</code></td></tr><tr><td><code dir="auto">mom()</code></td><td><code dir="auto">ta.mom()</code></td></tr><tr><td><code dir="auto">nvi</code></td><td><code dir="auto">ta.nvi</code></td></tr><tr><td><code dir="auto">obv</code></td><td><code dir="auto">ta.obv</code></td></tr><tr><td><code dir="auto">pvi</code></td><td><code dir="auto">ta.pvi</code></td></tr><tr><td><code dir="auto">pvt</code></td><td><code dir="auto">ta.pvt</code></td></tr><tr><td><code dir="auto">rma()</code></td><td><code dir="auto">ta.rma()</code></td></tr><tr><td><code dir="auto">roc()</code></td><td><code dir="auto">ta.roc()</code></td></tr><tr><td><code dir="auto">rsi(x, y)</code></td><td><code dir="auto">ta.rsi(source, length)</code></td></tr><tr><td><code dir="auto">sar()</code></td><td><code dir="auto">ta.sar()</code></td></tr><tr><td><code dir="auto">sma()</code></td><td><code dir="auto">ta.sma()</code></td></tr><tr><td><code dir="auto">stoch()</code></td><td><code dir="auto">ta.stoch()</code></td></tr><tr><td><code dir="auto">supertrend()</code></td><td><code dir="auto">ta.supertrend()</code></td></tr><tr><td><code dir="auto">swma(x)</code></td><td><code dir="auto">ta.swma(source)</code></td></tr><tr><td><code dir="auto">tr</code></td><td><code dir="auto">ta.tr</code></td></tr><tr><td><code dir="auto">tr()</code></td><td><code dir="auto">ta.tr()</code></td></tr><tr><td><code dir="auto">tsi()</code></td><td><code dir="auto">ta.tsi()</code></td></tr><tr><td><code dir="auto">vwap</code></td><td><code dir="auto">ta.vwap</code></td></tr><tr><td><code dir="auto">vwap(x)</code></td><td><code dir="auto">ta.vwap(source)</code></td></tr><tr><td><code dir="auto">vwma()</code></td><td><code dir="auto">ta.vwma()</code></td></tr><tr><td><code dir="auto">wad</code></td><td><code dir="auto">ta.wad</code></td></tr><tr><td><code dir="auto">wma()</code></td><td><code dir="auto">ta.wma()</code></td></tr><tr><td><code dir="auto">wpr()</code></td><td><code dir="auto">ta.wpr()</code></td></tr><tr><td><code dir="auto">wvad</code></td><td><code dir="auto">ta.wvad</code></td></tr></tbody></table> <h5 id="supporting-functions" class="md-heading"><a href="#supporting-functions">Supporting functions<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></h5> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">barsince()</code></td><td><code dir="auto">ta.barsince()</code></td></tr><tr><td><code dir="auto">change()</code></td><td><code dir="auto">ta.change()</code></td></tr><tr><td><code dir="auto">correlation(source_a, source_b, length)</code></td><td><code dir="auto">ta.correlation(source1, source2, length)</code></td></tr><tr><td><code dir="auto">cross(x, y)</code></td><td><code dir="auto">ta.cross(source1, source2)</code></td></tr><tr><td><code dir="auto">crossover(x, y)</code></td><td><code dir="auto">ta.crossover(source1, source2)</code></td></tr><tr><td><code dir="auto">crossunder(x, y)</code></td><td><code dir="auto">ta.crossunder(source1, source2)</code></td></tr><tr><td><code dir="auto">cum(x)</code></td><td><code dir="auto">ta.cum(source)</code></td></tr><tr><td><code dir="auto">dev()</code></td><td><code dir="auto">ta.dev()</code></td></tr><tr><td><code dir="auto">falling()</code></td><td><code dir="auto">ta.falling()</code></td></tr><tr><td><code dir="auto">highest()</code></td><td><code dir="auto">ta.highest()</code></td></tr><tr><td><code dir="auto">highestbars()</code></td><td><code dir="auto">ta.highestbars()</code></td></tr><tr><td><code dir="auto">lowest()</code></td><td><code dir="auto">ta.lowest()</code></td></tr><tr><td><code dir="auto">lowestbars()</code></td><td><code dir="auto">ta.lowestbars()</code></td></tr><tr><td><code dir="auto">median()</code></td><td><code dir="auto">ta.median()</code></td></tr><tr><td><code dir="auto">mode()</code></td><td><code dir="auto">ta.mode()</code></td></tr><tr><td><code dir="auto">percentile_linear_interpolation()</code></td><td><code dir="auto">ta.percentile_linear_interpolation()</code></td></tr><tr><td><code dir="auto">percentile_nearest_rank()</code></td><td><code dir="auto">ta.percentile_nearest_rank()</code></td></tr><tr><td><code dir="auto">percentrank()</code></td><td><code dir="auto">ta.percentrank()</code></td></tr><tr><td><code dir="auto">pivothigh()</code></td><td><code dir="auto">ta.pivothigh()</code></td></tr><tr><td><code dir="auto">pivotlow()</code></td><td><code dir="auto">ta.pivotlow()</code></td></tr><tr><td><code dir="auto">range()</code></td><td><code dir="auto">ta.range()</code></td></tr><tr><td><code dir="auto">rising()</code></td><td><code dir="auto">ta.rising()</code></td></tr><tr><td><code dir="auto">stdev()</code></td><td><code dir="auto">ta.stdev()</code></td></tr><tr><td><code dir="auto">valuewhen()</code></td><td><code dir="auto">ta.valuewhen()</code></td></tr><tr><td><code dir="auto">variance()</code></td><td><code dir="auto">ta.variance()</code></td></tr></tbody></table> <h4 id="math-namespace-for-math-related-functions-and-variables" class="md-heading"><a href="#math-namespace-for-math-related-functions-and-variables">”math” namespace for math-related functions and variables<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></h4> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">abs(x)</code></td><td><code dir="auto">math.abs(number)</code></td></tr><tr><td><code dir="auto">acos(x)</code></td><td><code dir="auto">math.acos(number)</code></td></tr><tr><td><code dir="auto">asin(x)</code></td><td><code dir="auto">math.asin(number)</code></td></tr><tr><td><code dir="auto">atan(x)</code></td><td><code dir="auto">math.atan(number)</code></td></tr><tr><td><code dir="auto">avg()</code></td><td><code dir="auto">math.avg()</code></td></tr><tr><td><code dir="auto">ceil(x)</code></td><td><code dir="auto">math.ceil(number)</code></td></tr><tr><td><code dir="auto">cos(x)</code></td><td><code dir="auto">math.cos(angle)</code></td></tr><tr><td><code dir="auto">exp(x)</code></td><td><code dir="auto">math.exp(number)</code></td></tr><tr><td><code dir="auto">floor(x)</code></td><td><code dir="auto">math.floor(number)</code></td></tr><tr><td><code dir="auto">log(x)</code></td><td><code dir="auto">math.log(number)</code></td></tr><tr><td><code dir="auto">log10(x)</code></td><td><code dir="auto">math.log10(number)</code></td></tr><tr><td><code dir="auto">max()</code></td><td><code dir="auto">math.max()</code></td></tr><tr><td><code dir="auto">min()</code></td><td><code dir="auto">math.min()</code></td></tr><tr><td><code dir="auto">pow()</code></td><td><code dir="auto">math.pow()</code></td></tr><tr><td><code dir="auto">random()</code></td><td><code dir="auto">math.random()</code></td></tr><tr><td><code dir="auto">round(x, precision)</code></td><td><code dir="auto">math.round(number, precision)</code></td></tr><tr><td><code dir="auto">round_to_mintick(x)</code></td><td><code dir="auto">math.round_to_mintick(number)</code></td></tr><tr><td><code dir="auto">sign(x)</code></td><td><code dir="auto">math.sign(number)</code></td></tr><tr><td><code dir="auto">sin(x)</code></td><td><code dir="auto">math.sin(angle)</code></td></tr><tr><td><code dir="auto">sqrt(x)</code></td><td><code dir="auto">math.sqrt(number)</code></td></tr><tr><td><code dir="auto">sum()</code></td><td><code dir="auto">math.sum()</code></td></tr><tr><td><code dir="auto">tan(x)</code></td><td><code dir="auto">math.tan(angle)</code></td></tr><tr><td><code dir="auto">todegrees()</code></td><td><code dir="auto">math.todegrees()</code></td></tr><tr><td><code dir="auto">toradians()</code></td><td><code dir="auto">math.toradians()</code></td></tr></tbody></table> <h4 id="request-namespace-for-functions-that-request-external-data" class="md-heading"><a href="#request-namespace-for-functions-that-request-external-data">”request” namespace for functions that request external data<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></h4> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">financial()</code></td><td><code dir="auto">request.financial()</code></td></tr><tr><td><code dir="auto">quandl()</code></td><td><code dir="auto">request.quandl()</code></td></tr><tr><td><code dir="auto">security(&lt;...&gt;, resolution, &lt;...&gt;)</code></td><td><code dir="auto">request.security(&lt;...&gt;, timeframe, &lt;...&gt;)</code></td></tr><tr><td><code dir="auto">splits()</code></td><td><code dir="auto">request.splits()</code></td></tr><tr><td><code dir="auto">dividends()</code></td><td><code dir="auto">request.dividends()</code></td></tr><tr><td><code dir="auto">earnings()</code></td><td><code dir="auto">request.earnings()</code></td></tr></tbody></table> <h4 id="ticker-namespace-for-functions-that-help-create-tickers" class="md-heading"><a href="#ticker-namespace-for-functions-that-help-create-tickers">”ticker” namespace for functions that help create tickers<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></h4> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">heikinashi()</code></td><td><code dir="auto">ticker.heikinashi()</code></td></tr><tr><td><code dir="auto">kagi()</code></td><td><code dir="auto">ticker.kagi()</code></td></tr><tr><td><code dir="auto">linebreak()</code></td><td><code dir="auto">ticker.linebreak()</code></td></tr><tr><td><code dir="auto">pointfigure()</code></td><td><code dir="auto">ticker.pointfigure()</code></td></tr><tr><td><code dir="auto">renko()</code></td><td><code dir="auto">ticker.renko()</code></td></tr><tr><td><code dir="auto">tickerid()</code></td><td><code dir="auto">ticker.new()</code></td></tr></tbody></table> <h4 id="str-namespace-for-functions-that-manipulate-strings" class="md-heading"><a href="#str-namespace-for-functions-that-manipulate-strings">”str” namespace for functions that manipulate strings<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></h4> <table><thead><tr><th>v4</th><th>v5</th></tr></thead><tbody><tr><td><code dir="auto">tostring(x, y)</code></td><td><code dir="auto">str.tostring(value, format)</code></td></tr><tr><td><code dir="auto">tonumber(x)</code></td><td><code dir="auto">str.tonumber(string)</code></td></tr></tbody></table> </div> <div class="pagination-buttons not-content" data-astro-cid-xgirumru> <a href="/pine-script-docs/migration-guides/to-pine-version-6" 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> To Pine Script™ version 6 </h4> </a> <a href="/pine-script-docs/migration-guides/to-pine-version-4" 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> To Pine Script™ version 4 <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="#v4-to-v5-converter" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>v4 to v5 converter</li></a><a href="#renamed-functions-and-variables" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Renamed functions and variables</li></a><a href="#renamed-function-parameters" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Renamed function parameters</li></a><a href="#removed-an-rsi-overload" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Removed an &#96rsi()&#96 overload</li></a><a href="#reserved-keywords" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Reserved keywords</li></a><a href="#removed-iff-and-offset" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Removed &#96iff()&#96 and &#96offset()&#96</li></a><a href="#split-of-input-into-several-functions" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Split of &#96input()&#96 into several functions</li></a><a href="#some-function-parameters-now-require-built-in-arguments" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Some function parameters now require built-in arguments</li></a><a href="#deprecated-the-transp-parameter" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Deprecated the &#96transp&#96 parameter</li></a><a href="#changed-the-default-session-days-for-time-and-time_close" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Changed the default session days for &#96time()&#96 and &#96time_close()&#96</li></a><a href="#strategyexit-now-must-do-something" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>&#96strategy.exit()&#96 now must do something</li></a><a href="#common-script-conversion-errors" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>Common script conversion errors</li></a><a href="#invalid-argument-stylelinestyle-in-plothline-call" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Invalid argument ‘style’/‘linestyle’ in ‘plot’/‘hline’ call</li></a><a href="#undeclared-identifier-inputinput_name" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Undeclared identifier ‘input.%input_name%’</li></a><a href="#invalid-argument-when-in-strategyclose-call" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Invalid argument ‘when’ in ‘strategy.close’ call</li></a><a href="#cannot-call-inputint-with-argument-minvalvalue-an-argument-of-literal-float-type-was-used-but-a-const-int-is-expected" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Cannot call ‘input.int’ with argument ‘minval’=‘%value%‘. An argument of ‘literal float’ type was used but a ‘const int’ is expected</li></a><a href="#all-variable-function-and-parameter-name-changes" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-2" data-astro-cid-oor6cujd>All variable, function, and parameter name changes</li></a><a href="#removed-functions-and-variables" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Removed functions and variables</li></a><a href="#renamed-functions-and-parameters" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-3" data-astro-cid-oor6cujd>Renamed functions and parameters</li></a><a href="#no-namespace-change" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-4" data-astro-cid-oor6cujd>No namespace change</li></a><a href="#ta-namespace-for-technical-analysis-functions-and-variables" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-4" data-astro-cid-oor6cujd>”ta” namespace for technical analysis functions and variables</li></a><a href="#math-namespace-for-math-related-functions-and-variables" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-4" data-astro-cid-oor6cujd>”math” namespace for math-related functions and variables</li></a><a href="#request-namespace-for-functions-that-request-external-data" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-4" data-astro-cid-oor6cujd>”request” namespace for functions that request external data</li></a><a href="#ticker-namespace-for-functions-that-help-create-tickers" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-4" data-astro-cid-oor6cujd>”ticker” namespace for functions that help create tickers</li></a><a href="#str-namespace-for-functions-that-manipulate-strings" class="document-toc-link" data-astro-cid-oor6cujd><li class="l-4" data-astro-cid-oor6cujd>”str” namespace for functions that manipulate strings</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