{"id":1871,"date":"2022-07-03T07:10:00","date_gmt":"2022-07-03T07:10:00","guid":{"rendered":"https:\/\/www.overcharts.com\/en\/helpcenter\/?post_type=docs&#038;p=1871"},"modified":"2022-08-12T10:56:11","modified_gmt":"2022-08-12T10:56:11","password":"","slug":"overbasic-variables-constants-data-types","status":"publish","type":"docs","link":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/","title":{"rendered":"Overbasic &#8211; Variables, Constants &#038; Data Types"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>Data types<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Data types define the type of variable, constant, function argument and the value returned by a function. For example, if a variable is defined as <em>Numeric<\/em>, it will contain a number, if defined as <em>String<\/em> then it will contain a string of characters etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Data type is defined using <strong>AS<\/strong> keyword followed by the data type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong> b <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Data types available in Overbasic are:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Numeric<\/strong>: represents a number. In OverBasic there is no distinction between integers, decimals, etc. Decimal separator is a point &#8220;.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Boolean<\/strong>: represents a Boolean value (TRUE or FALSE)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>String<\/strong>: represents a string of characters<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Database<\/strong>: represents the data series of an instrument<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>TradingSystem<\/strong>: represents a Trading System<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Date<\/strong>: (<em>available ONLY in PROPERTY<\/em>) represents a date in the YYYYMMDD format<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Time<\/strong>: (<em>available ONLY in PROPERTY<\/em>) represents a time in the HHMMSSFFFCCCN format (HH = hour; MM = minutes; SS = seconds; FFF = milliseconds; CCC = microseconds; N = 100 nanoseconds)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Indicator<\/strong>: (<em>available ONLY in PROPERTY<\/em>) represents an indicator.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Variable<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A variable is an object containing data (a number, boolean, string, etc.). Variables can be used in any expression in the Overbasic script (within <a href=\"#5-toc-title\"><strong>variable scope<\/strong><\/a>).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Syntax<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Before being used, a variable must be <em>declared<\/em>, that is, Overbasic must be informed of its existence and the type of data it can contain. Variable declaration is done using <strong>DIM<\/strong> keyword followed by the variable name, data type and initialization value\/expression (<em>optional<\/em>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong>Dim<\/strong><\/mark> &lt;variable name> <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong>As<\/strong><\/mark> &lt;data type>&#91;()] = &#91;&lt;initialization value\/expression>]<\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Variable name:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>must be unique within the script<\/li><li>can be any string of letters and numbers<\/li><li>CANNOT be an Overbasic keyword, or the name of a function, argument, etc.<\/li><\/ul>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong> a <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark> = 10\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#3fad1d\" class=\"has-inline-color\">'10 is the initialization value<\/mark><\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Array<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An array is an ordered collection (a series) of items of the same type. Access to an array item is via its numeric index. The first item of an array always has index 0 (zero).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"619\" height=\"244\" src=\"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array.png\" alt=\"\" class=\"wp-image-1879\" srcset=\"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array.png 619w, https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array-400x158.png 400w\" sizes=\"auto, (max-width: 619px) 100vw, 619px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A variable can be declared as an <em>array<\/em> by adding round brackets to the data type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong> a <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark>()<\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">An array can be <strong>initialized in 2 different ways<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>By item:<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3fad1d\" class=\"has-inline-color\">'Each array item is initialized to 10.<\/mark>\n<strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong> a <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark>() = 10<\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><em>With another array:<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong><\/strong><\/mark> a1 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/strong><\/mark>() = 10\na1(5) = 23 <mark style=\"background-color:rgba(0, 0, 0, 0);color:#3fad1d\" class=\"has-inline-color\">'let's use a1 at least once before assigning it to a2<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong><\/strong><\/mark> a2 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/strong><\/mark>() = a1<\/code><\/pre>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Array a2 is initialized with array a1. In this case it is not an initialization, but an assignment by reference. In other words, a1 and a2 actually represent the same object and therefore a subsequent modification to an element of a1 will be reflected on the same element of a2. The above is valid ONLY if a1 has been used at least once before being assigned to a2. This is because arrays in Overbasic are created and therefore only really exist when they are first used.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>It is not necessary to define the array size. The size is automatically managed by Overbasic.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Access to an array item is via its numeric index. The first item of an array always has index 0 (zero):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong><\/strong><\/mark> a1 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/strong><\/mark>() = 10\na1(5) = 23 <mark style=\"background-color:rgba(0, 0, 0, 0);color:#3fad1d\" class=\"has-inline-color\">'this line assigns the value 23 to item 5 of array a1<\/mark><\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">To delete all array items, use <strong>ERASE<\/strong> keyword:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Erase<\/mark><\/strong> a1<\/code><\/pre>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Constant<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A constant is an object containing data that <strong>does not change<\/strong> during script execution.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Syntax<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Before being used, a constant must be <em>declared<\/em>, i.e. Overbasic must be informed of its existence, data type and value. Constant declaration is done using <strong>CONST<\/strong> keyword followed by the constant name, data type and value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Const<\/mark><\/strong> &lt;constant name&gt; <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">As<\/mark><\/strong> &lt;data type&gt; = &lt;value\/expression&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Costante name:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>must be unique within the script<\/li><li>can be any string of letters and numbers<\/li><li>CANNOT be an Overbasic keyword, or the name of a function, argument, etc.<\/li><\/ul>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>Const<\/strong><\/mark> a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/strong><\/mark> = 10<\/code><\/pre>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Scope<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Scope is the region in which a variable\/constant is valid and can be used. In other words, <strong>a variable\/constant can only be used in the context in which it was declared<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If declaration is module level (<strong>outside of all functions<\/strong>), variable\/constant is valid everywhere in the script and its value is NOT initialized every time the script is run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong><\/strong><\/mark> a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/strong><\/mark> = 10\n\n<strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Function Main<\/mark><\/strong>()\n    ...\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">If<\/mark><\/strong> (a = 10) <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Then<\/mark><\/strong>\n        ...\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndIf<\/mark><\/strong>\n    ...\n<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndFunction<\/mark><\/strong><\/mark><\/strong>\n\n<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Function<\/mark><\/strong><\/mark><\/strong><\/mark><\/strong> CalculateABS <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/mark><\/strong>\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">If<\/mark><\/strong><\/mark><\/strong> (a &lt; 0) <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Then<\/mark><\/strong><\/mark><\/strong>\n        <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Return<\/mark><\/strong> -1 * a\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndIf<\/mark><\/strong>\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Return<\/mark><\/strong><\/mark><\/strong> a\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndFunction<\/mark><\/strong><\/strong><\/mark><\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">If declaration is <strong>internal to a function<\/strong>, variable\/constant will be valid only internally to the function and only in statements following its declaration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Function<\/mark><\/strong><\/mark><\/strong> <\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Main<\/mark><\/strong>()\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong><\/mark><\/strong> a <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/mark><\/strong> = 10\n    ...\n    <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">If<\/mark><\/strong><\/strong><\/mark> (a = 10) <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Then<\/mark><\/strong><\/mark><\/strong>\n        ...\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndIf<\/mark><\/strong><\/mark><\/strong>\n    ...\n<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndFunction<\/mark><\/strong><\/mark><\/strong><\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">If a variable is declared inside an IF, FOR, DO UNTIL, WHILE, SELECT CASE etc, it can only be used in the context in which it was declared:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Function<\/mark><\/strong><\/mark><\/strong> <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Main<\/mark><\/strong><\/mark><\/strong>()\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong><\/mark><\/strong> b <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">As Boolean<\/mark><\/strong> = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>True<\/strong><\/mark>\n    ...\n    <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">If<\/mark><\/strong><\/strong><\/mark> (b = <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>True<\/strong><\/mark>) <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Then<\/mark><\/strong><\/mark><\/strong>\n        <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Dim<\/mark><\/strong><\/mark><\/strong> a <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>As<\/strong> <strong>Numeric<\/strong><\/mark><\/mark><\/strong> = 10\n        ...\n        a = Close\n        ...\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndIf<\/mark><\/strong><\/mark><\/strong>\n    ...\n    a = 10 * High <mark style=\"background-color:rgba(0, 0, 0, 0);color:#e3615a\" class=\"has-inline-color\">'ERROR! It is NOT possible to use the variable outside the IF where it was declared<\/mark>\n    ...\n<strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndFunction<\/mark><\/strong><\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Static<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A variable declared inside a function will be initialized each time the script is executed. However, in particular situations, it can be useful to keep its last value avoiding reinitialization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this you have 2 possibilities:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>You declare a module-level variable (outside of all functions)<\/li><li>You declare a variable within the function using <strong>STATIC<\/strong> keyword instead of DIM keyword:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>St<strong>atic<\/strong><\/strong><\/mark> n <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">As Numeric<\/mark><\/strong> = 0<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Function<\/mark><\/strong><\/mark><\/strong> <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Main<\/mark><\/strong><\/mark><\/strong>()\n    ...\n    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#3fad1d\" class=\"has-inline-color\">'Initialization to 0 only occurs the first time.\n    'In the following runs, last previous value is kept<\/mark>\n    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\"><strong>S<strong>tatic<\/strong><\/strong><\/mark> n <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">As Numeric<\/mark><\/strong> = 0\n    ...\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">If<\/mark><\/strong><\/mark><\/strong> (Open &gt; Close) <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Then<\/mark><\/strong><\/mark><\/strong>\n        n = n + 1\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndIf<\/mark><\/strong><\/mark><\/strong>\n    ...\n    ...\n    <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">Return<\/mark><\/strong><\/mark><\/strong> n\n<strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0088cd\" class=\"has-inline-color\">EndFunction<\/mark><\/strong><\/code><\/pre>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Data types Data types define the type of variable, constant, function argument and the value returned by a function. For example, if a variable is defined as Numeric, it will contain a number, if defined as String then it will contain a string of characters etc. Data type is defined using AS keyword followed by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[16],"doc_tag":[],"class_list":["post-1871","docs","type-docs","status-publish","hentry","doc_category-syntax-keywords"],"year_month":"2026-10","word_count":909,"total_views":"6","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"Overcharts Team","author_nicename":"overadmin","author_url":"https:\/\/www.overcharts.com\/en\/helpcenter\/author\/overadmin\/"},"doc_category_info":[{"term_name":"Syntax &amp; Keywords","term_url":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs-category\/syntax-keywords\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\r\n<title>Overbasic - Variables, Constants &amp; Data Types - Overcharts Help Center<\/title>\r\n<meta name=\"description\" content=\"Variables, Constants, and Data Types in the Overbasic programming language.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Overbasic - Variables, Constants &amp; Data Types - Overcharts Help Center\" \/>\r\n<meta property=\"og:description\" content=\"Variables, Constants, and Data Types in the Overbasic programming language.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/\" \/>\r\n<meta property=\"og:site_name\" content=\"Overcharts Help Center\" \/>\r\n<meta property=\"article:modified_time\" content=\"2022-08-12T10:56:11+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array.png\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/\",\"url\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/\",\"name\":\"Overbasic - Variables, Constants & Data Types - Overcharts Help Center\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Array.png\",\"datePublished\":\"2022-07-03T07:10:00+00:00\",\"dateModified\":\"2022-08-12T10:56:11+00:00\",\"description\":\"Variables, Constants, and Data Types in the Overbasic programming language.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Array.png\",\"contentUrl\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Array.png\",\"width\":619,\"height\":244},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/docs\\\/overbasic-variables-constants-data-types\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Overbasic &#8211; Variables, Constants &#038; Data Types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/#website\",\"url\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/\",\"name\":\"Overcharts Help Center\",\"description\":\"Trading Software &amp; Technical Analysis\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.overcharts.com\\\/en\\\/helpcenter\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Overbasic - Variables, Constants & Data Types - Overcharts Help Center","description":"Variables, Constants, and Data Types in the Overbasic programming language.","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:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/","og_locale":"en_US","og_type":"article","og_title":"Overbasic - Variables, Constants & Data Types - Overcharts Help Center","og_description":"Variables, Constants, and Data Types in the Overbasic programming language.","og_url":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/","og_site_name":"Overcharts Help Center","article_modified_time":"2022-08-12T10:56:11+00:00","og_image":[{"url":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/","url":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/","name":"Overbasic - Variables, Constants & Data Types - Overcharts Help Center","isPartOf":{"@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/#primaryimage"},"image":{"@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/#primaryimage"},"thumbnailUrl":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array.png","datePublished":"2022-07-03T07:10:00+00:00","dateModified":"2022-08-12T10:56:11+00:00","description":"Variables, Constants, and Data Types in the Overbasic programming language.","breadcrumb":{"@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/#primaryimage","url":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array.png","contentUrl":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-content\/uploads\/2022\/07\/Array.png","width":619,"height":244},{"@type":"BreadcrumbList","@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/docs\/overbasic-variables-constants-data-types\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.overcharts.com\/en\/helpcenter\/"},{"@type":"ListItem","position":2,"name":"Overbasic &#8211; Variables, Constants &#038; Data Types"}]},{"@type":"WebSite","@id":"https:\/\/www.overcharts.com\/en\/helpcenter\/#website","url":"https:\/\/www.overcharts.com\/en\/helpcenter\/","name":"Overcharts Help Center","description":"Trading Software &amp; Technical Analysis","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.overcharts.com\/en\/helpcenter\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/docs\/1871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/comments?post=1871"}],"version-history":[{"count":19,"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/docs\/1871\/revisions"}],"predecessor-version":[{"id":1902,"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/docs\/1871\/revisions\/1902"}],"wp:attachment":[{"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/media?parent=1871"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/doc_category?post=1871"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.overcharts.com\/en\/helpcenter\/wp-json\/wp\/v2\/doc_tag?post=1871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}