Structure of Pine Script Code | Lesson 2 | Pine script Course

Structure of Pine Script Code | Lesson 2 | Pine script Course

Introduction to Script Structure in Pine Script

In this lesson, we will learn about the structure of a Pine Script and how to correctly program indicators. The script follows a specific structure that includes version directive, indicator/strategy/library annotation call, series of statements, and output function call.

Version Directive

  • The first statement in a Pine Script is the version directive.
  • It defines the version of Pine Script being used.
  • The latest version is 5, which will be used in this course.

Indicator/Strategy/Library Annotation Call

  • After the version directive, we define what we are working on (indicator/strategy/library).
  • For an indicator, use the indicator annotation call.
  • For a strategy, use the strategy annotation call.
  • For a library, use the library annotation call.

Series of Statements

  • This section implements the script's algorithm.
  • Define variables and calculations needed for the indicator or strategy.

Output Function Call

  • The output function call provides the output of our script.
  • Most commonly used is the plot function for indicators to plot lines on charts.
  • Strategies require at least one strategy function call to execute orders.

Indicator vs Strategy

  • Indicators focus on plotting lines or returning values on charts.
  • Strategies focus on executing orders in the market using strategy functions.
  • Strategy calls cannot be used inside an indicator.

Conclusion

This section concludes the lesson on script structure in Pine Script. Following this structure will help you write effective indicators and strategies. Remember to subscribe to our channel for more content and leave any questions you have in the comments section.

Video description

In this video we talk about the structure of a pinescript code for an indicator a strategy or a library. Whenever writing a code in pinescirpt we have to follow a specific structure. If that structure is not followed the script will not execute correctly and will give an error. Join our free telegram group and Facebook group at the links below Join Free Telegram Group 👉👉https://t.me/pinewizards Join Facebook Group 👉👉https://www.facebook.com/groups/pinescripts