MQL5 dll Normalize 2dim array Cols

//+------------------------------------------------------------------+

//|

//+------------------------------------------------------------------+

_DLLAPI void __stdcall fnNormalizeArray2DPT(double arr[][COL],const int arr_size, const int t_norm=0)

{

  double **ptr2;

  int i;

  if(arr==NULL || arr_size<1) return;

  //////////////////////////////////////////

  create_matrix<double>(&ptr2, arr_size, COL);

  for ( i = 0 ; i < arr_size ; i++)

    ptr2[i] = (double *)arr + i * COL;

  //////////////////////////////////////////

  if(t_norm==0)

  {

    double *xmean = fmx_mean(ptr2, arr_size, COL);

    double *std = fmx_std(ptr2, arr_size, COL);

    fmx_prenorm(ptr2, arr_size, COL, xmean, std);

  }

  else

  {

    double *xrange = fmx_range(ptr2, arr_size, COL);

    double *xmidrange = fmx_midrange(ptr2, arr_size, COL);

    double *xmin = fmx_min(ptr2, arr_size, COL);

    double *xmax = fmx_max(ptr2, arr_size, COL);

    fmx_prenorm_range(ptr2, arr_size, COL, xrange, xmidrange, xmin, xmax);

  }

  //////////////////////////////////////////

  delete_matrix<double>(&ptr2);

  //////////////////////////////////////////

}

//////////////////////////////////////////////////////////////////////////////////////

//+------------------------------------------------------------------+

//|                                                 MQL5DLL Test.mq5 |

//|                        Copyright 2010, MetaQuotes Software Corp. |

//|                                              http://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "2010, MetaQuotes Software Corp."

#property link      "http://www.mql5.com"

#property version   "1.00"

#define COL 5

//---

#import "dlltst1.dll"//msvc8

//#import "dlltst2.dll"//Open Watcom

int  fnCalculateSpeed(int &res1,double &res2);

void fnFillArray(int &arr[],int arr_size);

void fnFillArray2(int &arr[][COL],const int arr_size);

void fnFillArray2DP(int &arr[][COL],const int arr_size);

void fnFillArray2DPT(int &arr[][COL],const int arr_size);

void fnNormalizeArray2DPT(double &arr[][COL],const int arr_size, const int t_norm=0);

void fnCopyArray2(int &arr1[][COL],int &arr2[][COL],int arr_size);

void fnReplaceString(string text,string from,string to);

void fnCrashTest(int arr);

#import

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

/* 

//--- calling the function for calculations

   int    speed=0;

   int    res_int=0;

   double res_double=0.0;

   speed=fnCalculateSpeed(res_int,res_double);

   Print("Time ",speed," msec, int: ",res_int," double: ",res_double);

//--- call for the array filling

   int    arr[];

   string result="Array: ";

   ArrayResize(arr,10);

  

   fnFillArray(arr,ArraySize(arr));

   for(int i=0;i<ArraySize(arr);i++) result=result+IntegerToString(arr[i])+" ";

   Print(result);

//--- modifying the string

   string text="A quick brown fox jumps over the lazy dog";

  

   fnReplaceString(text,"fox","cat");

   Print("Replace: ",text);

//--- and finally call a crash

//--- (the execution environment will catch the exception and prevent the client terminal crush)

   fnCrashTest(NULL);

   Print("You won't see this text!");

//---

*/

/*

//--- call for the array2 filling

   int i,j;

   int    arr2[][COL];

   string result2="Array2: ";

   ArrayResize(arr2,10); 

   Print("arr_size: ",ArrayRange(arr2,0)," COL:",ArrayRange(arr2,1));

   fnFillArray2(arr2,ArrayRange(arr2,0));

  

   //for(i=0;i<ArrayRange(arr2,0);i++)

   //  for(j=0;j<COL;j++)

   //    arr2[i][j]=i;  

      

   for(i=0;i<ArrayRange(arr2,0);i++)

     for(j=0;j<COL;j++)

       result2=result2+IntegerToString(arr2[i][j])+" ";

   Print(result2);

*/

//--- call for the array2 filling

//--- call for the array2 filling

     int i,j;

   double    arr2[][COL];

   string result1="Array2: ";   

   string result2="NormalizedArray2: ";

   ArrayResize(arr2,10); 

   Print("arr_size: ",ArrayRange(arr2,0)," COL:",ArrayRange(arr2,1));

 

   for(i=0;i<ArrayRange(arr2,0);i++)

     for(j=0;j<COL;j++)

       arr2[i][j]=i;  

   for(i=0;i<ArrayRange(arr2,0);i++)

     for(j=0;j<COL;j++)

       result1=result1+DoubleToString(arr2[i][j])+" ";

   fnNormalizeArray2DPT(arr2,ArrayRange(arr2,0),1);//0-norm std, 1-norm range

      

   for(i=0;i<ArrayRange(arr2,0);i++)

     for(j=0;j<COL;j++)

       result2=result2+DoubleToString(arr2[i][j])+" ";

      

   Print(result1);      

   Print(result2);

  

  }

//+------------------------------------------------------------------+