Pine Script

Logging in Pine Script

Logging in Pine Script

Logging is a crucial aspect of programming, providing insights into software’s behavior during execution. It not only helps in debugging by recording events and errors, allowing developers to trace issues back to their source, but it also plays a significant role in monitoring the performance and health of applications in production. Through effective logging, programmers can understand the flow of their code, making it easier to diagnose problems, optimize performance, and ensure the reliability and stability of their applications over time.

For a long time, developers working with Pine Script faced a notable challenge due to the absence of comprehensive tools for logging and debugging. This gap made it difficult to track down errors or understand the behavior of scripts under various conditions, often leading to increased development time and decreased efficiency in creating and refining trading strategies.

TradingView has finally addressed a long-standing need within the Pine Script community by introducing robust logging functions. These enhancements have significantly simplified the process of logging information, making it easier for developers to debug and optimize their scripts, thereby enriching the overall development experience on the platform.

To log any info from Pine Script you can use one of 3 functions:

  • log.error
  • log.warning

Here is a very simplistic example that shows the usage of these functions. You can call them from any part of your code:


if (barstate.islast)
    log.error("This is an error message")
    log.warning("This is a warning message")"This is an info message")

To find your logs, you have to click on the 3 dots on the left of your Pine Editor and click “Pine Logs”

This will open a new sidebar where you’ll see all of your logs for every bar time:

It has quite a handy interface because you can search and filter your logs:

With the addition of logging capabilities and other sophisticated features, Pine Script is increasingly resembling a general-purpose programming language, showcasing its versatility and power. I appreciate how TradingView is dedicated to evolving its scripting environment, making it not only more user-friendly but also vastly more capable, aligning with the needs and expectations of its diverse user base.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Pine Script Programming Courses
Pine Script Programming Courses
Learn to build your own TradingView Indicators and Strategies
Sidebar Signup Form
If you want to be the first in this business, subscribe to the latest news