Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of console.log in pine-script?

How does one console.log variables, or the results of functions in pine-script? I'd like to convert a pine-script script into javascript, and I'd like to verify that the script I'm converting is the same as the original. Any work arounds are welcome if this functionality does not exist. Thanks!

like image 860
zero_cool Avatar asked Feb 07 '18 04:02

zero_cool


People also ask

How do I print a console in Pine script?

There is no way to print text or variables in pine-script to any form of "console". But you can use plot to print, very short text above or below each tick. The text, however, is static and you cannot use variables to change it.

What is Pine script similar to?

This makes Pine Script useful for both those who are new and experienced in writing custom trading scripts. It's not based on any language in particular but shares similarities with Python and Kotlin.

What does := mean in Pine script?

= is used to declare and initialize variables := is used to assign values to variables after initialization, transforming them into mutable variables(any immutable variable).

What is NZ function in Pine script?

nz is a “filler”, as it fills na values of a series with zeros (in the case of nz(x) ) or with a user-specified value (in the case of nz(x, y) ).


1 Answers

NOTES

  1. While this answer's content is not deprecated, the Pine User Manual now contains a page on debugging techniques explaining much of this answer's content, and more.
  2. RicardoSantos has a very nice DebugConsole library which v5 users can access.

There is actually something similar to a console for Pine developers; it's the Data Window. We use it constantly to debug. The idea is to use plotchar() in this way:

plotchar(bar_index, "Bar Index", "", location = location.top) 

enter image description here

This will not disrupt the indicator's scale and won't print anything in it, but it will show a value in the Data Window, as is explained in the second question of the PineCoders FAQ's section on debugging. As you move your mouse over chart bars, the corresponding value of the variable/expression will show in the Data Window. The FAQ explains other useful techniques that can be used to debug on the chart, as that is sometimes more efficient.


We use an AutoHotkey macro that creates the required plotchar() statement from a variable or expression previously copied to the clipboard. This is the AHK macro:

^+C:: SendInput plotchar(^v, "^v", "", location.top){Return} 

The Data Window is also a great option as a display panel for scripts requiring the display of many values, such as our Backtesting & Trading Engine, which makes extensive use of it: enter image description here

like image 106
PineCoders-LucF Avatar answered Oct 11 '22 07:10

PineCoders-LucF