how to program with complex numbers??

 

Hello Everyone!


I would like to use DSP analysis in MT4, actually i do it in MATLAB, but i would like to know how to program with complex numbers

(real and imainary) in MQL4 and i don't know how to do it.


How can i program using complex numbers in MQL4???


I hope you can help me


My best Regards!!

 
DSP, eh? I don't really see the problem. You can always store any number in angular state and remap back/forth.
 

alej0:

I would like to use DSP analysis in MT4, actually i do it in MATLAB, but i would like to know how to program with complex numbers

Same way you program anything, you CODE it. Write some CODE. Show us some functions like ComplexADD, ComplexMultiply.
 

Interesting question. :-)

Here is a suggestion, using two dimention arrays to encode real and imaginary parts:

void add( double c1[2], double c2[2], double &result[2])
{
   result[0]=c1[0]+c2[0];
   result[1]=c1[1]+c2[1];
}



void mult( double c1[2], double c2[2], double &result[2])
{
   result[0] = c1[0]*c2[0]-c1[1]*c2[1];
   result[1] = c1[0]*c2[1]+c1[1]*c2[0];
}


string c_to_string(double c[2])
{
   
   string sss = ""+c[0]+" "+c[1]+"j";
   return( sss);
}


int start()
{
   double complex1[2]={2,3};
   double complex2[2]={4,5};
   double result1[2], result2[2];
   
   add(complex1, complex2, result1);
   mult(complex1,complex2, result2);
   
   Print("Add  result is "+c_to_string(result1) );
   Print("Mult result is "+c_to_string(result2) );
   return(0);
}   


Other complex operators/functions can be implemented in a similar way.

Enjoy it. :-)

AM.

Reason: