forex software

Create and Test Forex Strategies

forex software

Skip to forum content

Forex Software

Create and Test Forex Strategies

You are not logged in. Please login or register.


Forex Software → Expert Advisor Studio → Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 19

1 (edited by Roughey 2020-01-19 10:16:41)

Topic: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Hi,

now i use Popov Datafeed. All looks nice. I have data from 2007 to 2020.

Now when i test in MT4 i get this error.

2020.01.19 10:08:29.790    2017.01.02 00:00:00  Portfolio Expert EURUSD H1 EURUSD,H1: array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

It is this line of code in Portfolio.

//+------------------------------------------------------------------+
double Close(int bar)
  {
   return Close[bar];
  }

When i change my testing data time between x and x nothing happen.

What is this and how can i resolve this.

The Close is needed in a strategie with this code.

   {
      int consecutiveBullish = 0;
      int consecutiveBearish = 0;
      double pipVal = pip * 8;

      for (int b = 1 + 2; b > 0; b--)
        {
         consecutiveBullish = Close(b) - Open(b) >= pipVal ? consecutiveBullish + 1 : 0;
         consecutiveBearish = Open(b) - Close(b) >= pipVal ? consecutiveBearish + 1 : 0;
        }

      ind2long  = consecutiveBullish >= 1;
      ind2short = consecutiveBearish >= 1;
   }

It is something with the Indicator Candle Color.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Hello Roughey,

I'm in the Netherlands now and have only a Linux laptop with me. Please try to find a solution and post an update.

I'll be back in Bulgaria on 27th of January and will be able to make tests.

Anyway, I'll try to find time to post further updates.

Trade Safe!

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

i didnt get it work.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

can someone check if have same problem with candle color indicator

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

I tested an expert with Candle Color and it works fine.

Please upload your expert for further analysis. It can be another reason and we must find and fix it.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Popov wrote:

I tested an expert with Candle Color and it works fine.

Please upload your expert for further analysis. It can be another reason and we must find and fix it.

Hi,

i have now checked a little. It must be something with Open Prices Only test and Tick data test.

When i use Tickdata test than i get the out of range error when i use open prices only it is working.

But why it is ? Can you check . Here the Ea.  Use date from 02.01.2015 - 31.01.2020

Post's attachments

Portfolio Expert EURUSD H1.mq4 244.67 kb, 14 downloads since 2020-02-16 

You don't have the permssions to download the attachments of this post.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

any idea about that?

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

I tested the attached Portfolio Expert on "every tick" and found it working fine.

https://image-holder.forexsb.com/store/portfolio-ea-tick-testing-found-ok-thumb.png

It must be something of how MT generates the ticks. Generally, you don't need to use "every tick" in MT with EA Studio experts. Please check if you have similar results when you use the "bar open" or the "control points" methods with EA Studio.

9 (edited by bobstar 2021-03-17 22:29:41)

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

This bug can happen when you start the backtest at the exact beginning of a historical data, and for some strategies requires an index that go outside the array size (for these Time[], Open[], High[], Low[], Close[]).
I solved and fixed this bug by modyfing the code like that:

datetime Time(int bar){ if(bar >= ArraySize(Time)) return 0; return Time[bar];}
double Open(int bar){   if(bar >= ArraySize(Open)) return 0; return Open[bar];}
double High(int bar){    if(bar >= ArraySize(High))  return 0; return High[bar];}
double Low(int bar){     if(bar >= ArraySize(Low))   return 0; return Low[bar];}
double Close(int bar){   if(bar >= ArraySize(Close)) return 0; return Close[bar];}

@Popov I thinnk you can modify this code in the current MQL template, in order to fix this bug with that solution.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

How you can start the backtest from the first bar?
Usually, MetaTrader starts from bar number 100.

Please check if you have any data. Print the size of the data arrays.
Is it possible to require more bars than you have?

11 (edited by bobstar 2021-03-17 18:24:35)

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Yes, it's possible to start the backtest from the first bar (when you download data from Tickstory for example or other third-party providers), in this case when the backtest starts at the beginning of downloaded datas, it doesn't show any previous bar and therefore the size of these standard arrays (Time[], Open[], etc...) are limited to the actual bars.
With some strategies, that uses these values, this can happen.

@Popov here a screenshot where I made a Print of the value of the ArraySize of Time and it shows also the number of Bars on the chart (that of course are equal to ArraySize(Time).

PunBB bbcode test

Post's attachments

solution for Array out of range.jpg 194.96 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

In that case, the better solution is to set a starting date of the backtest. Let's say 2020-01-03.

What is the purpose of importing data in MetaTrader?

The backtest on third party data may not correspond to the following real trading.

13 (edited by bobstar 2021-03-17 22:15:00)

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

The purpose of importing data into MT4 is to make high quality backtests from tick by tick data; MT4 by default uses the global history data that are not good for tick by tick backtests, instead Tickstory or Tickdata Suite are optimal choices for professional backtest and these data are taken from Dukascopy database (@Popov the same provider that you are using for Premium Data on EA Studio).

It's possible to overcome these "Array out of range" problems by starting the backtest 1 or 2 days later, but @Popov you know that "Array out of range" is not a problem from a backtest but from a source code and needs to be managed properly.

Like I told you, a possible solution is to put a simple condition before accessing to the actual array, like that:

datetime Time(int bar){
    if(bar >= ArraySize(Time)) return 0;
    return Time[bar];
}

instead of

datetime Time(int bar){
    return Time[bar];
}

Think about that, maybe for the next release.
Thank you @Popov

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

A better solution would be to skip all the calculations until we have enough bars.

Something like:

const int requiredBars = 100;

void OnTick()
{
    if ( ArraySize(Time) < requiredBars ) return;

    ...
}

requiredBars can be set from EA Studio on export depending on the strategy.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

yes, it's a solution

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Done.

Please reload EA Studio with Ctrl + F5 and try.

17 (edited by bobstar 2021-03-18 12:07:56)

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

@Popov, you forgot to define the macro REQUIRED_BARS, in fact it doesn't compile because of this error (both on MQL for single EA and Portfolio)

Post's attachments

error macro.jpg
error macro.jpg 120.15 kb, 2 downloads since 2021-03-18 

You don't have the permssions to download the attachments of this post.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Please reload EA Studio with Ctrl + F5 and try.

But you are right. There are many users that don't reload EA Studio for weeks. So I changed the MQL to have requiredBars = 100 by default.

Re: Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

all right

Posts: 19

Pages 1

You must login or register to post a reply

Forex Software → Expert Advisor Studio → Array out of range in 'Portfolio Expert EURUSD H1.mq4' (592,16)

Similar topics in this forum