Home > Blog > Pine Script Tutorial > Pine Script Basics | Study vs Strategy | Tutorial 2

Pine Script Basics | Study vs Strategy | Tutorial 2

Published by Ali Muhammad
Updated on

In this article we will cover basic overview of pine script editor as well as basic syntax.

So, let us get started

Tradingview Pine Editor Basics

The first step is to click on the pencil icon. It is used to rename your script. Or simply click on the untitled script and easily rename your script. My script 1 is the default text. Look at the highlighted area in the image below.

To the right of the pencil icon, there are two more icons. Star icon is used to add the script to favorite so you can easily access your script. A search icon is used to find or replace a specific text in the script.

While editing the script in the pine editor, A small red star icon will appear with the script name. it indicates unsaved script so remember to save your script.

Another important option here is revision. Whenever you will save your script, the number will continue adding up by one. By default, it will be 1.0. Now you have written your script and press save then it will turn 2.0 so you can access your previous script easily by switching the number to 1.0 This is an awesome feature.

Another feature of the pine script editor is the option of “open”. By clicking here, you can access your previous scripts, use built-in scripts, create a new indicator and a strategy.

How to write a comment in pine script

Publish script option is used to share your script with the public. A trader can sell his script to others easily and safely by using this feature. Also, you can take help from other programmers by sharing questions about a particular script.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © forexbee

The above two lines are comments by default. To write a comment in pine script, start with two forward slashes. The text/code written after two forward slashes will not be executed by the compiler.


This piece of code indicates the version of pine script you are using. There are currently four versions of pine script and they are incompatible with one another. By default, it will be version=4 because it is the latest version and has much more features as compared to previous versions. There is also an option of converting older version scripts to version 4. So before modifying an old script in the public library, first remember to convert it.

Study vs Strategy

study("My Script")

Study and strategy are two functions. A function is used to do calculations and variable is used to store these calculations.

  • There must be at least one function call in study which will be used to show the return value of study function. Like a Plot() function which is used to plot the return value. Like to plot indicator on chart.
  • Study function is used to show information on chart and to show alerts on chart. Simply Study is used to make indicator
strategy("My Strategy", overlay=true)

longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)

Strategy function must contain at least a strategy like entry, strategy, etc like shown in the above code (the code is to just show you the difference between study and strategy at this level). Otherwise, you will get errors. So, the function call is necessary to show the return value.

The strategy function is used to plot information on chart as well as to backtest a specific strategy.

Video Tutorial 👇👇

Study vs Strategy | Pine script Course | Lesson 2

I hope you will like this Article. For any Questions Comment below, also share by below links.

Note: All the viewpoints here are according to the rules of technical analysis. We are not responsible for any type of loss in forex trading.

Do you want to get success in Trading?

Here's the Roadmap:

1. Learn supply and demand from the cheat sheet here
2. Get access the Supply & Demand Indicator here
3. Understand the fair value gap here
4. Use the set and forget strategy here
5. Follow the risk management plan here

Leave a Comment