Errors, bugs, questions - page 2614

 
Andrei Kossarev:
Reading binary from indicator does not work, similar code from EA works without problems!

The ChartScreenShot in the indicators most likely works asynchronously.

 
fxsaber:

Most likely ChartScreenShot in indicators works asynchronously.

Checked it, that's why I put in a loop

 
Andrei Kossarev:

I checked, that's why I put in a loop

Ending the loop does not guarantee that there is a file.

 

Andrei Kossarev:
Не работает чтение бинарного файла из индикатора, аналогичный код из советника работает без проблем!

void TestPhoto() {
   string name;
   MqlDateTime  dtLocal;
   TimeToStruct(TimeLocal(), dtLocal);
   string date = IntegerToString(dtLocal.year) + IntegerToString(dtLocal.mon, 2, '0') + IntegerToString(dtLocal.day, 2, '0');
   string time = IntegerToString(dtLocal.hour, 2, '0') + "." + IntegerToString(dtLocal.min, 2, '0') + "." + IntegerToString(dtLocal.sec, 2, '0');
   name = "ScreenShots/" + date + "/" + _Symbol + "_" +date + "_" + time + ".png";
   
   if (!ChartScreenShot(0, name, 1920,1200, ALIGN_RIGHT))
      return;

   ResetLastError();
   
   for (int i=0; i < 100000; i++){
      if (FileIsExist(name,false) && FileSize(name) > 0)
         break;
   }
   //---
   int flags=FILE_READ|FILE_BIN|FILE_SHARE_READ;

   //---
   int file=FileOpen(name,flags);
   if(file<0) {
      Print("Операция FileOpen неудачна, ошибка ",GetLastError());
      return;
}
   uchar photo[];
   FileReadArray(file,photo);
   FileClose(file);
   
   Print(ArraySize(photo));
}

Doesn't it bother you that there are errors in your code?

ulong  FileSize( 
   int  file_handle      // handle файла 
   );

The FileSize function expects int variable and you put string...

 
//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots   1
#property indicator_buffers 1
#include <Trident\TCoreMain.mqh>
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   ::EventSetMillisecondTimer(500);
   return(INIT_SUCCEEDED);
  }
  
  void OnDeinit(const int reason) {
   ::EventKillTimer();
}

void OnTimer() {
   ::EventKillTimer();
   TestPhoto();
}
//+------------------------------------------------------------------+
//| 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);
  }
//+------------------------------------------------------------------+

void TestPhoto() {
   string name;
   MqlDateTime  dtLocal;
   TimeToStruct(TimeLocal(), dtLocal);
   string date = IntegerToString(dtLocal.year) + IntegerToString(dtLocal.mon, 2, '0') + IntegerToString(dtLocal.day, 2, '0');
   string time = IntegerToString(dtLocal.hour, 2, '0') + "." + IntegerToString(dtLocal.min, 2, '0') + "." + IntegerToString(dtLocal.sec, 2, '0');
   name = "ScreenShots/" + date + "/" + _Symbol + "_" +date + "_" + time + ".png";
   
   if (!ChartScreenShot(0, name, 1920,1200, ALIGN_RIGHT))
      return;

   ResetLastError();
   
   //---
   int flags=FILE_READ|FILE_BIN|FILE_SHARE_READ;

   //---
   int file=FileOpen(name,flags);
   if(file<0) {
      Print("Операция FileOpen неудачна, ошибка ",GetLastError());
      return;
   }
   
   for (int i=0; i < 100000; i++){
      if (FileSize(file) > 0)
         break;
   }
   
   uchar photo[];
   FileReadArray(file,photo);
   FileClose(file);
   
   Print(ArraySize(photo));
}

Corrected code, still doesn't work

 
Andrei Kossarev:

Corrected code, still doesn't work

Try splitting the code into two separate functions:

1. Read file and follow up.

2. Taking a screenshot.

And if the result is null, then try flagging. And sequence of function calls, first try to read, but by the flag read is skipped, then skim, by the flag is executed and the flag is switched. And after that, on the next tick the file is read.

 

Suggestion - add another field to store user information, not accessible to change by the broker and mandatory to be saved on rollovers.

In short, a non-destructible field that can only be changed by the user.

 
Михаил:

Suggestion - add another field to store user information, not accessible to change by the broker and mandatory to be saved on rollovers.

In short, a non-destructible field that can only be changed by the user.

Plus 100600
 
Vladislav Andruschenko:
Plus 100600

No it won't, the server part of MT needs to be rewritten, it hasn't been done in 10+ years, so it will be in the near future, use what you were given - file, global variables of the terminal, DB

i write the state of orders in the file, i used a template of my universal databaseat https://www.mql5.com/ru/forum/85652/page17#comment_12370424

here is the latest offer from the developers - a SQLite databasehttps://www.mql5.com/ru/forum/327940

 
Igor Makanu:

No it won't, the server part of MT needs to be rewritten, it hasn't been done in 10+ years, so it will be in the near future, use what you were given - file, global variables of the terminal, DB

i write the state of orders in the file, i used a template of my universal databaseat https://www.mql5.com/ru/forum/85652/page17#comment_12370424

this is the latest offering from the developers - a SQLite DBhttps://www.mql5.com/ru/forum/327940


Yes I also store the information in a DB. But ... but ... but ...