Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 67

 
Aliaksandr Kryvanos:
bool WriteToFile(int FileHandle,string DataToWrite)
  {
// Receives the number of bytes written to the file. Note that MQL can only pass
// arrays as by-reference parameters to DLLs
   int BytesWritten[1]={0};

// Get the length of the string
   int szData=StringLen(DataToWrite);

// Do the write
   WriteFile(FileHandle,DataToWrite,szData,BytesWritten,0);

// Return true if the number of bytes written matches the expected number
   return (BytesWritten[0] == szData);
  }

I want to write a line to the file with translations to a new line, but it doesn't work, this code is from herehttps://www.mql5.com/en/forum/118999

this code writes a line with spaces after each letter, I need a replacement for FileWrite() but it works

Read it here.
 
Thanks, I'd rather use this articlehttps://www.mql5.com/ru/articles/1540 but still, I'd like to use WriteFile() from kernel32.dll and make it work with line translation
Файловые операции через WinAPI
Файловые операции через WinAPI
  • 2008.07.03
  • MetaQuotes Software Corp.
  • www.mql5.com
Исполнительная среда MQL4 основана на концепции безопасной "песочницы": чтение и запись средствами языка разрешены только в определенных папках. Это защищает пользователя MetaTrader 4 от потенциальной опасности испортить важные данные на жестком диске компьютера. Но иногда все же бывает необходимость покинуть безопасную зону. Как это сделать легко и правильно - об этом статья.
 
Artyom Trishkin:
Please read up on what a function is. Then you'll understand that the array declared in the function body will be local - out of sight of the rest of the program.

That is, I need 3 functions

1) where I declare it

2) which one I will use to add values to it

3) which one I will use to delete them from the database?

right?

 
trader781:

That is, I need 3 functions

1) where I declare it

2) which one I will use to add values to it

3) which one I will use to delete them from the database?

correct?

Read here carefully.
Учёт ордеров - Создание обычной программы - Учебник по MQL4
Учёт ордеров - Создание обычной программы - Учебник по MQL4
  • book.mql4.com
Учёт ордеров - Создание обычной программы - Учебник по MQL4
 
Alekseu Fedotov:
Read it carefully.

Ok, make a void function that will write orders into a two-dimensional array (ticket + lot)

get a picture of this type

            if(Ask>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в плюс и это 5 ордер в списке
              {
               ticket=OrderSend(Symbol(),OP_BUY,(лот2 ордера+лот4 ордера),Ask,50,0,0,"",Magic,0,clrAzure);
               Функция записи();
              }  
и если массив локальный то каким образом я буду оттуда вытаскивать данные в текущую команду?
ретурн не возвращает данные массивов, а если засунуть туда выражение извлечения его будет не видно

 
trader781:

Ok, make a void function that will write orders into a two-dimensional array (ticket + lot)

get a picture of this type

            if(Ask>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в плюс и это 5 ордер в списке
              {
               ticket=OrderSend(Symbol(),OP_BUY,(лот2 ордера+лот4 ордера),Ask,50,0,0,"",Magic,0,clrAzure);
               Функция записи();
              }  
и если массив локальный то каким образом я буду оттуда вытаскивать данные в текущую команду?
ретурн не возвращает данные массивов, а если засунуть туда выражение извлечения его будет не видно

Please tell me why I need to write tickets and lots in the array, besides learning how to use the array? If you turn off your computer the whole array will crash, why make it so unreliable in the first place? Unless of course it makes sense to learn how to work with arrays...)
 
Vladimir Zubov:
Tell me please, why write the tickets and lots into an array at all, other than to learn how to use an array ? When you turn off your computer the whole array will crash, why make it so unreliable in the first place? Unless of course the point is to learn how to work with arrays...)

ok, find me 6 orders in an uneven grid the easy way, or 8 by ticketing

I need it as long as there is a grid of orders, then let it roll.

well the goal i stated in the code above
 
trader781:

ok, find me 6 orders in an uneven grid the easy way, or 8 by ticketing

I need it as long as there is a grid of orders, then let it roll.

Well, I stated the goal in the code above

Here, there's a chance to sort by several parameters, so a two-dimensional array is used.

I hope you will understand how to use it, if not - to freelance)

double BPosMass[][2];
double SPosMass[][2];

void OnTick()
{
// Заполняем массивы
int b=-1,s=-1; // Объявим переменные с минусом
  for(int i=0; i<OrdersTotal(); i++) {
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
    if(OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic || Magic<0)) {
     if(OrderType()==OP_BUY) {
      b++;
       ArrayResize(BPosMass,b+1);
       BPosMass[b][0]= (int)OrderOpenPrice();// Для сортировки = можно сортировать по: OrderProfit(), OrderLots(), OrderTicket(), OrderOpenTime()
       BPosMass[b][1]= OrderTicket(); // Для чтения
     }
     if(OrderType()==OP_SELL) {
      s++;
       ArrayResize(SPosMass,s+1);
       SPosMass[s][0]= (int)OrderOpenPrice();// Для сортировки = можно сортировать по: OrderProfit(), OrderLots(), OrderTicket(), OrderOpenTime()
       SPosMass[s][1]= OrderTicket(); // Для чтения
     }
  }}} // конец записи массив

// Читаем отсортированный массив с тикетами
// Buy
  if(b>0) { // Если он не пустой и больше двух элементов - [0], иначе будет ошибка: "Выход за пределы массива"
    ArraySort(BPosMass, WHOLE_ARRAY, 0, MODE_ASCEND); // Отсортируем по первому измерению
    // Работа с полученными данными
    Comment("Самый старый Buy тикет: ",    BPosMass[0][1],
            "\nПоследний Buy тикет: ",     BPosMass[b][1],
            "\nПредпоследний Buy тикет: ", BPosMass[b-1][1]
           );

  } // end Buy

// Sell
  if(s>0) { // Если он не пустой и больше двух элементов - [0], иначе будет ошибка: "Выход за пределы массива"
    ArraySort(SPosMass, WHOLE_ARRAY, 0, MODE_ASCEND); // Отсортируем по первому измерению
    // Работа с полученными данными
    Comment("Самый старый Sell тикет: ",    SPosMass[0][1],
            "\nПоследний Sell тикет: ",     SPosMass[s][1],
            "\nПредпоследний Sell тикет: ", SPosMass[s-1][1]
           );

  } // end Sell
  
// Конец функции OnTick()
}
 
Vitaly Muzichenko:

Here, there's a chance to sort by several parameters, so a two-dimensional array is used.

I hope you understand how to use it, if not, go to freelance)

double BPosMass[][];
How to get a dimensionless one beforehand, it doesn't work with empty values
 
trader781:
how to get a dimensionless one beforehand, it doesn't work with empty values

It is dimensionless as it is, but it is two-dimensional, and you can put a dimensionless number of elements in two dimensions.

What are you doing anyway, do you have any idea what the result of the work you do should be? Or are you making logic up as you go along?

Reason: