Optimize history real trades for future trading by the same strategie

 

Hello,

at first, sorry for my bad english ;-)

I looking for an EA only for backtest, who read old real trade data from a csv file (only time lot entryprice), and then it use in optimize mode, to get betther settings for Limit and Stoploss. eg...

With this program we can test best settings for signal providers too.

Is there in the community a code as base for my little project?

Yours Joe

 
JoeDorman:

Hello,

at first, sorry for my bad english ;-)

I looking for an EA only for backtest, who read old real trade data from a csv file (only time lot entryprice), and then it use in optimize mode, to get betther settings for Limit and Stoploss. eg...

With this program we can test best settings for signal providers too.

Is there in the community a code as base for my little project?

Yours Joe

I doubt the result would be useful. Sounds like curve fitting to me. IMHO.

Anyway, I don't know of any EA like that, but it's doable.

 
gordon wrote >>

I doubt the result would be useful. Sounds like curve fitting to me. IMHO.

Anyway, I don't know of any EA like that, but it's doable.

Hello,

at the programming I get an error by execution.

I have to Read a large csv file.

Because speed I will get the data in an glbal array sizes with 10000 entries.

for every of the 10000 entries have 18 arrays with data like string int bool double.

Itss like as a record set.

When I load smal files up to 250 Entries, no problem.

But larger files will not complet read in the array.

MT4 shows no errors.

There are any unknowed restrictions?

What can be the problem?

Yours Joe

 
JoeDorman wrote >>

Hello,

at the programming I get an error by execution.

I have to Read a large csv file.

Because speed I will get the data in an glbal array sizes with 10000 entries.

for every of the 10000 entries have 18 arrays with data like string int bool double.

Itss like as a record set.

When I load smal files up to 250 Entries, no problem.

But larger files will not complet read in the array.

MT4 shows no errors.

There are any unknowed restrictions?

What can be the problem?

Yours Joe

maybe you read the file with every tick incomming?

is neccesary?

 

JoeDorman wrote >>

When I load smal files up to 250 Entries, no problem.

But larger files will not complet read in the array.

MT4 shows no errors.

There are any unknowed restrictions?

What can be the problem?

The arrays are restricted to a max of 4 dimensions, but I don't know of any restrictions on their size. Anyway, had u reached that restriction u would have gotten an error. Same goes for if u had memory problems.

I recommend u post your code and a sample of the CSV file...

 
EADeveloper wrote >>

maybe you read the file with every tick incomming?

is neccesary?

No,

I read the complet file in an array in the init() function only, because the programm is only for backtesting and i will not read the files by every thick ;-)

In the start() function I will work with this data to buy and sell all the orders at the array, with using my stoploss and target pips by optimize.

I hope you understand my intension ;-)

I get Print comments in part init() for debugging and there I see, that not all csv lines put in the array.

By every csv file i get never more than 250 entries in the array.

But there is no restriction by the program code.

When the datasize of my record set is smaller, also when I disable some string arrays, I can more lines put in the memory.

Also I think, there must be restrictions by memory.

What can I do for test to find the point of error?

Yours Joe

 
JoeDorman:

Also I think, there must be restrictions by memory.

What can I do for test to find the point of error?

Joe, the following code is from this article: https://www.mql5.com/en/articles/1544


//+------------------------------------------------------------------+
//| writing the content of the file into string array 'array[]'      |
//| in case of failing, return 'false'                               |
//+------------------------------------------------------------------+
bool ReadFileToArray(string &array[],string FileName, string WorkFolderName)
  {
   bool res=false;
   int FileHandle;
   string tempArray[64000],currString;
   int stringCounter;
   int devider='\x90';
   string FullFileName;
   if (StringLen(WorkFolderName)>0) FullFileName=StringConcatenate(WorkFolderName,"\\",FileName);
   else FullFileName=FileName;
//----
   Print("Trying to read file ",FileName);
   FileHandle=FileOpen(FullFileName,FILE_READ,devider);
   if (FileHandle!=-1)
      {
      while(!FileIsEnding(FileHandle)) 
         {
         tempArray[stringCounter]=FileReadString(FileHandle);
         stringCounter++;
         }
      stringCounter--;
      if (stringCounter>0) 
         {
         ArrayResize(array,stringCounter);
         for (int i=0;i<stringCounter;i++) array[i]=tempArray[i];
         res=true;
         }
      FileClose(FileHandle);   
      }
   else
      {
      Print("Failed reading file ",FileName);
      }      
//----
   return(res);
  }

Probably not exactly what u want, but notice he is reading a file to an array with 64000 cells... So memory is probably not your problem. Maybe u can get ideas from this code, otherwise please explain HOW exactly u r getting the data from file into the array (or post your code)...

 
gordon wrote >>

Joe, the following code is from this article: https://www.mql5.com/en/articles/1544

Probably not exactly what u want, but notice he is reading a file to an array with 64000 cells... So memory is probably not your problem. Maybe u can get ideas from this code, otherwise please explain HOW exactly u r getting the data from file into the array (or post your code)...

You are right.

Thx for the code Sir.

I have found a limit variable for reading lines per file in my code. SORRY.

I used the limit because tryed to debug a problem:

My Arrays are:

#define DF_ZEILEN 10000

string sComment[DF_ZEILEN];
string sDate[DF_ZEILEN];
string sSymbol[DF_ZEILEN];
int iOrderType[DF_ZEILEN];
double dEntry[DF_ZEILEN];
double dStopLoss[DF_ZEILEN];
double dTarget[DF_ZEILEN];
datetime dtDate[DF_ZEILEN];
datetime dtExpiration[DF_ZEILEN];
bool bFlag[DF_ZEILEN];
double dSpread[DF_ZEILEN];
double dDigits[DF_ZEILEN];
double dPoint[DF_ZEILEN];
double dAsk[DF_ZEILEN];
double dBid[DF_ZEILEN];
double dSlippage[DF_ZEILEN];

All this arrays i will filled when i read a line from csv at runtime.

The array sComment[x] i filled with "signalname YYYY.MM.DD hh:mm:ss". It should be to put as comment in OrderSend() function.

When DF_ZEILEN is not so big, eg. lower as 100, i can read this variable good in start() function and put the comment in the order.

But when DF_ZEILEN is higher, eg. 1000, then i can show only the part of date.

I ask me, where is the part of signalname, was saved in this variable sComment[x]

Why could be a higher definition for array count make problems.

Any idea?

Yours Joe

 
JoeDorman:

The array sComment[x] i filled with "signalname YYYY.MM.DD hh:mm:ss". It should be to put as comment in OrderSend() function.

When DF_ZEILEN is not so big, eg. lower as 100, i can read this variable good in start() function and put the comment in the order.

But when DF_ZEILEN is higher, eg. 1000, then i can show only the part of date.

I ask me, where is the part of signalname, was saved in this variable sComment[x]

Why could be a higher definition for array count make problems.

Any idea?

Yours Joe

The comment field in the OrderSend() function is limited to 31 chars + zero terminator. Additionally, some servers might overwrite the 6 rightmost characters of the comment in some cases (more info here -> https://www.mql5.com/en/forum/101419). So maybe that's why u can't get the signal name to show?


If that's not it, then please make sure the data is proper. First make sure that the signal name appears in the data file in those lines. Also make sure that the format of the file is proper in those lines - if it's a CSV file, make sure there are no missing commas, etc.


I don't have any other ideas now...

 
gordon wrote >>

The comment field in the OrderSend() function is limited to 31 chars + zero terminator. Additionally, some servers might overwrite the 6 rightmost characters of the comment in some cases (more info here -> https://www.mql5.com/en/forum/101419). So maybe that's why u can't get the signal name to show?

If that's not it, then please make sure the data is proper. First make sure that the signal name appears in the data file in those lines. Also make sure that the format of the file is proper in those lines - if it's a CSV file, make sure there are no missing commas, etc.

I don't have any other ideas now...

Thank you very much.

The problem no longer exist. The bug was a confused coding, LOL

I changed the datastructure complete like the sample above.

It´s much better yet.

But the application ist very slow, because it is a only backtest program.

Maybe because at every price tick, the program will show, is there is a order to place.

Are you interested to search in the program some points for code optimizing?

Dear Joe

 
JoeDorman:

Are you interested to search in the program some points for code optimizing?

Dear Joe

If I have the time... Just post it here and I am sure people will help. You can also take a look at this recent thread for code optimization ideas: https://www.mql5.com/en/forum/123747.

Reason: