TradingView
QuantNomad
2021年6月5日午前7時53分

Logging in Pine Script 

Bitcoin / Tether USDPoloniex

詳細

I'm building quite a lot of pretty complicated indicators/strategies in Pine Script. Quite often they don't work from the 1 try so I have to debug them heavily.
In Pine Script there are no fancy debuggers so you have to be creative. You can plot values on your screens, check them in the data window, etc.
If you want to display some textual information, you can plot some info as labels on the screen.
It's not the most convenient way, so with the appearance of tables in Pine Script, I decided to implement a custom logger that will allow me to track some useful information about my indicator over time.
Tables work much better for this kind of thing than labels. They're attached to your screen, you can nicely scale them and you can style them much better.

The idea behind it is very simple. I used few arrays to store the message, bar number, timestamp, and type of the message (you can color messages depend on the type for example).
There is a function log_msg that just append new messages to these arrays.
In the end, for the last bar, I create the table and display the last X messages in it.

In parameters, you can show/hide the entire journal, change the number of messages displayed and choose an offset. With offset, you can basically scroll through the history of messages.

Currently, I implemented 3 types of messages, and I color messages according to these types:
  • Message - gray
  • Warning - yellow
  • Error - red


Of course, it's a pretty simple example, you can create a much fancier way of styling your logs.
What do you think about it? Is it useful for you? What do you use to debug code in Pine Script?

Disclaimer
Please remember that past performance may not be indicative of future results.
Due to various factors, including changing market conditions, the strategy may no longer perform as good as in historical backtesting.
This post and the script don’t provide any financial advice.

リリースノート

updating to v5
コメント
PineCoders
PineCoders
This publication is now featured in our Editors' Picks: tradingview.com/scripts/editors-picks/ .
In the name of all TradingViewers, thank you for your valuable contribution to the community, and congrats!
Pratik_4Clover
Thanks! Very useful :)
MadScalper
Awesome..Pinescript needs some arrangements in datawindow to show datafraames and variable values..that would be much usefull
morzor61
hello, thank you for your greet work.
i'm a newbie and i wonder if you can teach me how to make table like this for financial data.

what i want is to create a table and show financial data (such as eps, revenue) in each quarter or year.

but until now, i can't figture out.

thank you in advance.
vaidab
So creative. Thank you!
ICEKI
Thank You QuantNomad for contribution this nice and useful code for us; very appreciated <3
kurtsmock
Oh man this is really nice. I had the same idea, but haven't had the time to build it. Very cool. Thanks for the contribution to the community
Vishant_Meshram
Really nice and useful code. Thanks for sharing.
raja74sekhar
Thanks a lot
詳細