Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1111

 
Roman Sharanov:

Nothing has changed, it still shows e+321

You haven't shown the full code. You don't know what kind of array it is and how big it is, in which you get data from the indicator.

 
Ai I was very stupid, I made a silly mistake in the initialisation and that's why everything didn't work, thanks for the help
 
Vitaly Muzichenko:

It works, it's the easiest solution!

void OnStart()
{
  double d = 1.5;
  
  Print((long)d == d ? (string)(long)d : (string)d);
}
 
Roman Sharanov:

Here's an example: copies three items - from bar #0, from bar #1 and from bar #2 from all indicator buffers.

Prints the value from bar #0 from each buffer:

//+------------------------------------------------------------------+
//|                                           Simple Heiken_Ashi.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.000"
/*
   barabashkakvn Trading engine 3.025
*/
int    handle_iCustom;              // variable for storing the handle of the iCustom indicator 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iCustom
   handle_iCustom=iCustom(Symbol(),Period(),"Examples\\Heiken_Ashi");
//--- if the handle is not created 
   if(handle_iCustom==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double heiken_ashi_open[],heiken_ashi_high[],heiken_ashi_low[],heiken_ashi_close[];
   ArraySetAsSeries(heiken_ashi_open,true);
   ArraySetAsSeries(heiken_ashi_high,true);
   ArraySetAsSeries(heiken_ashi_low,true);
   ArraySetAsSeries(heiken_ashi_close,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iCustom,0,start_pos,count,heiken_ashi_open) || 
      !iGetArray(handle_iCustom,1,start_pos,count,heiken_ashi_high) || 
      !iGetArray(handle_iCustom,2,start_pos,count,heiken_ashi_low) || 
      !iGetArray(handle_iCustom,3,start_pos,count,heiken_ashi_close))
     {
      return;
     }
   Comment(DoubleToString(heiken_ashi_open[0],Digits()),"\n",
           DoubleToString(heiken_ashi_high[0],Digits()),"\n",
           DoubleToString(heiken_ashi_low[0],Digits()),"\n",
           DoubleToString(heiken_ashi_close[0],Digits()));
  }
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- 

  }
//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
double iGetArray(const int handle,const int buffer,const int start_pos,
                 const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      Print("This a no dynamic array!");
      return(false);
     }
   ArrayFree(arr_buffer);
//--- reset error code 
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(false);
     }
   return(result);
  }
//+------------------------------------------------------------------+
Files:
 
fxsaber:

It's just what you need, very "light". Thank you!

 

Please tell me the path to the shared folder for MT5 terminals

//--- открытие файла для записи, с флагом совестного пользования для чтения
   int han=FileOpen(subfolder+"\\experts\\files\\"+folder+".csv",FILE_WRITE|FILE_SHARE_READ|FILE_ANSI,",");
   if(han!=INVALID_HANDLE)// если файл открыт удачно
     {
      //ЗДЕСЬ ПРОЦЕДУРА ЗАПИСИ В ФАЙЛ
     }
 
yiduwi:

Can you tell me the path to the shared folder for MT5 terminals?

The FILE_COMMON flag is responsible for the shared folder of all client terminals.

Документация по MQL5: Константы, перечисления и структуры / Константы ввода/вывода / Флаги открытия файлов
Документация по MQL5: Константы, перечисления и структуры / Константы ввода/вывода / Флаги открытия файлов
  • www.mql5.com
Файл открывается для чтения. Флаг используется при открытии файлов (FileOpen()). При открытии файла обязательно должен быть указан флаг FILE_WRITE и/или флаг FILE_READ Файл открывается для записи. Флаг используется при открытии файлов (FileOpen()). При открытии файла обязательно должен быть указан флаг FILE_WRITE и/или флаг FILE_READ Файл...
 
yiduwi:

Tell me the path to the shared folder for MT5 terminals

Add FILE_COMMON

https://www.mql5.com/ru/docs/constants/io_constants/fileflags

find folder: in terminal: file-open data directory - in Windows Explorer one level up and it will be \Common\Files folder

 
Thank you
 
Good afternoon, fellow programmers! Forgive me for the dumbest question, but it's been bugging me. How the program is executed, or rather how the terminal reads lines, what is the sequence of their execution, or is there any video to see and understand how it all happens? because learning a language without knowing how it's read by a program is hard!!!!
Reason: