create account

Getting Started With Pine Script by geekgirl

View this thread on: hive.blogpeakd.comecency.com
· @geekgirl ·
$15.66
Getting Started With Pine Script
<center> ![pinescript.png](https://cdn.steemitimages.com/DQmdsPfx8tPtTntfAqbYwsUmPag4xPjNt1AKMoCcJ9pJ3bZ/pinescript.png)</center>

Pine Script is a scripting language built for developing trading chart indicators and backtesting trading ideas on Tradingview. If you are not familiar with the Tradingview platform you may want to read [Getting Started with Tradingview](https://steemit.com/crypto/@geekgirl/getting-started-with-tradingview) first. In short, Tradingview is a social networking platform where users can share their trading ideas. It provides users with powerful charting tools such as real-time charts for various financial assets including cryptocurrencies, advanced drawing tools, programming tools, etc. 

Pine Script is developed by Tradingview and only works on their platform. It is not a general-purpose programming language. It only works on Tradingview. It has only one purpose - to provide Tradingview users with programming capabilities for developing indicators and backtesting their strategies on the platform. The platform has an easy-to-use editor to write the scripts, and all scripts are run in the cloud. Because it is cloud-based, and computing is provided mainly for free they may impose certain limits to ensure a smooth experience to all users. I have been experimenting with it a little bit, and so far have not experienced any limitations.

<center>**Why learn Pine Script?**</center>

Those who already use the platform for various reasons like looking up prices, drawing on charts, following trading ideas will be able to take advantage of the platform to the fullest. Even if you don't write your own scripts, just being able to run publicly shared scripts will beneficial. Ability to read and be able to interpret the scripts, and the logic of what they are doing may help to understand commonly used indicators like RSI, MACD, moving averages, and more. It is up to the user to decide to what extent they would like to learn and implement their knowledge Pine Script. There sure are benefits for those who already use the platform.

Those who don't use the Tradingview platform yet but are crypto enthusiasts or traders may find it to be familiar as well. Tradingview supports third-party apps and websites, and there are many who utilized their charting tools on their website. Of course, Tradingview charts are not limited to cryptocurrencies, and the provide data/charts for many financial assets like stocks and futures markets. Normally those charts on third-party apps and websites are limited to charts and main indicators and do not provide the ability to run scripts.

Compared to other programming languages Pine Script easier to learn. There are many freelancing opportunities for Pine Script programmers. You may even have some friends who have trading ideas and strategies but don't know how to code it. Unlike other programming languages, Pine Script programmers do not need to learn several libraries and other technologies to become proficient in it. Just knowing the core language syntax, rules, logic, and getting familiar with built-in functions might be sufficient enough.

If you were to write code to build indicators on general programming languages like python or javascript, two of the main things you will have to learn would be how to get historic and realtime price data and how to plot them. While this may give more flexibility, it will also require a lot of time and effort. In Pine Script all the necessary price data is already available and plotting the final results is super easy with the use of the ***plot()*** function. Built-in variables like ***close, open, high, low, time,*** and ***volume*** will return the relevant data. 

Oh and Pine Script is fun.

<center>**Basics of the language to start with**</center>

They actively continue developing and improving Pine Script. Over the years they have developed four versions. These versions are not inter-compatible with each other. The code written in version 4 may not run on 3 or vice-versa. A good practice is to use the latest version. However, from time to time you may see scripts shared by community members in the older versions. As long as the version is stated at the beginning of the code, older version codes will run just fine. If the version is not specified, it defaults to version 1. To declare the version of your code you would simply write the following line.

`//@version=4`

The next thing you will need to specify is if the code is a study or a strategy. This would go in the following line.

`study("My First Script")` 

or 

`strategy("My First Strategy")`

The difference between study and strategy is that study is used for building and plotting indicators, while strategy is used for backtesting. I personally have not used strategies yet. If you are a beginner you will probably start with study. Just remember every Pine Script code starts with either ***study()*** or ***strategy()*** function.

Pine Script codes will mainly consist of variables and functions. There are no classes, complex data structures, and object-oriented notions like in other programming languages. All you need to master is how to use variables and functions. 

Variables will contain our data to be computed. Among primitives data types are ***integers, floats, booleans, strings***. These are all easy to grasp. If you have done any programming chances are you already know them. The core data type on Pine Script is ***series***. You may want to spend some extra time and effort to understand what they are and how they work. These are lists of values. However, they do not behave the same way as lists and arrays do in other programming languages. 

For example, ***close*** is a built-in variable that holds a list of closing prices. When applied to a certain asset at a certain timeframe it will return the closing prices for each bar. In other programming languages to access individual values in the list we do something like this:

`close[1] or close[5]`

You would think it would return the value at the provided index. It doesn't. Using [x] will return another series with prices being shifted in the index and some turned into a special value ***na*** (not available).  

Let's say our ***close*** has 5 prices inside, (10, 10.5, 11, 9, 9.5). ***close[1]*** will have (na, 10, 10.5, 11, 9).

If it seems complicated, don't worry, it kinda is. But after experimenting a little bit, it starts making sense.

Then we have functions. There are many built-in functions already available so we don't have to re-invent the wheel. At times though we want to create our own custom function. A simple example of a function may look like this:

`f(a,b) => a + b`

Here, our ***f*** function has two arguments ***a, b***. Our function will return the sum of ***a*** and ***b***. Functions are straightforward and are easy to understand and use.

An important thing to know about functions in Pine Script that they are distinguished in two categories: ***functions*** and ***annotations***. While they both are still considered functions, the difference is functions are used to calculate values and often return a new value. Annotations are usually used to output the end result of our code, get input from users, and assign global properties. All annotations are built-in, we don't get to code them ourselves, we just use them. Functions can be built-in as well. We create our own functions for different calculations within our code.

I hope to write about various aspects of Pine Script more in more detail in the future as I continue learning and experimenting. This is not an educational material, but more of a documentation of my journey in learning the language for future reference. If you have experience with Pine Script and would like to share some tips and tricks I would appreciate it.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 199 others
👎  , ,
properties (23)
authorgeekgirl
permlinkgetting-started-with-pine-script
categoryprogramming
json_metadata{"tags":["programming","trading","stem","neoxian","palnet"],"image":["https://cdn.steemitimages.com/DQmdsPfx8tPtTntfAqbYwsUmPag4xPjNt1AKMoCcJ9pJ3bZ/pinescript.png"],"links":["https://steemit.com/crypto/@geekgirl/getting-started-with-tradingview"],"app":"steemit/0.1","format":"markdown"}
created2020-02-01 17:35:06
last_update2020-02-01 17:35:06
depth0
children8
last_payout2020-02-08 17:35:06
cashout_time1969-12-31 23:59:59
total_payout_value8.617 HBD
curator_payout_value7.040 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,840
author_reputation1,588,017,773,177,039
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,999,431
net_rshares55,342,138,501,115
author_curate_reward""
vote details (266)
@avare ·
!COFFEEA $trdo
For you 
👍  
properties (23)
authoravare
permlinkre-geekgirl-202022t18361959z
categoryprogramming
json_metadata{"tags":["programming","trading","stem","neoxian","palnet"],"app":"esteem/2.2.4-mobile","format":"markdown+html","community":"hive-125125"}
created2020-02-02 15:35:21
last_update2020-02-02 15:35:21
depth1
children1
last_payout2020-02-09 15:35:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length23
author_reputation30,667,607,216,522
root_title"Getting Started With Pine Script"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,025,309
net_rshares1,429,922,801
author_curate_reward""
vote details (1)
@trendotoken ·
Congratulations @avare, you successfuly trended the post shared by @geekgirl!
@geekgirl will receive <b>0.13923900</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) & @avare will get <b>0.09282600</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation in 3 Days from Post Created Date!

<b>"Call [TRDO](https://steem-engine.com/?p=history&t=TRDO), Your Comment Worth Something!"</b>
---
<sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO)
Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
properties (22)
authortrendotoken
permlinkre-avare-re-geekgirl-202022t18361959z-20200202t153529952z
categoryprogramming
json_metadata{"tags":["comments-scot","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"}
created2020-02-02 15:35:30
last_update2020-02-02 15:35:30
depth2
children0
last_payout2020-02-09 15:35:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length612
author_reputation5,546,209,053,433
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,025,313
net_rshares0
@churchofgod ·
# According to the Bible, *Will animals and pets go to heaven? (Part 4 of 4)*
***(Sorry for sending this comment. We are not looking for our self profit, our intentions is to preach the words of God in any means possible.)***
https://youtu.be/w7gmfQcyZBM
https://i.postimg.cc/SxmKZFY2/image.jpg
Comment what you understand of our Youtube Video to receive our full votes. We have 30,000 #SteemPower. It's our little way to **Thank you, our beloved friend.**  
Check our [Discord Chat](https://discord.gg/vzHFNd6) 
Join our Official Community: https://beta.steemit.com/trending/hive-182074
👍  
properties (23)
authorchurchofgod
permlinkjmiampg4yw
categoryprogramming
json_metadata""
created2020-02-01 17:43:21
last_update2020-02-01 17:43:21
depth1
children0
last_payout2020-02-08 17:43:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length589
author_reputation-6,077,691,794,793
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout10,000.000 HBD
percent_hbd100
post_id94,999,625
net_rshares758,823,847
author_curate_reward""
vote details (1)
@coffeea.token ·
[![coffeea](http://c0ff33a.uk/outofcoffee.gif)](http://bit.ly/2YbNaET)  You need to own more COFFEEA (5 COFFEEA in your wallet allows you to send 1 TOKEN per day)
properties (22)
authorcoffeea.token
permlinkre-getting-started-with-pine-script-20200203t030728z
categoryprogramming
json_metadata"{"app": "beem/0.21.1"}"
created2020-02-03 03:07:30
last_update2020-02-03 03:07:30
depth1
children0
last_payout2020-02-10 03:07:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length162
author_reputation4,292,084,626,291
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,040,984
net_rshares0
@trendotoken ·
Congratulations @geekgirl, your post successfully recieved <b>0.139239</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) from below listed TRENDO callers:<br>

>	<sup>@avare earned : **0.092826** [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation</sup> 

---
<sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO)
Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
properties (22)
authortrendotoken
permlinkre-geekgirl-getting-started-with-pine-script-20200204t175118456z
categoryprogramming
json_metadata{"tags":["trdo","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"}
created2020-02-04 17:51:33
last_update2020-02-04 17:51:33
depth1
children0
last_payout2020-02-11 17:51:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length483
author_reputation5,546,209,053,433
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,098,011
net_rshares0
@tts ·
To listen to the audio version of this article click on the play image.
[![](https://s18.postimg.org/51o0kpijd/play200x46.png)](http://ec2-52-72-169-104.compute-1.amazonaws.com/geekgirl__getting-started-with-pine-script.mp3)
Brought to you by [@tts](https://steemit.com/tts/@tts/introduction). If you find it useful please consider upvoting this reply.
👎  ,
properties (23)
authortts
permlinkre-getting-started-with-pine-script-20200201t174123
categoryprogramming
json_metadata""
created2020-02-01 17:41:24
last_update2020-02-01 17:41:24
depth1
children0
last_payout2020-02-08 17:41:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length352
author_reputation-4,535,154,553,995
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,999,575
net_rshares-26,026,153,309
author_curate_reward""
vote details (2)
@whatsup ·
$0.16
I don't program, but this seems like great information and ike it would be interesting to many in this space!

Diversity in content is important.
👍  ,
properties (23)
authorwhatsup
permlinkq51aw9
categoryprogramming
json_metadata{"app":"steemit/0.1"}
created2020-02-01 17:50:36
last_update2020-02-01 17:50:36
depth1
children1
last_payout2020-02-08 17:50:36
cashout_time1969-12-31 23:59:59
total_payout_value0.080 HBD
curator_payout_value0.080 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length145
author_reputation519,839,651,581,670
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,999,773
net_rshares885,495,541,281
author_curate_reward""
vote details (2)
@geekgirl ·
$0.04
Thank you @whatsup!
👍  ,
properties (23)
authorgeekgirl
permlinkq51cq0
categoryprogramming
json_metadata{"users":["whatsup"],"app":"steemit/0.1"}
created2020-02-01 18:30:00
last_update2020-02-01 18:30:00
depth2
children0
last_payout2020-02-08 18:30:00
cashout_time1969-12-31 23:59:59
total_payout_value0.017 HBD
curator_payout_value0.018 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length19
author_reputation1,588,017,773,177,039
root_title"Getting Started With Pine Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,000,726
net_rshares212,777,219,419
author_curate_reward""
vote details (2)