Remap
- re-maps one range to another

Math functions
(AmiBroker 6.30)


SYNTAX Remap( value, srcMin, srcMax, dstMin, dstMax )
RETURNS NUMBER or ARRAY
FUNCTION The function re-maps a value (number or array) from 'source' to 'destination' range. That is, a value of srcMin would get mapped to dstMin, a value of srcMax to dstMax, values in-between to values in-between, etc. Does not constrain values to within the range, because out-of-range values are sometimes intended and useful.

Parameters:

  • value - the value to be remapped
  • srcMin, srcMax - minimum and maximum value of source range
  • dstMin, dstMax - minimum and maximum value of destination range

Depending on input value type (number or array) the result will be also number or array.

Mathematically the function performs the following linear transformation:

result = (value - srcMin) * (dstMax - dstMin) / (srcMax - srcMin) + dstMin;

Typical usage of the function is to convert indicator from one range to another. Say you have an indicator that ranges from -1..1 and you want it to be bounded in 0..100 space. Then you can use Remap( value, -1, 1, 0, 100 );

Or you want to convert pixels to prices or bars or vice versa as shown in the example below

EXAMPLE height = Status("pxheight");
pxmin = Status("pxchartleft");
pxmax = Status("pxchartright");
barmin = Status("firstvisiblebar");
barmax = Status("lastvisiblebar")+1;

GfxSelectPen( colorRed );

for( bar = barmin; bar < barmax; bar++ )
{
   // re-map bar numbers to pixel co-ords
   x = Remap( bar, barmin, barmax, pxmin, pxmax );
   // draw vertical lines where bars are
   GfxMoveTo( x, 0 );
   GfxLineTo( x, height );
}
SEE ALSO Status() function

References:

The Remap function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.