WiseTrader Toolbox

PercentDifference

Background

Often you want to know how far apart two numbers are as a percentage rather than in raw points, because a 5 point gap means very different things on a $10 stock and a $500 stock. PercentDifference is a small helper that does exactly that. It's the same calculation the pattern finders in this toolbox use internally when they check, for example, whether two tops in a double-top are close enough in height to count.

Function

PercentDifference(Value1, Value2)

Parameters

ParameterDescription
Value1The first value.
Value2The second value.

Usage

// How far today's close is from the 50-day average, in percent
diff = PercentDifference( Close, MA( Close, 50 ) );
Filter = diff < 1;   // price within 1% of the average
AddColumn( diff, "% From MA" );
Note

The result is the size of the gap as a percentage, so it is always positive regardless of which value is larger.