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

 

How can I control pending orders in MQL5?


The problem is that I need the following functions: "Do not confuse positions and pending orders".


Then how do I get information about those pending orders?

 
Alexandr Sokolov:

How can I control pending orders in MQL5?


The problem is that I need the following functions: "Do not confuse positions and pending orders".


Then how should I get information about these pending orders?

I just need to read the pending orders. For instance, this function is only for pending stop orders:

//+------------------------------------------------------------------+
//| Calculate all pending orders                                     |
//+------------------------------------------------------------------+
void CalculateAllPendingOrders(int &count_buy_stops,int &count_sell_stops)
  {
   count_buy_stops   = 0;
   count_sell_stops  = 0;

   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of current orders
      if(m_order.SelectByIndex(i))     // selects the pending order by index for further access to its properties
         if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic)
           {
            if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
               count_buy_stops++;
            else
               if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
                  count_sell_stops++;
           }
  }
 
Vladimir Karputov:

You just need to read the pending orders. For example this function is only for pending stop orders:

Thank you very much!


I was just looking at the example and it's all through Position...

 
Alexandr Sokolov:

Thank you very much!


It's just that I looked at the example and it's all through Position...

Here's an example that compiles:

//+------------------------------------------------------------------+
//|                                    CalculateAllPendingOrders.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property script_show_inputs
//---
#include <Trade\SymbolInfo.mqh>
#include <Trade\OrderInfo.mqh>
//---
CSymbolInfo    m_symbol;                     // object of CSymbolInfo class
COrderInfo     m_order;                      // object of COrderInfo class
//--- input parameters
input ulong    InpMagic             = 200;         // Magic number
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   if(!m_symbol.Name(Symbol())) // sets symbol name
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: CSymbolInfo.Name");
      return;
     }
//---
   int count_buy_stops=0,count_sell_stops=0;
   CalculateAllPendingOrders(count_buy_stops,count_sell_stops);
  }
//+------------------------------------------------------------------+
//| Calculate all pending orders                                     |
//+------------------------------------------------------------------+
void CalculateAllPendingOrders(int &count_buy_stops,int &count_sell_stops)
  {
   count_buy_stops   = 0;
   count_sell_stops  = 0;

   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of current orders
      if(m_order.SelectByIndex(i))     // selects the pending order by index for further access to its properties
         if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic)
           {
            if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
               count_buy_stops++;
            else
               if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
                  count_sell_stops++;
           }
  }
//+------------------------------------------------------------------+
 
Alexandr Sokolov:

How can I control pending orders in MQL5?


The problem is that I need the following functions: "Do not confuse positions and pending orders".


Then how do I get information about those pending orders?

The difference is that in mql4 function OrdersTotal() returns the total number of market and pending orders. And in mql5 it returns the number of pending orders only. And to get the number of positions, in terms of mql4 market orders, function PositionsTotal()

 
Alexey Viktorov:

Haven't seen the thread on the forum, but after looking at a few instructions, I find this one more understandable. Tried it, it worked, but I don't see the need to apply it yet. Although I do think it would be a good idea to combine the history from all terminals in one folder.

I read the article at the link. It's brilliant. And it's a super solution, for those who have many terminals. Now there can be one mql4 folder for different terminals, without having to constantly copy files back and forth.

thank you very much!!!

 
Sergey Likho:

I read the article at the link. It's brilliant. And it's a super solution, for those who have many terminals. Now there can be one mql4 folder for different terminals, without having to constantly copy files back and forth.

thank you so much!!!

I'm not the one to thank. I paid attention to Sergei Tabolin's posts and matched some of the words in them with Seric29's wish, well I looked it up myself.

 

Hello.

Please help me sort out the code.

I tried to put the grid on the market and they started swearing at me:2016.04.01 00:02:00 1111111113241135454356146 EURUSD,H1: invalid lots amount for FreeMarginCheckfunction

attached Expert Advisor file.

Thank you in advance.

Документация по MQL5: Константы, перечисления и структуры / Именованные константы / Предопределенные макроподстановки
Документация по MQL5: Константы, перечисления и структуры / Именованные константы / Предопределенные макроподстановки
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
Files:
123.mq4  87 kb
 
Dmitriy Prigodich:

Hello.

Please help me sort out the code.

I tried to put the grid in the market and they started swearing at me:2016.04.01 00:02:00 1111111113241135454356146 EURUSD,H1: invalid lots amount for FreeMarginCheck function

attached Expert Advisor file.

Thank you in advance.

It says too: invalid lots amount

The FreeMarginCheck function does not check Expert Advisor arguments and does not add a normalized lot size.

PS - well, do not put everything in a row in the market, the more thing that they themselves do not use. I'm not sure what to do with it.

 

I wanted to make a video, but I don't have a camera, and my phone is an old one, that was under the Tsar Pea. So I created an expert and called it 111.mq4

Here's its primitive code.

#property strict
#import "111б.ex4"//111б.mq4
int Funi(string Soob);
#import

int OnInit(){Funi(Symbol());return(INIT_SUCCEEDED);}
void OnDeinit(const int reason){}
void OnTick(){Funi(Symbol());}


and then I created a library and named it 111b.mq4 with the primitive code

#property library
#property strict
 string  st_mas[]; //export
 int Funi(string Soob)export
 {st_mas[(ArrayResize(st_mas,ArrayRange(st_mas,0)+1))-1]=Soob;
 Print("Размер массива = ",ArrayRange(st_mas,0));
 for(int i=0;i<ArrayRange(st_mas,0);++i)
 Print("Вывод массива ",st_mas[i]);
 return 2;}

. I declared a string array inside the library, but it turned out later, the developers didn't provide the possibility to export and import arrays and variables. It turns out, there is no way to get a global array that would remember the information. But never mind, I took another way. I createdFuni() function. Then I created hard links by key H terminals are set like this

The original files are in Forex4you, and links in Forex4you1 I threw the robot original and link to the chart, the first calculations were obtained, but when the ticks went only original Forex4you updated the information and arrayst_mas increased in size, but when ticks went to Forex4you1 nothing happens only when the file manually gets to the chart. Then I took another way. I made an Expert Advisor called 333.mq4 and installed it in MT4 Forex4you1 and connected the library 111b.mq4 to it and threw the program on a chart. The robot 333.mq4 was able to connect to the library link and this thing started working online but as it turned out later the library was a prototype and the array declared in it works within a single chart

The example shows that even though the robot is connected to a library with a global array, that array works as an image and still can't provide communication, we need to create shared variables that will be available from all sides. Who knows if it's possible to export arrays and variables. I think the second option is to write the information to a file, because the file will not be a proxy and will be read from both sides and thus terminals and robots will be able to communicate with each other. Who knows how to work with files check this theory as I don't have that experience yet.

Do you guys know if you can export arrays and variables?

Reason: