Benjamin
Benjamin

Reputation: 697

Turn off compiler warning messages

After my script saves successfully I receive warning messages from pinescript. Is there a way to turn these annoying messages off.

The function 'perc_change' should be called on each calculation for consistency. It is recommended to extract the call from this scope.

The `transp` argument will be deprecated soon. We recommend using color.new() or color.rgb() functions to specify the transparency of the plots instead.

Upvotes: 2

Views: 1462

Answers (2)

Guardian667
Guardian667

Reputation: 452

First I want to put some spice into the discussion. Later I provide a solution.

This behavior of PineScript annoys me from time to time. There are actual cases, where the calculation of something is intended to be conditional.

Let's say I have a user input for something that should be plotted:

plotIndication = input.bool(false, title="Plot Indication")

Beside that the script could require the indication, even if the user doesn't want to see it. (The script works pretty dynamically). The script decides once if the indication is required, at the start of the execution:

var mustCalculateIndication = na
var indicationRequired = false
if barstate.isfirst
    indicationRequired := <DecisionThings>
    mustCalculateIndication := plotIndication or indicationRequired

Now I am sure, that the bool value that decides if the indication has to be calculated is set once and I know I don't change it anymore on any bar. Now I should be allowed to calculate the indication condionally:

indication = mustCalculateIndication ? calcInd() : na

If wether the user want's to see the indication, nor the script requires it (because of its current config), then there was no need to calculate it, which safes execution time, especially in large scripts

If the user wanted to see the indication, I can plot it. If not, it doesn't matter if it was calculated or not

plot(plotIndication ? plotIndication : na)

Way later I then include the indication in some calculations only when the script requires it. If it doesn't require it, it doesn't matter if it has been calculated or not,

trigger = false
// ... calculate trigger
if indicationRequired
    if indication
        trigger := true

In my special case, the point is that my script can calculate MUCH stuff, but in general only a small part of it is required, depending on user inputs. Everything that I don't have to calculate safes execution time.

====

Now here is the promised solution. Write a library and use delegate the function call. Here is an example to calculate a high pivot, which leads to the error, if called within an if statement

library("PivotDelegate")

export highPivot(float lookback, float confirmation) =>
    fixnan(ta.pivothigh(lookback, confirmation)[1])

In another indicator you can do this

import <Username>/PivotDelegate/1 as pd

// ...

pivotHigh = pivotRequired ? pd.highPivot(pivotLeft, pivotRight) : na

In my opinion this is a pretty inconsistent behavior and writing a library just to avoid the warning is like a hack. But... libraries are cool, so I'm fine with it ;)

Upvotes: 0

juanmirocks
juanmirocks

Reputation: 6239

When you do know what you are doing, it could indeed be useful to turn off some compiler warnings. However, as of the time of this writing, this is not available. For reference, pine-script already supports special compiler annotations with comments; see doc. It should be easy for TradingView folks to implement such a warning-off functionality.

Having said that, unless you know well what you are doing, you should not ignore such a warning:

The function 'foo' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator or from the scope

This is because function blocks in pine-script keep their own independent historical context. For some types of functions, not running them in every bar leads to odd and wrong results; see doc.

Upvotes: 1

Related Questions