Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1380

 

I assume that if the current bar has an index with its own time, then this combination will never change.
Or is it possible that as a result of history paging this index will be assigned to some historical bar and the current bar will get a new index, larger by the number of paged bars?

Also in other words:
is it correct to understand that the current bar becomes available (index, price and time) only after a full history swap and its parameters never change thereafter?

 

Please tell me how to get the number of rows in a MySQL table

//--- Выставленные позиции
struct PositionFib
  {
   int               ID;            // Индификатор
   int               ur;            // Уровень
   int               per;           // Период
   int               type;          // Тип ордера
   double            price;         // Цена Открытия
   double            priceTP;       // Цена Профита
   double            priceSL;       // Цена Стопа
   double            lot;           // Лот
   datetime          time;          // Время
   string            key;           // Ключ
  } position_buff[];
//--- заблокируем базу данных перед выполнением транзакций
   DatabaseTransactionBegin(database);
   int request=DatabasePrepare(database, "SELECT COUNT(*) FROM POSITION");
   DatabaseReadBind(request, person)
   id=person.ID;
  

Returns an error

Get last ID

also try this, can't get number of rows

 int request=DatabasePrepare(database, "SELECT COUNT(*) FROM POSITION");
   id= DatabaseRead(request);
 

What's wrong, why can't I get a value from the query?

//--- открываем/создаем базу данных в общей папке терминалов
   int database=DatabaseOpen(filename+".sqlite", DATABASE_OPEN_READWRITE | DATABASE_OPEN_CREATE | DATABASE_OPEN_COMMON);
   if(database==INVALID_HANDLE)
     {
      Print("SaveStats: ", filename, " открываем/создаем базу данных в общей папке терминалов ", GetLastError());
      return;
     }

//--- заблокируем базу данных перед выполнением транзакций
   DatabaseTransactionBegin(database);
   int request=DatabasePrepare(database, "SELECT COUNT(*) FROM POSITION");
   int id= DatabaseRead(request);

If I check the query against the database, it returns as is



Right

 int id= DatabaseRead(request);

Database is a bool , and id is int


How do I get the query result out?


It worked. I created an extra sql class

//--- заблокируем базу данных перед выполнением транзакций
   DatabaseTransactionBegin(database);
   int request=DatabasePrepare(database, "SELECT COUNT(*) FROM POSITION");
   DatabaseReadBind(request,sql);
 

Several seconds elapse between unloading the indicator and calling DeInit.

Why is there a pause and can it be avoided?

 
An order opens on every tick. How do I fix it so that only one order opens?

I am using this block, taken from the documentation (both tp and sl)

//+------------------------------------------------------------------+

void Open_order_BUY()

  {

    double bid = SymbolInfoDouble(Symbol(),SYMBOL_BID),

      ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);

    //--- объявление и инициализация запроса и результата

   MqlTradeRequest request={};

   MqlTradeResult  result={};

//--- параметры запроса

   request.action   =TRADE_ACTION_DEAL;                     // тип торговой операции

   request.symbol   =Symbol();                              // символ

   request.volume   =0.01;                                   // объем в 0.1 лот

   request.type     =ORDER_TYPE_BUY;                        // тип ордера

   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // цена для открытия

   request.sl       =bid-SL*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // SL

   request.tp       =ask+TP*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // TP

   request.deviation=5;                                     // допустимое отклонение от цены

   request.magic    =EXPERT_MAGIC;                          // MagicNumber ордера

//--- отправка запроса

   if(!OrderSend(request,result))

       PrintFormat("OrderSend error %d",GetLastError());     // если отправить запрос не удалось, вывести код ошибки

//--- информация об операции

   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

  }

  

//+------------------------------------------------------------------+ 

void Open_order_SELL()

  {

  

    double bid = SymbolInfoDouble(Symbol(),SYMBOL_BID),

      ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);

//--- объявление и инициализация запроса и результата

   MqlTradeRequest request={};

   MqlTradeResult  result={};

//--- параметры запроса

   request.action   =TRADE_ACTION_DEAL;                     // тип торговой операции

   request.symbol   =Symbol();                              // символ

   request.volume   =0.01;                                   // объем в 0.2 лот

   request.type     =ORDER_TYPE_SELL;                       // тип ордера

   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_BID); // цена для открытия

   request.sl       =ask+SL*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // SL

   request.tp       =bid-TP*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // TP

   request.deviation=5;                                     // допустимое отклонение от цены

   request.magic    =EXPERT_MAGIC;                          // MagicNumber ордера

//--- отправка запроса

   if(!OrderSend(request,result))

      PrintFormat("OrderSend error %d",GetLastError());     // если отправить запрос не удалось, вывести код ошибки

//--- информация об операции

   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

  }


 
Ivan Butko #:
An order opens on every tick. How can I fix to have only one order open?

I am using this block, taken from documentation (both tp and sl)

//+------------------------------------------------------------------+

void Open_order_BUY()

  {

    double bid = SymbolInfoDouble(Symbol(),SYMBOL_BID),

      ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);

    //--- объявление и инициализация запроса и результата

   MqlTradeRequest request={};

   MqlTradeResult  result={};

//--- параметры запроса

   request.action   =TRADE_ACTION_DEAL;                     // тип торговой операции

   request.symbol   =Symbol();                              // символ

   request.volume   =0.01;                                   // объем в 0.1 лот

   request.type     =ORDER_TYPE_BUY;                        // тип ордера

   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // цена для открытия

   request.sl       =bid-SL*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // SL

   request.tp       =ask+TP*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // TP

   request.deviation=5;                                     // допустимое отклонение от цены

   request.magic    =EXPERT_MAGIC;                          // MagicNumber ордера

//--- отправка запроса

   if(!OrderSend(request,result))

       PrintFormat("OrderSend error %d",GetLastError());     // если отправить запрос не удалось, вывести код ошибки

//--- информация об операции

   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

  }

  

//+------------------------------------------------------------------+ 

void Open_order_SELL()

  {

  

    double bid = SymbolInfoDouble(Symbol(),SYMBOL_BID),

      ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);

//--- объявление и инициализация запроса и результата

   MqlTradeRequest request={};

   MqlTradeResult  result={};

//--- параметры запроса

   request.action   =TRADE_ACTION_DEAL;                     // тип торговой операции

   request.symbol   =Symbol();                              // символ

   request.volume   =0.01;                                   // объем в 0.2 лот

   request.type     =ORDER_TYPE_SELL;                       // тип ордера

   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_BID); // цена для открытия

   request.sl       =ask+SL*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // SL

   request.tp       =bid-TP*SymbolInfoDouble(Symbol(),SYMBOL_POINT);                                   // TP

   request.deviation=5;                                     // допустимое отклонение от цены

   request.magic    =EXPERT_MAGIC;                          // MagicNumber ордера

//--- отправка запроса

   if(!OrderSend(request,result))

      PrintFormat("OrderSend error %d",GetLastError());     // если отправить запрос не удалось, вывести код ошибки

//--- информация об операции

   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

  }


Resolved.

 

How do I extend the line to the right? Further than the current bar.

There are time and price coordinates. The price is clear, but how to set the time (I tried iTime(Symbol(), PERIOD_CURRENT, 0), but its index is zero)

 
Ivan Butko #:

How do I extend the line to the right? Further than the current bar.

There are time and price coordinates. I understand the price, but how to set the time (I tried iTime(Symbol(), PERIOD_CURRENT, 0), but its index is zero)

iTime(Symbol(), PERIOD_CURRENT, 0) + PeriodSeconds()*5 // 5 баров
 

Good afternoon.

Here's a question:

I am writing an indicator that draws zones with DRAW_FILLING drawing style. There are several other indicators, including a lot of muwings, on the chart in addition to the drawn zone. When a zone is drawn, the lines of other indicators sharply change their colours.

The question: can we draw the zones in MT5 in such a way, that their colour does not overlap and does not change the colours of lines of other indicators?

P.S. I dug all properties of indicator buffers (methods like PlotIndexSetInteger), there is nothing similar.

P.S2. attached is a screenshot from MT5.

Files:
u68ufb.PNG  49 kb
 
satorifx #:

Good afternoon.

Here's a question:

I am writing an indicator that draws zones with DRAW_FILLING drawing style. There are several other indicators, including a lot of muwings, on the chart in addition to the drawn zone. When a zone is drawn, the lines of other indicators sharply change their colours.

The question: can we draw the zones in MT5 in such a way, that their colour does not overlap and does not change the colours of lines of other indicators?

P.S. I dug all properties of indicator buffers (methods like PlotIndexSetInteger), there is nothing similar.

P.S2. Here is a screenshot from MT5.

It all depends on the overlap sequence, who is last is on top

Define buffer withDRAW_FILLING first

Reason: