Questions from Beginners MQL5 MT5 MetaTrader 5 - page 929

 
Juer:

Code

Gives this result:

What am I doing wrong?

You can't go through all enumeration members. Built-in enumerations cannot be traversed as an array - like from "0" to "end". To traverse inline enumerations, you need to address each member of the enumeration directly, correctly. For example like this:

//+------------------------------------------------------------------+
//|                                              ENUM_TIMEFRAMES.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Print("PERIOD_CURRENT ",PERIOD_M1,"\n",
         "PERIOD_M2 ",PERIOD_M2,"\n",
         "PERIOD_M3 ",PERIOD_M3,"\n",
         "PERIOD_M4 ",PERIOD_M4,"\n",
         "PERIOD_M5 ",PERIOD_M5,"\n",
         "PERIOD_M6 ",PERIOD_M6,"\n",
         "PERIOD_M10 ",PERIOD_M10,"\n",
         "PERIOD_M12 ",PERIOD_M12,"\n",
         "PERIOD_M15 ",PERIOD_M15,"\n",
         "PERIOD_M20 ",PERIOD_M20,"\n",
         "PERIOD_M30 ",PERIOD_M30,"\n",
         "PERIOD_H1 ",PERIOD_H1,"\n",
         "PERIOD_H2 ",PERIOD_H2,"\n",
         "PERIOD_H3 ",PERIOD_H3,"\n",
         "PERIOD_H4 ",PERIOD_H4,"\n",
         "PERIOD_H6 ",PERIOD_H6,"\n",
         "PERIOD_H8 ",PERIOD_H8,"\n",
         "PERIOD_H12 ",PERIOD_H12,"\n",
         "PERIOD_D1 ",PERIOD_D1,"\n",
         "PERIOD_W1 ",PERIOD_W1,"\n",
         "PERIOD_MN1 ",PERIOD_MN1,"\n");
  }
//+------------------------------------------------------------------+
Files:
 
Vladimir Karputov:

You don't go through all the enumeration members. Built-in enumerations cannot be traversed as an array - like from "0" to "end". To access embedded enumerations, you must address each member of the enumeration directly, correctly. For example like this:

Who would have thought...
 
int val=(int)PERIOD_H1;

In an expression like this, val is 16385. What is this value?

I always thought int and enum could be easily converted to each other :(

 
Juer:
Who would have thought...

If you want to access a standard enumeration as an array, you must first declare and fill such an array yourself:

//--- variant 2
   ENUM_TIMEFRAMES timeframes_array[21]=
     {
      PERIOD_M1,PERIOD_M2,PERIOD_M3,
      PERIOD_M4,PERIOD_M5,PERIOD_M6,
      PERIOD_M10,PERIOD_M12,PERIOD_M15,
      PERIOD_M20,PERIOD_M30,PERIOD_H1,
      PERIOD_H2,PERIOD_H3,PERIOD_H4,
      PERIOD_H6,PERIOD_H8,PERIOD_H12,
      PERIOD_D1,PERIOD_W1,PERIOD_MN1
     };
   int size=ArraySize(timeframes_array);
   for(int i=0;i<size;i++)
      Print(i,": ",EnumToString(timeframes_array[i])," ",timeframes_array[i]);
 
Juer:

In an expression like this, val is 16385. What is this value?

I always thought int and enum could be easily converted to each other :(

My example above): reproduce and look at the numbers

 

I'm trying to set up an ftp file transfer.

Pressing Test button in Service-Settings-FTP allows to send file, i.e. passwords and path are correct.

I can 't send files via software. When sending file via script when executing SendFTP("File_1.txt", "/ftp_failes"); the terminal hangs. File_1.txt is in the Files directory.

Question. TerminalInfoInteger( TERMINAL_FTP_ENABLED) in my script =0. I can't find where and how it is configured at all, please advise.

And can you tell me what else I'm missing?
Использование облачных хранилищ для обмена данными между терминалами
Использование облачных хранилищ для обмена данными между терминалами
  • www.mql5.com
Все большее распространение в современном мире получают облачные технологии. Мы можем использовать хранилища разного объема, как платные, так и бесплатные. Можем ли мы их использовать в практическом трейдинге? В этой статье предлагается технология для обмена данными между терминалами, через облачные хранилища. Вы спросите: зачем для этого...
 
User_mt5:

I'm trying to set up an ftp file transfer.

Pressing Test button in Service-Settings-FTP allows to send file, i.e. passwords and path are correct.

I can 't send files via software. When sending file via script when executing SendFTP("File_1.txt", "/ftp_failes"); the terminal hangs. File_1.txt is located in the Files directory.

Question. TerminalInfoInteger( TERMINAL_FTP_ENABLED) in my script =0. I can't find where and how it is configured at all, please advise.

And can you tell me what else I missed?
The reason was: naming a file in Russian letters is not allowed.
The issue has been resolved.
 

I'm trying to read a string from a file:

#include <Files\FileTxt.mqh>
CFileTxt          m_file_txt;
m_file_handle=m_file_txt.Open(m_file_name,FILE_CSV|FILE_READ|FILE_COMMON|FILE_ANSI,10);
m_file_txt.Seek(0,SEEK_SET);
string str=m_file_txt.ReadString();

Here is the first line in the file:

,1,1,1,21,0,unmatch count,IGNORECRLF

I only get the character "," in str.

 
FILE_UNICODE

helped, but in this case the Chinese characters are read.

What if I need ANSI? Why can't I read a whole string when the FILE_ANSI flag?

 
Can:
   int cur_bars=Bars(_Symbol,PERIOD_CURRENT);

replace with:

   int cur_bars=Bars(_Symbol,_Period);
Reason: