Standard deviation refusing to return a value for cumulative indicators

So, I’ve got myself in a bit of a bind. I built a custom volume indicator that has two drawn out steps – a compression tool for volume and a weighting factor – and the result of these two steps is summed from a bar index of 1 to current (like Cum Delta, AccDist, or OBV). All very bespoke, still pretty simple, and I’ve been using it for awhile now on other platforms because it worked surprisingly well, but porting it to Tradovate has been like pulling teeth.

After many attempts to diagnose and fix the problem, here’s what I know.

  1. Individually, the two pieces work totally fine. The weighting factor presents a usable value and the compressed volume presents a usable value.

  2. Each component in the calculation (SMA, StDev, volume, various weights involved in the weighting factor) can be plotted and presents a usable value.

  3. The weighting factor * compressed volume returns a value identical to the values I can pull from my other platforms on the same time intervals and can be plotted to boot.

  4. When I try to plot a cumulative value of the weighting factor * volume, it works fine and plots as expected.

  5. When I enable the compressor, the cumulative value now returns null (see below image for #4 and #5

  6. When calculating the cumulative value, every part of the equation used returns a usable value except Standard Deviation, which returns a null value. Interestingly, standard deviations .avg call still returns a non-NaN value.

  7. The same exact issue occurs if using Mean Deviation (from the core SMA function), yielding usable values until added continuously, then no longer functioning.

  8. My compressor function applied to PVT, AccDist, or any of the custom OBV scripts has the same problem – the individual values are successfully returned but not the cumulative value.

I’ve used the handful of methods I could come up with to do cumulative summation (the standard method that is like the stock PVT and AccDist code, cut my code and dropped it into the stock Delta script, and found a couple community scripts to try theirs out as a Hail Mary) and none were able to bypass the issue.

Am I missing something obvious, shooting myself in the proverbial foot, or is this a bug with the base standard deviation script? More importantly, anyone have any ideas how I can fix it?

Check the outputs of the previous indicators in your pipeline. Somewhere along the line, its possible that one of those doesn’t return a simple number, or returns an object with no value field. If an indicator’s map doesn’t return a plain number and no value field is present, you will have to specify the output field you want to use. It seems most likely that this issue happens when you apply the compression equation - check to see what that function returns. If it is an object with no value field or not a simple number you may need to change how you consume that value.

1 Like

Well, you’re the lifesaver! Turns out the StdDev function was returning NaN in some very specific circumstances, now everything works as expected.

Thanks!

1 Like