{"id":4776,"date":"2020-06-17T16:16:11","date_gmt":"2020-06-17T16:16:11","guid":{"rendered":"http:\/\/joapen.com\/blog\/?p=4776"},"modified":"2020-06-19T08:24:00","modified_gmt":"2020-06-19T08:24:00","slug":"tradingview-pine-limit","status":"publish","type":"post","link":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/","title":{"rendered":"tradingview pine limit"},"content":{"rendered":"<p>I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to make a set of operations.<\/p>\n<p>Something as:<\/p>\n<pre>a = if(Alerta1[-1] == 5, 10,0)<\/pre>\n<p>the pine script is saved without error, but during the execution, an error is shown:<\/p>\n<p><strong><em>Index can&#8217;t be a negative value (-1)<\/em><\/strong><\/p>\n<p>Is there anybody that could let me know how to solve it?<\/p>\n<p>I would like to use &#8220;[-1]&#8221; and other &#8220;minus&#8221; such &#8220;[-20]&#8221; for a script.<\/p>\n<p>many thanks in advance<\/p>\n<h1>The answer<\/h1>\n<p>The answer is as simple that I&#8217;m embarrassed of not being able to see it:<\/p>\n<p><a href=\"https:\/\/www.tradingview.com\/pine-script-docs\/en\/v4\/language\/Operators.html#history-reference-operator\">https:\/\/www.tradingview.com\/pine-script-docs\/en\/v4\/language\/Operators.html#history-reference-operator<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to make a set of operations. Something as: a = if(Alerta1[-1] == 5, 10,0) the pine script is saved without error, but during the execution, an &#8230; <a title=\"tradingview pine limit\" class=\"read-more\" href=\"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/\" aria-label=\"Read more about tradingview pine limit\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[],"class_list":["post-4776","post","type-post","status-publish","format-standard","hentry","category-trading"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>tradingview pine limit -<\/title>\n<meta name=\"description\" content=\"I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to - joapen projects\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"tradingview pine limit -\" \/>\n<meta property=\"og:description\" content=\"I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to - joapen projects\" \/>\n<meta property=\"og:url\" content=\"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/\" \/>\n<meta property=\"og:site_name\" content=\"joapen projects\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-17T16:16:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-19T08:24:00+00:00\" \/>\n<meta name=\"author\" content=\"joapen\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"joapen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/\"},\"author\":{\"name\":\"joapen\",\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/#\\\/schema\\\/person\\\/23919df2312175fe9c4609203595b217\"},\"headline\":\"tradingview pine limit\",\"datePublished\":\"2020-06-17T16:16:11+00:00\",\"dateModified\":\"2020-06-19T08:24:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/\"},\"wordCount\":122,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/#\\\/schema\\\/person\\\/23919df2312175fe9c4609203595b217\"},\"articleSection\":[\"Trading\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/\",\"url\":\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/\",\"name\":\"tradingview pine limit -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/#website\"},\"datePublished\":\"2020-06-17T16:16:11+00:00\",\"dateModified\":\"2020-06-19T08:24:00+00:00\",\"description\":\"I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to - joapen projects\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/2020\\\/06\\\/17\\\/tradingview-pine-limit\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/joapen.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"tradingview pine limit\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/joapen.com\\\/blog\\\/\",\"name\":\"joapen projects\",\"description\":\"Just a place to write\",\"publisher\":{\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/#\\\/schema\\\/person\\\/23919df2312175fe9c4609203595b217\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/joapen.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/#\\\/schema\\\/person\\\/23919df2312175fe9c4609203595b217\",\"name\":\"joapen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/joapen-mini.jpeg\",\"url\":\"https:\\\/\\\/joapen.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/joapen-mini.jpeg\",\"contentUrl\":\"https:\\\/\\\/joapen.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/joapen-mini.jpeg\",\"width\":400,\"height\":400,\"caption\":\"joapen\"},\"logo\":{\"@id\":\"https:\\\/\\\/joapen.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/joapen-mini.jpeg\"},\"sameAs\":[\"http:\\\/\\\/www.joapen.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"tradingview pine limit -","description":"I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to - joapen projects","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/","og_locale":"en_US","og_type":"article","og_title":"tradingview pine limit -","og_description":"I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to - joapen projects","og_url":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/","og_site_name":"joapen projects","article_published_time":"2020-06-17T16:16:11+00:00","article_modified_time":"2020-06-19T08:24:00+00:00","author":"joapen","twitter_misc":{"Written by":"joapen","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/#article","isPartOf":{"@id":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/"},"author":{"name":"joapen","@id":"https:\/\/joapen.com\/blog\/#\/schema\/person\/23919df2312175fe9c4609203595b217"},"headline":"tradingview pine limit","datePublished":"2020-06-17T16:16:11+00:00","dateModified":"2020-06-19T08:24:00+00:00","mainEntityOfPage":{"@id":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/"},"wordCount":122,"commentCount":0,"publisher":{"@id":"https:\/\/joapen.com\/blog\/#\/schema\/person\/23919df2312175fe9c4609203595b217"},"articleSection":["Trading"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/","url":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/","name":"tradingview pine limit -","isPartOf":{"@id":"https:\/\/joapen.com\/blog\/#website"},"datePublished":"2020-06-17T16:16:11+00:00","dateModified":"2020-06-19T08:24:00+00:00","description":"I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to - joapen projects","breadcrumb":{"@id":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/joapen.com\/blog\/2020\/06\/17\/tradingview-pine-limit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/joapen.com\/blog\/"},{"@type":"ListItem","position":2,"name":"tradingview pine limit"}]},{"@type":"WebSite","@id":"https:\/\/joapen.com\/blog\/#website","url":"https:\/\/joapen.com\/blog\/","name":"joapen projects","description":"Just a place to write","publisher":{"@id":"https:\/\/joapen.com\/blog\/#\/schema\/person\/23919df2312175fe9c4609203595b217"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/joapen.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/joapen.com\/blog\/#\/schema\/person\/23919df2312175fe9c4609203595b217","name":"joapen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/joapen.com\/blog\/wp-content\/uploads\/2021\/04\/joapen-mini.jpeg","url":"https:\/\/joapen.com\/blog\/wp-content\/uploads\/2021\/04\/joapen-mini.jpeg","contentUrl":"https:\/\/joapen.com\/blog\/wp-content\/uploads\/2021\/04\/joapen-mini.jpeg","width":400,"height":400,"caption":"joapen"},"logo":{"@id":"https:\/\/joapen.com\/blog\/wp-content\/uploads\/2021\/04\/joapen-mini.jpeg"},"sameAs":["http:\/\/www.joapen.com"]}]}},"_links":{"self":[{"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/posts\/4776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/comments?post=4776"}],"version-history":[{"count":4,"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/posts\/4776\/revisions"}],"predecessor-version":[{"id":4781,"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/posts\/4776\/revisions\/4781"}],"wp:attachment":[{"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/media?parent=4776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/categories?post=4776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joapen.com\/blog\/wp-json\/wp\/v2\/tags?post=4776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}