General-Purpose Functions


Anchors a value in multi-bar function calculations




value - the value to anchor


In functions such as CountTrue, SinceTrue and TrueInRow, we sometimes want to compare a number of prior bar values to one specific bar value.

For example, say you want to know how many bars it has been since there was more volume than today's volume.

You might try using SinceTrue(V[1] > V), but since this is a multi-bar function, the entire expression "V[1] > V" is rolled back through time and evaluated for each bar as if it was the current bar. So instead of telling you how many bars since volume exceeded today's volume, it is telling you how many bars since any day's volume was greater than the following day's volume.

To get what you're looking for, you'd instead use SinceTrue(V > This(V)). When SinceTrue rolls back through time, it now only rolls the first 'V' in the expression, while keeping the 'This(V)' anchored to the current bar.

To further understand how this works, consider a simple price with offset C[n]. If n=0, this is today's close, if n=1, yesterday's close, and so on. Now consider that This(C)[n] might mean. Since This has anchored C to today's bar, the [n] offset has no effect, so C will always be returned regardless of the value of n.

The Debug Panel is a useful place to study complex functions such as this one.





Copyright © 2020-2021 Systematic Solutions, LLC