Equity oscillator by MQL5 means - page 4

 
joo:

Declare two arrays Equity[] and Time[] on global level in EA.

Write the value of equity and time in the appropriate array when testing the EA.

Use a script to read the file at the end of testing and plot the equity on the required chart.

This is the best way for your purposes, I do not understand why you need an indicator.

Eh, if I could understand clearly and precisely what the difficulty is in what I have already done, then it would be easier...

( The changing values in OnCalculated are already there, so what else is needed? )

I've already thought about global variables, but by definition:

datetime  GlobalVariableSet(
   string  name,      // имя
   double  value      // устанавлимое значение
   );

And how to write an array or at least a reference to Value to be able to retrieve it later... Question.

As for the objects, I want to combine two things:

1. Lines of deals indicate depending on the result (red - all unprofitable, blue - all profitable)

2. and in the Indicator to build a graph of returns from the initial deposit at the bottom.

Otherwise, when using objects at a small scale, even the circles of deals prevent from seeing the price dynamics (of which, by the way, I want to get rid, but again, I do not know how).

I am speaking about testing Expert Advisors on large timeframes, where exactly this combination of curves, as I understand it now, will give the most complete idea of distribution of losing and profitable trades over history without necessity of traditional comparison of opening direction with the movement direction for each trade.

 

sergey1294:
Даже не знаю как вам объяснить. AccountInfoDouble(ACCOUNT_EQUITY) хранит последнее значение эквити. После тестирования как сказал Ренат индикатор инициилизируется заново и пересчитывается. По этому данные эквити накопленные в буфере индикатора за время прогона стираются.

And this - about erasure - is already "hot"!

But what prevents to write these values in OnCalculated to another foreign and "non-erasable" Indicator array, to restore then without more cumbersome and resource-intensive procedure of writing and reading files?

Or it's already a system-level question (of forced auto-unloading of arrays, which I can't get around)?

Although I read that such kind of resources (creation and deletion of variables in memory) can be managed manually as well...

 
DV2010:

Eh, if I could understand clearly and precisely what the difficulty is in what I've already done, then it would be easier to bail out...

( The changing values in OnCalculated are already there, so what else is needed? )

I've already thought about global variables, but by definition:

And how to write an array or at least a reference to Value to be able to retrieve it later... Question.

As for the objects, I want to combine two things:

1. Lines of deals indicate depending on the result (red - all unprofitable, blue - all profitable)

2. and in the Indicator to build a graph of returns from the initial deposit at the bottom.

Otherwise, when using objects at a small scale, even the circles of deals prevent from seeing the price dynamics (of which, by the way, I want to get rid, but again, I do not know how).

In my case I am speaking about testing Expert Advisors on large timeframes, where exactly this combination of curves, as I understand it now, will give the most complete picture of distribution of losing and profitable trades over history without necessity of traditional comparing opening direction with movement direction for each trade.

I meant the global variables of the program, not of the terminal.

The objects can be drawn even on a 1-minute chart to achieve the maximum accuracy (frequency). Then, after reading the objects from the chart, you can draw lines with the indicator (if there is an incredibly strong desire to do it with the indicator), you can even enter a correction factor in the indicator settings, so that you can view the equity of any initial deposit.

Again, all lines and diagrams can also be constructed by a script.

 
joo:

I meant global program variables, not terminal variables.

Objects can be plotted even on a one-minute chart for maximum accuracy (frequency). Then, by reading the objects from the chart, you can build lines using the indicator. You can even enter the correction factor in the indicator settings, so that you could see the equity of any initial deposit.

Concerning global variables of the program - as I understand it, there can be global variables in the Indicator's code and in the Expert Advisor's code.

One of these variables is an array of Indicator values from which they are erased after testing for some reason (probably of system nature).

But then I understand correctly that it is necessary to take the values for displaying the Equty history, be it the history from global variables, objects or from a file, in OnCalculated Indicator?

 
DV2010:

But then I understand correctly, that it is necessary to take values to display Equty history from global variables, objects or from a file, just in OnCalculated Indicator?

Exactly.
 
joo:
Exactly.

Will it be possible to use the global variables of the program in this case?

Because the global variables of the Expert Advisor will not be visible in the indicator, and then we have to use the global variables of the indicator, which, unlike the array of indicator values, should be "indelible" after the work of OnCalculated in the Expert Advisor mode?

And another, if possible, question about the objects of the current chart. I have tried to find how to extract the list of objects belonging to it, but it is still difficult to find. Could you suggest how to do it programmatically?

Документация по MQL5: Основы языка / Переменные / Глобальные переменные
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
  • www.mql5.com
Основы языка / Переменные / Глобальные переменные - Документация по MQL5
 
DV2010:

And also, if you can, a question about the objects in the current timetable. I've tried to find out how to extract the list of objects belonging to it, but it's still hard to find. Can you tell me how to do it programmatically?

Use the ObjectsTotal function to get the number of objects on the chart

int  ObjectsTotal(
   long  chart_id,     // идентификатор графика
   int   nwin=-1,      // индекс окна
   int   type=-1       // тип объекта     
   );
Get the chart ID using ChartID
 

Roughly, it goes something like this:

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2010, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
input int TradeHistoy=10000;

//Глобальные пременные
double   Equity[];
datetime EquityTime[];
int      cnt;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   ArrayResize(Equity,TradeHistoy);ArrayInitialize(Equity,0.0);
   ArrayResize(EquityTime,TradeHistoy);ArrayInitialize(Equity,1);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

//Записать накопленные данные в файл
   D_ArrayToCsv("DATA",Equity,TradeHistoy,";");
   D_ArrayToCsv("TIME",Equity,TradeHistoy,";");

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {

//В нужном месте эксперта проверить значение эквити
//записать эквити и время замера 
   if(cnt<TradeHistoy)
     {
      Equity[cnt]=AccountInfoDouble(ACCOUNT_EQUITY);
      EquityTime[cnt]=TimeTradeServer();
     }

  }
//+------------------------------------------------------------------+

void D_ArrayToCsv(string filename,double &mass[],int line,string Separator)
  {
// запись массива в файл
   string str;
   int handle=FileOpen(filename,FILE_CSV|FILE_WRITE,Separator);
//Цикл записи строчек в файл
   for(int l=0;l<line;l++)
     {
      str=DoubleToString(mass[l],8);
      FileWrite(handle,str);
     }
   FileClose(handle);
  }
//+------------------------------------------------------------------+
Then you can do whatever you like with the files you've created.
 

Thanks, Rosh, for the tip on objects, I think I can handle this part of my task now.

...But with file operations, which I've just tried to master, it's a bit more complicated (which I was actually afraid of!).

: )

A few surprises at once:

1. File writable in loop for some reason writes only one value instead of several.

2. Although the operation FileWriteArray successfullygets a pointer and checks whether the array being passed is not empty, the

the number of items written equals -1.

3.The documentation says that during testing the opening operations are performed in the MQL5\tester\files folder, and during the main operation - in MQL5/files, and therefore the question immediately arose as to how the Indicator could receive the data recorded during the test phase, during the main work (and the path to the folder is not simple and most likely may change over time - \tester\Agent-127.0.0.1-3000\MQL5\Files )

 
DV2010:


3.The documentation says that during the test phase opening operations are performed in the MQL5\tester\files folder, and during the main operation phase - in MQL5/files, and therefore the question arose as to how the Indicator could receive the data recorded during the test phase, during the main work (and the path to the folder is not simple and most likely may change over time - \tester\Agent-127.0.0.1-3000\MQL5\Files )

You have to transfer by hand.

Here's your code to read from the file:

void CsvTo1D_Array(string nameFile,double &array[],int line,string Separator)
{
        int end=0;
        int handle=FileOpen(nameFile,FILE_CSV|FILE_READ,Separator);

        if (handle!=1)
        {
                Alert("Файл ",nameFile," не найден!");
        }
        else
        {
                for (int l=0;l<line;l++)
                {
                        array[l]=StringToDouble(FileReadString(handle));
                }
                FileClose(handle);
        }
}
//+------------------------------------------------------------------+
Reason: