This project is read-only.

iMAOnArray passing array to MQL

Dec 17, 2012 at 4:09 PM

Hi folks,

Is anybody was able to resolve passing array to MQL problem with iMAOnArray?


Dec 18, 2012 at 1:17 PM
Edited Dec 18, 2012 at 1:17 PM

Hi All,

This is how you can pass array to MQL to get back iMAonArray value

First you need to modify [Terminal folder]\experts\include\System_NET_MQL.mqh

Add following method to split string into double array:

void SplitDouble(double& arr[], string str, string delim) 
  ArrayResize(arr, 0);
  double item;
  int pos, size;
  int len = StringLen(str);
  for (int i=0; i < len;) {
    pos = StringFind(str, delim, i);
    if (pos == -1) pos = len;
    item = StrToDouble(StringSubstr(str, i, pos-i));
    size = ArraySize(arr);
    ArrayResize(arr, size+1);
    arr[size] = item;
    i = pos+1;


Then add following code into System_NET_MQL_TechIndicators method:

string System_NET_MQL_TechIndicators(string message[])
 if(message[1] == "iMAOnArray") {
   double arr[];
   SplitDouble(arr, message[2], message[8]);
   return (iMAOnArray(arr,




Save it, Open Expert_NET.mq4 and compile it.

Next you'll need to add following code to TechnicalIndicators.cs file in API project

public static double iMAOnArray(this MqlHandler handler, 
	double[] arr, int total, int period, int ma_shift, 
	MA_METHOD ma_method, int shift, string delim = ",")
	string sarr = ArrayToString(arr, delim);
	string retrunValue = handler.CallMqlMethod("iMAOnArray", 
	    sarr, total, period, ma_shift, 
		((int)ma_method), shift, delim);
	return Convertor.ToDouble(retrunValue);
public static string ArrayToString(IList array, string delim)
	string outStr = "";
	for (int i = 0; i < array.Count; i++)
		outStr += array[i].ToString();
		if (i != array.Count - 1)
			outStr += delim;
	return outStr;

That it.