"nz" in Pinescript Equivalent in Thinkscript


New member
Is there an easy way of implementing "nz" from pinescript to Thinkscript. The best I could come up with is "if... isNan().. else" but it makes it complex when multiple nz variables are used

nz in pinescript:
This function takes an argument and if it is equal to na then it returns 0, otherwise it returns the argument’s value.


Well-known member
You can define a script within your indicator script that is callable.

see: https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/script

for your nz function, it might look like this:

script nz {
    input data = 0;
    def ret_val = if isNaN(data) then 0 else data;
    plot return = ret_val;

declare lower;
plot garbage = nz(2);

This, obviously, won't actually plot much other than a straight line at 2. But perhaps it gets you going on a solution.


Similar threads