Up / Down

All functions · nseries package

UpDown

func (s Series) UpDown(n int, tolerance ...float64) Series

UpDown returns a series of numbers where each 2 bits represents an up bar (2), a down bar (1), or a flat bar (0), for the preceding n bars. Optionally, a tolerance (in the form of value that represents a percentage) may be provided. For example, a tolerance of 5 dictates that a value must be 5% higher/lower than its predecessor to register as an up/down. The maximum number of values to look back to is 24. All three direction APIs use threshold = abs(previous)*tolerance/100: change > threshold is up, change < -threshold is down, otherwise flat. Negative, NaN, or infinite tolerance yields aligned zeros.

The tolerance is a percentage of the previous value’s magnitude, so 0.05 means 0.05%, not 5%; the threshold is |previous|*tolerance/100, multiplied before it is divided, and the comparison is strict, so a change equal to the threshold is flat. The warm-up reads 0, not NaN: bars 0 to n-1 are 0, which is also a real code, n flat bars.

UpDownString

func (s Series) UpDownString(n int, tolerance ...float64) []string

UpDownString returns a string slice representing whether the last n values, when compared with the previous value, were up (“U”), down (“D”), or flat ("-"). Optionally, a tolerance (in the form of value that represents a percentage) may be provided. For example, a tolerance of 5 dictates that a value must be 5% higher/lower than its predecessor to register as an up/down. The maximum number of values to look back to is 24. A period outside the valid range 1..24, or an invalid (negative, NaN, or infinite) tolerance, yields an aligned slice of empty strings; a valid period and tolerance produce ordinary warm-up strings, including flat ("-") symbols where applicable.

The tolerance is a percentage, as in UpDown, compared strictly against |previous|*tolerance/100, multiplied before it is divided, so 0.05 means 0.05%, not 5%, and a change equal to the threshold is flat.

UpDownSum

func (s Series) UpDownSum(n int, tolerance ...float64) Series

UpDownSum returns a series which is a sum of +1 values for each bar that was higher than the previous bar and -1 for each bar that was lower than the previous bar, for n bars. For example, if n is 6 and 4 bars are higher than their previous, 1 is equal, and 1 is lower, the value at that bar would be +3. Optionally, a tolerance (in the form of value that represents a percentage) may be provided. For example, a tolerance of 5 dictates that a value must be 5% higher/lower than its predecessor to register as an up/down. UpDownSum uses the same mutually exclusive up/down/flat classification as UpDown (see UpDown). A negative, NaN, or infinite tolerance yields an aligned zero-filled result. Unlike UpDown and UpDownString, UpDownSum has no upper bound of 24 on n.

The tolerance is a percentage, as in UpDown, compared strictly against |previous|*tolerance/100, so 0.05 means 0.05%, not 5%. The warm-up reads 0, not NaN: bars 0 to n-1 are 0, which is also a real balance.