Equity oscillator by MQL5 means - page 5

 
joo:

Here is the code to read from a file:

WhyFileReadString() ?

You can useFileReadArray(), then you don't need to do a loop.

 
Serj_Che:

WhyFileReadString() ?

Wouldn't it be better to useFileReadArray(), then there is no need to do a loop.

Perhaps it is better. I'm just used to it. :)
 

Rosh:
Write equity values into a file. Then build indicator by these values. However, the data file has to be moved manually because during testing the files are written to the folder Agent_name/MQL5/Files.

Only now have I realised how complicated everything is.

But manually is clearly not the solution to this issue, as we are talking about hundreds of tests.

And it would seem: in the beginning there is available data, but - oh, Miracle! - the program is designed in such a way, that there is no possibility to save them somehow and somewhere until they are extracted and used programmatically!

I am not a professional programmer, but this situation is hard to comprehend.

Huge documentation..., vast possibilities in building, it would seem, everything and everything..., memory management, OOP, and here, in fundamentally simple and critically necessary (which, I hope, I have already explained) - a deadlock.

...And yet... Question!

Is there no possibility to write in the test mode in some forced-nearly-erasable program arrays, which subsequently could be used to build an indicator?

Including the possibility to pass through a global variable a pointer to such an array?

And what is the problem of storing and transferring data between the testing stage and the time of the main work, not in terms of current implementation, but in principle?

Renat mentioned hundreds of megabytes of data, but, firstly, why should we always reload data when we can provide for such possibility only at the programmer's explicit wish and, secondly, the amount of data in terms of the task at hand is much smaller and amounts to some thousands of digits.

Once again I declare that from a user's point of view, the option of manual transfer of files during multiple testing (and the market, due to its complexity, requires multiple testing) is absolutely inconvenient and unpromising, while I'm ready to argue with anyone that the dynamics of account indicators in direct correlation with price dynamics in the testing history is one of the most important in general.

What is the question of extending the visibility in the main mode of operations of opening files in read mode to the folder of the tester's files? What would be even a hypothetical threat in this?

And what's the issue of not being able to force storage of required data between main mode and test mode in RAM?

 

Use dll to write and read files from arbitrary folders on disk. Simply move the file writing and reading functions to the dll and that's it.

 
DV2010:

...And yet... Question!

Is there no possibility to write in the test mode in some forced-narrow program arrays, which subsequently could be used to build an indicator?


Try to set the FILE_COMMON flag when opening the file - https://www.mql5.com/ru/docs/constants/io_constants/fileflags

Identifier

Value

Description

FILE_COMMON

4096

Location of a file in the shared folder of all client terminals. This flag is used when opening files (FileOpen()), copying files (FileCopy(), FileMove()) and verifying the existence of files (FileIsExist())

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы ввода/вывода / Флаги открытия файлов
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы ввода/вывода / Флаги открытия файлов
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы ввода/вывода / Флаги открытия файлов - Документация по MQL5
 
Rosh:

Try specifying the FILE_COMMON flag when opening a file - https://www.mql5.com/ru/docs/constants/io_constants/fileflags

Run this script and see where it writes

//+------------------------------------------------------------------+
//|                                             Demo_File_Common.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"
#property script_show_inputs
//--- input parameters
input string   filename="file_common.txt";
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string common_folder=TerminalInfoString(TERMINAL_COMMONDATA_PATH);
//---
   int handle=FileOpen(filename,FILE_WRITE|FILE_COMMON);
   if(handle!=INVALID_HANDLE)
     {
      uint written=FileWrite(handle,"Общая папка всех терминалов - ",common_folder);
      if(written>0)
        {
         PrintFormat("Записано %d байт в общую папку всех терминалов - %s",written,common_folder);
        }
     }
   else
     {
      Print("Не удалось открыть на запись файл ",filename,".  Ошибка ",GetLastError());
     }

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

joo, Rash, thank you!

The shared folder option seems more... integrated.

The only thing that surprises is that when running this code, a message about failed write is displayed within the indicator, although the write itself does get done. Plus - still an open question how and when exactly it's better to write the data (separately for each tick, but it's resource-intensive, or at the very end - the whole array, but with array writing something is not quite clear yet and, besides, it's hard to understand how OnCalculated will work in this case for its extraction - in the second, it turns out the passage already after testing?)

And another question, somewhat off-topic, but on the question already touched upon yesterday.

Inserted in OnTick and in OnCalculated:

Print("ObjectsTotal =", ObjectsTotal(ChartID()));
but after test completion despite the presence of objects related to opening and closing positions (arrows and lines - visible in Terminal: Charts>Objects>Objects List), the return value is 0 for some reason.
 

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

The algorithm emerges as follows:

1) Run the expert in the tester.

2) Measured the value of interest.

3) Recorded the value in the file.

4) Write true to a separate file, which means we recorded 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 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.

Документация по MQL5: Файловые операции / FileWrite
Документация по MQL5: Файловые операции / FileWrite
  • www.mql5.com
Файловые операции / FileWrite - Документация по MQL5
 
DV2010:

joo, Rash, thank you!

The shared folder option seems more... integrated.

The only surprising thing is that when running this code within the indicator it displays a failed write message, although the write itself does get done.

I don't get any of that output. Give it a try:

//+------------------------------------------------------------------+
//|                                   Demo_File_Common_Indicator.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"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red

double buffer[];
input string   filename="file_common.txt";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,buffer,INDICATOR_DATA);

   string common_folder=TerminalInfoString(TERMINAL_COMMONDATA_PATH);
//---
   int handle=FileOpen(filename,FILE_WRITE|FILE_COMMON);
   if(handle!=INVALID_HANDLE)
     {
      uint written=FileWrite(handle,"Общая папка всех терминалов - ",common_folder);
      if(written>0)
        {
         PrintFormat("Записано %d байт в общую папку всех терминалов - %s",written,common_folder);
        }
     }
   else
     {
      Print("Не удалось открыть на запись файл ",filename,".  Ошибка ",GetLastError());
     }
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Rosh:

I don't get any of that. You should try it:

Rosh

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

2011.01.21 13:52:53     Core 1  2011.01.14 00:00:00   Expert removed because indicator 43 cannot load [4002]

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 though no error is written and file is created, records and file are empty.

#property copyright "Copyright 2010, Pavlov Sergei"
#property link      ""
#property version   "1.00"

#include <\..\Experts\_My\Classes\ClassExpert\ClassExpert.mqh>
ClassExpert Expert1;
int handle;
string common_folder;
string filename;

void OnInit(){
   Expert1.Init();
   //--
   filename="equity.txt";
   common_folder=TerminalInfoString(TERMINAL_COMMONDATA_PATH);
   int handle=FileOpen(filename,FILE_WRITE|FILE_COMMON);
}
void OnTick(){
   Expert1.OnTick();
   //---
   if(handle!=INVALID_HANDLE){
      uint written=FileWrite(handle, AccountInfoDouble(ACCOUNT_EQUITY),common_folder);
      PrintFormat("Expert OnTick: Записано %d байт в общую папку всех терминалов - %s",written,common_folder);
   }
   else{
      Print("Expert OnTick: Не удалось открыть на запись файл ",filename,".  Ошибка ",GetLastError());
   }  
}
void OnDeinit(const int reason){
   Expert1.Deinit();
   //---
   FileClose(filename);
}

2011.01.21 14:00:46     Core 1  connect closed
2011.01.21 14:00:46     Core 1  log file "C:\Program Files\MetaTrader 5\Tester\Agent-127.0.0.1-3000\logs\20110121.log" written
2011.01.21 14:00:46     Core 1  EURUSD,H1: 5516 ticks (23 bars) generated within 47 ms (total bars in history 6419, total time 3093 ms)
2011.01.21 14:00:46     Core 1  OnTester result 0
2011.01.21 14:00:46     Core 1  2011.01.14 23:59:59   order performed sell 0.15 at 1.33829 [#13 sell 0.15 EURUSD at 1.33829]
2011.01.21 14:00:46     Core 1  2011.01.14 23:59:59   deal performed [#13 sell 0.15 EURUSD at 1.33829]
2011.01.21 14:00:46     Core 1  2011.01.14 23:59:59   deal #13 sell 0.15 EURUSD at 1.33829 done (based on order #13)
2011.01.21 14:00:46     Core 1  2011.01.14 23:59:59   position closed due end of test at 1.33829 [buy 0.15 EURUSD 1.33593]
2011.01.21 14:00:46     Core 1  2011.01.14 22:00:00   Expert OnTick: Записано 0 байт в общую папку всех терминалов - C:\Documents and Settings\All Users\Application Data\MetaQuotes\Terminal\Common
2011.01.21 14:00:46     Core 1  2011.01.14 21:00:00   Expert OnTick: Записано 0 байт в общую папку всех терминалов - C:\Documents and Settings\All Users\Application Data\MetaQuotes\Terminal\Common
Reason: