Equity oscillator by MQL5 means - page 6

 
joo:

It is best to write to the file as infrequently as possible, so it's best to do it as an array. The values should not be measured more often than once a minute, otherwise there will be problems with displaying them on the chart (and it is unreasonably resource intensive). That is, at the end of run. But this variant is also possible:

The algorithm emerges as follows:

1) Run expert in the tester.

2) We measured the value of interest.

3) Recorded this value to the file.

4) We write true to a separate file, which means we have a new value.

5) Start an infinite loop, the exit condition is false in the flag file.

6) In a separate chart the script reads the file with the flag, if there is a new value, draw a risk on the chart, write false to the file.

This is roughly what the visual mode of testing in the tester will look like.

Wait a bit, the contest will be over, maybe more elegant and beautiful solutions will be presented.

joo, Wait, what other value is of interest, if all values are of interest? :)

I think it's like this:

1. in the OnTick of the Expert Advisor, we form a programmatic array of count states,

2. at the end of testing, write this program array as a whole into a file (better to write each parameter into a separate file),

3. then fetch the specified one-dimensional array in the indicator OnInit

4. and copy it to the indicator array in OnCalculated.

The only problem is that even writing the array is still a problem for some reason (see above)

 
DV2010:

Wait, what's the other value of interest if I'm interested in all the values? :)

I don't care about all of them.

DV2010:

I think it goes like this

1. let's form program array of count states in OnTick of Expert Advisor,

2. at the end of testing, write this program array as a whole into a file (better to write each parameter into a separate file),

You can do that.

DV2010:

3. then fetch the specified one-dimensional array in the indicator OnInit

Why in oninite then? Do you only need to do it once? You said that you almost have to monitor the testing in real time.

DV2010:

4. and copy it to the indicator array in OnCalculated.

The only problem is that even writing the array is still a problem for some reason (see above)

The problem will be that you can't display the ticky data on the chart. Unless of course you collect the ticks, then ....... Anyway, I've already warned you - don't save data more than once per minute. But if you want to analyse, say, without binding to a trading instrument, you can also upload it to an excel file.

 

joo, no! :)

All I need so far is for the tester to do its job and get the oscillators of the curves of the account indicators I want on the history!

Tell me, in your opinion, why does my Expert Advisor, the code of which I cited above and link to below, refuse to record data?

 
DV2010:

Rosh

I can't understand what exactly the reason is, but unlike my indicators, when you start with yours, you get a message:

Now I've made a similar simple Expert Advisor, based on your code, which should write all Equity values into file (I've changed only output of all values, including zero bytes written, made variables global, and divided file opening and writing into OnInit and OnTick), but despite the absence of writing error and the file is created, the entries and file are empty.

Is there anything wrong?

FileClose(filename);
 
Rosh:

You didn't mess up anything, did you?

I did, but the difference with corrected ( FileClose(handle); ) is little felt :)

Still doesn't write! :) At the same time it keeps silent like a partisan (unless you count 0 bytes being written as an "explanation").

 
DV2010:

Messed up, but the difference with the corrected ( FileClose(handle); ) feels little :)

Still doesn't write! :) At the same time it's silent like a partisan (unless you count as an "explanation" that 0 bytes are written).

I don't know what you're doing there. Here's a variant that works

//+------------------------------------------------------------------+
//|                                          Demo_File_Common_EA.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//--- input parameters
input string   filename="equity.txt";
int handle;
string common_folder;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   common_folder=TerminalInfoString(TERMINAL_COMMONDATA_PATH);
//---
   handle=FileOpen(filename,FILE_WRITE|FILE_READ|FILE_COMMON);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   FileClose(handle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(handle!=INVALID_HANDLE)
     {
      FileSeek(handle,0,SEEK_END);
      uint written=FileWrite(handle,TimeToString(TimeCurrent()),AccountInfoDouble(ACCOUNT_EQUITY));
      if(written>0)
        {
         //PrintFormat("Записано %d байт в общую папку всех терминалов - %s",written,common_folder);
        }
     }
   else
     {
      Print("Не удалось открыть на запись файл ",filename,".  Ошибка ",GetLastError());
     }

  }
//+------------------------------------------------------------------+
 
Rosh:

I don't know what you're doing there. Here is an option that works

Great! So, to write to a file, in addition to FileWrite, you also need to set a pointer via FileSeek.
Документация по MQL5: Файловые операции / FileWrite
Документация по MQL5: Файловые операции / FileWrite
  • www.mql5.com
Файловые операции / FileWrite - Документация по MQL5
 

... On an issue already raised yesterday.

I inserted it into OnTick and into OnCalculated:

Print("ObjectsTotal =", ObjectsTotal(ChartID()));

but after testing, despite the presence of objects related to opening and closing positions (arrows and lines parameters in Terminal can be seen at: Charts>Objects>Objects List), the return value is 0 for some reason.

Who may tell me why it happens?

Can it be that the tester doesn't see the objects that are automatically created by itself?

 
DV2010:

Who can tell me why this is the case?

Does the tester not see the objects it creates automatically at all?

The graphical objects that are created during testing have nothing to do with the objects that are present on the chart that is opened after testing is finished. It means, there is no way to reach entry/exit arrows that will appear on the chart after testing is finished.
 
Rosh:
Graphical objects created during testing are not related in any way to objects on the chart that is opened after testing. In other words, there is no way to reach the entry/exit arrows that will appear on the chart after testing is completed.

This is exactly what I was afraid of!

Well, then I will have todraw my ownobjects, although all I need is just to change the colour of lines depending on the sign of result (profit or loss) of corresponding positions, because from the point of view of the fastest analysis of distribution of profitable and losing trades, the colour of result is much more important than the colour of direction. More important - if only because one can see the direction up or down on the chart anyway (both by the slope of the line and by the colour of arrows), while to understand the profit or loss of a trade using the standard approach it is necessary to compare the position type with the market direction every time).

And it's good if there are only a few positions in the tester. But what if there are hundreds or thousands? In the standard approach it would be impossible to see the distribution of losing and profitable positions in this case, while if loss-making trades were shown with red lines and profitable ones - with blue ones, the distribution can be most probably seen even at the smallest scale.

Why is this important? Because a trading system can behave differently at different timeframes, and to identify its weakest points and work through those points you need to have an idea of the price dynamics with which those series of losing trades are associated.

Many traders' requests are of a private nature and have both pluses and minuses, i.e. from the category of "to a greater or lesser extent". The possibility of setting the type of lines of deals at the interface of MetaTrader, in my opinion, would make the history analysis much more comfortable for many traders, while from the programmatic point of view, I think it is easy to do and there are no minuses. In other words, we need an alternative to the traditional variant of processing by position type, the variant of processing by trade result. So maybe you can add or at least put it to a vote among forum participants?

There may be two ways to implement it:

1. The connection of object drawing with the OnTcik Expert Advisor, so these objects can be changed programmatically.

2. Add setting on window interface level.

The oscillators of account states will partly solve this problem, but only partly, because the most convenient representation of the trades effectiveness - is their visual representation, closest to the price dynamics.

Speaking in general, in my opinion, the tester and the visualization of the deal efficiency are the weakest point of the current version 5. So far we have here only the legacy of the previous versions in the form of the Chart and Results, but both of them allow us to judge only about the Expert Advisor's effectiveness in general, and even that can give a deceptive impression (the overall Equity graph of the Expert Advisor has been frequently shown to be steadily ascending, while a closer examination will reveal bigger relative drawdowns and other "surprises").