# Correlation with remap return nan

Hello,Bonjour,
I don’t understand why the correlation function with remap at first arg returns nan

//NumBars = GetVisibleBarCount() ;
NumBars = Param( "NumBars", 64, 14, 256, 4 );
Pds = Param( "Periods", 10, 5, 28, 1 );
periodsMFI = Param( "periodsIndicator", 14, 5, 28, 1 );

price = Close;
remapPrice = Remap( price, LLV( price,NumBars), HHV( price,NumBars ), 0, 1 );
//Plot( remapPrice , "normPrice", colorLightOrange, ParamStyle("Style") );
array = MFI(periodsMFI);
remapArray = Remap( array, LLV( array,NumBars), HHV( array,NumBars ), 0, 1 );
//Plot( remapArray, "normArray" , colorGreen, ParamStyle("Style") );

corrPrice = Correlation( remapPrice, BarIndex(), Pds ) ; // returns nan
corrArray = Correlation( remapArray, BarIndex(), Pds ) ; // returns nan

If I loop on BarCount

myClose = 0;
myArray = 0;
for (i = 1 ; i < BarCount; i++)
{
myClose[i] = remapPrice[i];
myArray[i] = remapArray[i];
}

corrMyPrice = Correlation( myClose, BarIndex(), Pds ) ; // return array
corrMyArray = Correlation( myArray, BarIndex(), Pds ) ; // return nan

cos remap array value is sometimes == zero

You will got Nan if HHV == LLV (if prices don't change) then there is no way to map range of 0..0 to 0..1.

You should add some small value of upper bound so upper and lower bounds are different.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.