Lesson Summary
How to declare variables
Common data types in Pine Script
A variable is a way to label and store a value in memory so that it can be used later in the program. Variables can be updated, modified, and accessed throughout the program's execution. We use the “ = ” to create a variable.
Variable_name = Value
When naming variables, there are some important things to know.
The name must begin with a letter (upper or lowercase) or a an underscore “_”
They are case sensitive
Any character after the first can be a number
Examples
Variables in programming have a data type associated with them, which specifies the type of data that can be stored in that variable, and how those values can be used.
Before we dive into data types make sure you are subscribed so that you don’t miss any future updates!
These are the most common data types you will see in Pine Script:
Integer: a whole number, such as 1, 2, 3, etc.
Float: a number with a decimal point, such as 1.5, 2.3, 3.14159, etc.
Boolean: a true/false value, represented by the keywords true and false.
Color: can be either a built in color or custom color by using hex colors or rgb.
String: a sequence of characters enclosed in quotes, such as "hello", "world", "stocks", etc.
Next week, we will take a look at getting user inputs and creating a nice settings menu for indicators.
Thanks for reading! I plan on putting out a lot more content on Pine Script very soon. If you enjoyed this article please help support my work by doing the following:
Follow me on Twitter @amphtrading
Share this post using the button below
The content presented is for informational and educational purposes only. Nothing contained in this newsletter should be construed as financial advice or a recommendation to buy or sell any security. Please do your own due diligence or contact a licensed financial advisor as participating in the financial markets involves risk.