Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1022

 
ara66676:

Or let me ask a simpler question:

In the OnCalculate() function a loop is inserted, so it only goes through one iteration, the next one only when the graph is updated....

It looks like you need a psychic or a CODE TO STUDY.
 
bistreevseh:
Thank you very much! It works strangely I have admin rights, specifically for the terminal folder I gave all destructions to the owner, it helped, but then it stopped working. Then tried to read the log file using the FileReadStrArrayW (if I'm not mistaken with the name) read the empty lines, script hangs in ansi mode. Only FileReadCharArr was able to read the ansi codes. Maybe you have some example how to parse log file with your library? I would be very grateful!

Yes, there is a problem in reading the log now. It used to be easier.

The thing is that the file itself is ANSI-encoded, but the strings are now UNICODE.

Here is such script works:

#property strict
#property script_show_inputs

#include <FileFunctions.mqh>

input int NumLines = 10;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
  string sName = TimeToString(TimeLocal(), TIME_DATE);
  StringReplace(sName, ".", "");
  string sPath = TerminalPath() + "\\MQL4\\Logs\\" + sName + ".log";
  Print(sPath);
  
  if (!FileCheckW(sPath))
   {
    Print("Файл отсутствует!");
    return;
   }
    
  int hFile = FileOpenExistingW(sPath, GENERIC_READ, SHARE_READ);
  if (hFile == NULL)
   {
    Print("Файл не открыт!");
    return;
   }

  string asArray[];
  ArrayResize(asArray, NumLines);
  Print("hFile = ", hFile);
  for (int i = 0; i < NumLines; i++) asArray[i] = string(i) + "                                                                                                                                                                                                                                                          ";
  FileReadStrArrayMW(hFile, asArray, ArraySize(asArray), 0, NumLines);
  FileCloseHandle(hFile);
  for (int i = 0; i < NumLines; i++) Alert(asArray[i]);
 }

But it will work only if the log file is saved in UNICODE first!

I.e. the library works correctly. We need to think of a simple way to convert from ANSI-encoding of the file into UNICODE string array, or I should add to the library a function which would convert the encoding of strings when reading the file.

=====================

Option 1: You don't have to deal with arrays. Read the entire file as ANSI, convert it into UNICODE, and then parse it using MQL.

Variant 2. Read it as ANSI, write it to the current directory of the terminal and read it using MQL functions for CSV-files.

Option 3. Create a symbolic link to the log file in the sandbox using the function from the same library and read it using MQL functions for working with CSV files:

#property strict
#include <FileFunctions.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
  string sName = TimeToString(TimeLocal(), TIME_DATE);
  StringReplace(sName, ".", "");
  sName += ".log";
  
  string sPathLogs = TerminalPath() + "\\MQL4\\Logs\\" + sName;
  string sPathFiles = TerminalPath() + "\\MQL4\\Files\\" + sName;
  
  Print(sPathLogs);
  Print(sPathFiles);
  
  if (!FileCheckW(sPathLogs))
   {
    Print("Файл отсутствует!");
    return;
   }
  
  if (!FileCheckW(sPathFiles) && !FileSymbolicLinkW(sPathLogs, sPathFiles))
   {
    Print("Символьная ссылка не создана!");
    return;
   }
  
  int hFile = FileOpen(sName, FILE_READ|FILE_CSV|FILE_ANSI, '\t');
  if (hFile == INVALID_HANDLE)
   {
    Print("Файл не открыт!");
    return;
   }
  
  while (!FileIsEnding(hFile)) Alert(FileReadString(hFile));
  FileClose(hFile);
 }

In my opinion, this is the nicest and easiest option.

 

I am trying to write one channel indicator. I calculated values for drawing on the chart and put them into double tob[] and double tos[] arrays, but when I try to connect them to the buffer for drawing on the chart - in lines 25 and 26:

SetIndexBuffer(0, tob);
SetIndexBuffer(1, tos);

, these arrays instead of the required values, such as:

0/1.424/1.3679
1/1.42/1.3639

are filled in with the number 2147483647, like this:
0/2147483647/2147483647
1/2147483647/2147483647
2/2147483647/2147483647

How can this be cured?

Files:
channel1.mq4  7 kb
 
Are there any hotkeys to quickly switch between periods?
By pressing D , H1 switches to M15 , and by pressing U , switches to H1.
 

Help me find a template for MT4 to separate night and day.

Let's say the chart from 00:00 to 8:00 is in one colour and from 8:00 to 00:00 is in a different colour.

 

Greetings all.

Faced with this problem:

A snippet of robot code:

int per=Period();
if(per = 60)
{

Print("If the period is not H1, this line shouldn't be in the log");

Comment (...);

... //both bodies of the robot

...

...

}

implies that neither the robot body, nor the Print(...) line, nor the Comment(...) on the screen will be executed if a period other than H1 is enabled on the chart.

However, everything is executed on any period. Why ?

How to write correctly, that if the period on the chart does not match the specified - return control to the terminal. (By the way, I tried RETURN (0) - does not help - still prints everything...)

 
Dikons:

Greetings all.

Faced with this problem:

Robot code snippet:

int per=Period();
if(per = 60)
{

Print("If the period is not H1 - this line should not be in the logbook");

Comment (...);

... // then the body of the robot

...

...

}

implies that neither the body of the robot, nor the Print(...) string, nor Comment(...) on the screen will be executed if a period other than H1 is enabled in the chart.

However, everything is executed on any period. Why?

How to correctly register that if the timeframe does not correspond to the one set - return control to the terminal. (By the way, I tried RETURN (0) - it doesn't work - still prints everything...)

You are doing assignment, you need comparison if(per == 60)
 
Trader76:
You are doing assignment, while you need comparison if(per == 60)

Thank you comrade... I've got my brain all boiled over... I've had a significant break in programming - I've forgotten a lot of the little I know...

---

One more question... Fragment of search for max/mini first 8 hours in a day by terminal:

int h=TimeHour(TimeCurrent()); // find out current terminal hour (0...23)
if (h<8) return(0); // if no H1 of first 8 candles of day = leave...

double Maxi=High[iHighest(NULL,PERIOD_H1,MODE_HIGH,8,h-7)]; // define maximal first 8 candles of the day.

double Mini=Low[iLowest(NULL,PERIOD_H1,MODE_LOW,8,h-7)];


The last two lines do not work correctly if the chart period is set to something other than H1. Why? Because the robot has been explicitly assigned a period for calculations...

If you put H4 on the chart, for example, the robot will rebalance it using H4 candles (the same happens with other timeframes).

 
Dikons:

Thank you comrade... I've got my brain all boiled over... I've had a significant break in programming - I've forgotten a lot of the little I know...

---

One more question... Fragment of search for max/mini first 8 hours in a day by terminal:

int h=TimeHour(TimeCurrent()); // find out current terminal hour (0...23)
if (h<8) return(0); // if no H1 of first 8 candles of day = leave...

double Maxi=High[iHighest(NULL,PERIOD_H1,MODE_HIGH,8,h-7)]; // define maximal first 8 candles of the day.

double Mini=Low[iLowest(NULL,PERIOD_H1,MODE_LOW,8,h-7)];


The last two lines do not work correctly if the chart period is set to something other than H1. Why? Because the robot has been explicitly assigned a period for calculations...

If you put H4 on the chart, for example, the robot will rebalance it using H4 candles (the same happens with other timeframes).

Here you get the number of max/min bar: iHighest(NULL,PERIOD_H1,MODE_HIGH,8,h-7)

And then you insert for example bar number 2 and get:High[2] and on another timeframe you will get a value that is different from H1. Read about High.

iHigh(NULL,PERIOD_H1, iHighest(NULL,PERIOD_H1,MODE_HIGH,8,h-7))

 
please advise how to get a date without time e.g. after getting data from TimeLocal()

only by converting to string???