0
votes

I am trying the following code:

void OnInit()
{
    int i = 0;
    string d[];
    while(i < 2)
    {
        ArraySetAsSeries(d,true);
        for (int j=0; j<5; j++)
        {
            if(MathMod(j,2)==0 && i==0)
                d[j] = "even";
            else if(MathMod(j,2)==0 )
                d[j] = "even without i zero";
            else
                d[j] = "odd";
        }
        i++;
    }
}

I am willing to get output on testing. But I am getting the following error:
2018.03.23 14:51:20.005 EURUSD,M1 (MetaQuotes-Demo): generating based on real

ticks
2018.03.23 14:51:20.006 EURUSD,M1: testing of Experts\testing lines and trdae.ex5 from 2018.02.01 00:00 to 2018.02.20 00:00 started
2018.03.23 14:51:20.050 2018.02.01 00:00:00   array out of range in 'testing lines and trdae.mq5' (61,2)
2018.03.23 14:51:20.051 OnInit critical error

Kindly, help me get rid of this and print the array as I am willing to print it.

1
string d[]; should be a compile time error.mch
Are you sure this is C and not C++? What is string?Lundin

1 Answers

0
votes

You must explicitely indicate the size of the array before inserting data into it.

Use ArrayResize(d,5); and then it will work.