Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1025

 

I can't figure out what the optimiser is swearing at?

2019.04.10 13:26:50.177 Core 8  genetic pass (13, 498) tested with error "critical runtime error 502 in OnTick function (array out of range, module Experts\xxxxxx.ex5, xxxxxx.mq5, line 384, col 73)" in 0:00:00.102

The code it is blaming

            if(profit_level == EMPTY_VALUE
               && ((pos_set.order_direction == trend_up && (buffer_HMA7C[2] <= buffer_HMA7C[1] && buffer_HMA7C[1] >= buffer_HMA7C[0]) && buffer_HMA7C[0] > pos_set.order_price)
               ||  (pos_set.order_direction == trend_dn && (buffer_HMA7C[2] >= buffer_HMA7C[1] && buffer_HMA7C[1] <= buffer_HMA7C[0]) && buffer_HMA7C[0] < pos_set.order_price))
              )

This is the buffer of the custom indicator, the handle of which was received correctly and the data are also copied correctly

      handle_HMA7C = iCustom(Symbol(),0,"my_used\\my_HMA7C_121",period_HMA7C);
      if(handle_HMA7C == INVALID_HANDLE)                                   // проверяем наличие хендла индикатора
      {
         Print("Не удалось получить хендл индикатора handle_HMA7C");       // если хендл не получен, то выводим сообщение в лог об ошибке
         return(INIT_FAILED);                                              // завершаем работу с ошибкой
      }
      else
      {
         Print("Получен хендл индикатора handle_HMA7C");
         ChartIndicatorAdd(ChartID(),0,handle_HMA7C);                      // подключаем индикатор к графику
      }
.........................................
//+------------------------------------------------------------------+
bool copyBuffers()
{
   int   nbars = 11;
   
   ArrayFree(rates);
   ArrayFree(buffer_HMA7C);
      
   ResetLastError();
   
   if(CopyRates(Symbol(),0,0,nbars,rates) < nbars) return(false);
   
      if(CopyBuffer(handle_HMA7C,0,1,nbars,buffer_HMA7C) < nbars )         // копируем данные из индикаторного массива в массив buffer_HMA7C
      {                                                                                         // если не скопировалось
         Print("Не удалось скопировать данные из индикаторного буфера в buffer_HMA7C");         // то выводим сообщение об ошибке
         Print("LastError = "+string(GetLastError()));
         return(false);                                                                         // и выходим из функции
      }
}


 
Hello! What is MQL5InfoString orMQL5InfoInteger? Where can I read about it? I couldn't find it in the Help!
 
Tango_X:
Hello! What is MQL5InfoString or MQL5InfoInteger? Where can I read about it? I could not find it in the Help!
How could you search for it that you could not find it?
Документация по MQL5: Проверка состояния / MQLInfoString
Документация по MQL5: Проверка состояния / MQLInfoString
  • www.mql5.com
Проверка состояния / MQLInfoString - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Alexey Viktorov:
How did you search that you couldn't find it?

It's strange, in the editor I press F1 against this function and it doesn't show anything... thank you!

 
#include <Trade\Trade.mqh>

CTrade trader;
int OnInit()
  {

   trader.SetExpertMagicNumber(1);

   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
//---
  
  }
void OnTick()
  {
      Print("тикет ",OrderGetTicket(0));
      Print("магик ",OrderGetInteger(ORDER_MAGIC));
      if (OrderGetInteger(ORDER_MAGIC)==1)
      {
         trader.OrderDelete(OrderGetTicket(0));
      }
  }

After deleting the order magik=1. What to do?

 
ascerdfg:

After deleting the order magic=1. What to do?

You have deleted a LOCAL order. What is the connection with magic being "1"? More precisely, what exactly is it that you don't like or are confused about?

 
Vladimir Karputov:

You have deleted a LOCAL order. What is the connection with magic being "1"? More precisely, what exactly is it that you don't like or are confused about?

         trader.OrderDelete(OrderGetTicket(0));
Keeps deleting non-existent orders
 
ascerdfg:
Keeps deleting non-existent orders

According to your code, this is exactly what will happen: you force a command on each tick to delete a REPLACEMENT order with a tick "0".

Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
Vladimir Karputov:

In your code, this is exactly what will happen: you will forcibly issue a command on each tick to delete a LOCKED order with a tick "0".

no, that's not true, only if magik=1

 
ascerdfg:

no it's not, only if magik=1

The point doesn't change - you are trying to delete a pending order with a ticket "0" on every tick.

And who says that you have a pending order with a "0" tick on every tick? Have you checked how many pending orders there are? And how do you know that ....?