Replace NaN with a number


Category:
0
0

I am trying to create a custom column for my Quotes watchlist.

 

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on February 7, 2021 5:39 pm
346 views
0
Private answer

Sorry but there does not seem to be a quick and easy solution to this. I tried many different ways to get it working and only one was able to give the result you are seeking. The problem with this approach is that it only displays the value as a chart label instead of a numeric value:

def percentChange = 100 * (close / close[756] - 1);
AddLabel(yes, if !IsNaN(percentChange) then percentChange else 0);

Which means you can "use it in a larger formula".

I am out of time to continue working on this. But some other methods I might consider would be to use a specific date rather than the number of bars. I have no idea if that solves the problem and I don't have time to test it.

The other thing you might consider is to remove these stocks from your watchlist or results list. Any stock that returns a current BarNumber() less than 756 would be excluded from the results list.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on February 8, 2021 9:49 am