0

This question is a follow-up question to an earlier question asked.

Using assert in pinescript

I tried to write my own library for assert. Here is the code;

library(title="TestLibrary", overlay=true)

export assert(bool condition, string error_msg) =>
    if (condition == false)
        runtime.error(error_msg) 

When I tried to run it with a test code TestLibrary.assert(false, "OwnLibTestError"), it did not work. I did not get any error.

The assert implementation looks fine to me. What is wrong with the code?

I am using pine-script v5

FDL
  • 115
  • 8

1 Answers1

2

This is a bug, exported function result should be assigned to some variable and used explicitly, so workaround is:



//@version=5

library(title="TestLibrary7", overlay=true)

export assert(bool condition, string error_msg) =>
    if (condition == false)
        runtime.error(error_msg)
        false
    else 
        true

plot(close)

Script:

//@version=5
indicator("My script")

import user/TestLibrary/1 as TestLibrary

x = TestLibrary.assert(false, "OwnLibTestError")

plot(x?1:0)
Starr Lucky
  • 1,578
  • 1
  • 7
  • 8