Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1553

 
Thank you very much!
 

I have written a script that fills an array with time series values.

If you take the data of the current chart symbol, everything is fine

//+------------------------------------------------------------------+
//|                                                          444.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
  
  double M[10]={0};
 for(int i=0; i<10; i++)
 {
 M[i]=iOpen(Symbol(),PERIOD_H1,i);
 
 Alert(M[i]);
 }
 
   
  }
//+------------------------------------------------------------------+
//---
//---

But how to specify another symbol of the instrument?

It gives the error 'Symbol' - wrong parameters count

void OnStart()
  {
  
  double M[10]={0};
 for(int i=0; i<10; i++)
 {
 M[i]=iOpen(Symbol(EURUSD),PERIOD_H1,i);
 
 Alert(M[i]);
 }

 

I wanted to drop a fixed number of time series values into an array, and then work with this array. I understood that for this purpose either to write a loop into the array via

iOpen

for example. Or copy and paste a piece of history into an array via CopyOpen for example. Do I understand correctly?

Документация по MQL5: Доступ к таймсериям и индикаторам / CopyOpen
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyOpen
  • www.mql5.com
Функция получает в массив open_array исторические данные цен открытия баров для указанной пары символ-период в указанном количестве. Необходимо...
 
Novichokkk #:

Wrote a script that fills an array with time series values.

If you take the data of the current chart symbol, everything is fine

But how to specify another symbol of the instrument?

It gives the error 'Symbol' - wrong parameters count


Read more carefully the help on the used functions.

The Symbol() function returns a string with the name of the current symbol. If you need another one, you can specify it either as a string literal or create a string variable with the desired name and pass it to the iOpen() function.

void OnStart() {
   double M[10] = {0};
   for(int i = 0; i < 10; i++) {
      M[i] = iOpen("EURUSD", PERIOD_H1, i);

      Alert(M[i]);
   }
}
 
Yuriy Bykov #:

Read more carefully the help for the functions used.

The Symbol() function returns a string with the name of the current symbol. If another symbol is needed, we specify it either as a string literal or create a string variable with the desired name and pass it to the iOpen() function.

Thanks. I have read the help, but I haven't found an example of specifying another character. Thank you. I'd like to put your example directly into the help below.

 
Conditionally I want my code to start like this: if current time >=9:00, then I open a deal

Everything is almost ready, the code is partially there, the idea of how to do it is there, but on the implementation of the mind is not enough, help me
 
Hey, everybody. Help. I have written a function to calculate the profit of closed orders. It does not work in the tester. Please tell me what the problem is and where to look.
double History_Profit(datetime startTime)
  {
   double h_profit = 0.0;
   ulong ticket;
   HistorySelect(startTime, TimeCurrent()); // Выбор истории сделок в указанном диапазоне
   int total_h = HistoryDealsTotal(); // Общее количество сделок в истории

// Цикл проходит по всем сделкам в истории
   for(int i = total_h - 1; i >= 0; i--)
     {
      ticket = HistoryDealGetTicket(i); // Получение тикета сделки
      if(ticket > 0)
        {
         // Получение символа, магического числа и прибыли сделки
         string dealSymbol = HistoryDealGetString(ticket, DEAL_SYMBOL);
         long dealMagic = (long)HistoryDealGetInteger(ticket, DEAL_MAGIC);
         double dealProfit = HistoryDealGetDouble(ticket, DEAL_PROFIT);
         double dealCommission = HistoryDealGetDouble(ticket, DEAL_COMMISSION);
         double dealSwap = HistoryDealGetDouble(ticket, DEAL_SWAP);

         // Фильтрация сделок по символу и магическому числу
         if(dealSymbol == _Symbol && dealMagic == Magic)
           {
            // Суммирование прибыли, комиссии и свопа
            h_profit += dealProfit + dealCommission + dealSwap;
           }
        }
     }
    return (h_profit); // Возврат общей прибыли
  }
 
Robert Sadamon #:
Hey, everybody. Help. I have written a function to calculate the profit of closed orders. It does not work in the tester. Please tell me what the problem is and where to look.
Hi. Where does the Magic variable get its value? Is it global?
 
Yuriy Bykov #:
Hi. Where does the Magic variable get its value? Is it global?

Of course it is. It's in external variables.

 
Robert Sadamon #:
Hey, everybody. Help. I have written a function to calculate the profit of closed orders. It does not work in the tester. Please tell me what the problem is and where to look.

You have it all wrong, besides, an order cannot be closed/open, it can be set/deleted.

A position can be closed.