The great and terrible MT4 forever (or how to strategise a transition) - page 24

 
Artyom Trishkin:
In Russian? In Spanish? In English? Which one?

of course in all languages that the terminal supports

the format does not matter - it can be an SB in the form of a class where the constructor gets the language as a parameter

or it can be a group of custom functions with language ending GetTxtErrDescription_RU()

or even a regular function like GetLastError()

if you wish


OK, forget it, I have everything, and my rank does not allow to take care of the universal well-being, let specially trained people deal with usability and userfriendly

 

I guessed why your position is double.))) Because you have placed two libraries in CodeBase)))


 

Why don't you like GetTickCount(); it doesn't slow down the whole code, unlike Sleep, you can at least add 500ms if the ping is high,

In my multisymbol, for each pair a separate counter is activated after OrderSend, the rest of the logic continues to work

void OnStart()
  {
   MqlTradeRequest BuyRequest = {0};
   MqlTradeResult result = {0};
   BuyRequest.action = TRADE_ACTION_DEAL;
   BuyRequest.type = ORDER_TYPE_BUY;
   BuyRequest.symbol = _Symbol;
   BuyRequest.volume = 0.1;
   BuyRequest.type_filling = GetFilling();
//---
   while(1 && !IsStopped())
     {
      static uint LastOnCalculate = GetTickCount();
      if(GetTickCount() - LastOnCalculate > 5)
         //---
        {
         BuyRequest.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
         OrderSend(BuyRequest, result);
         LastOnCalculate = GetTickCount();
         continue;
        }
      if(PositionGetTicket(0) > 0 && PositionsTotal() >= 10)
        {
         Sleep(100);
         Print(PositionsTotal());
         return;
        }
     }
  }
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE_FILLING GetFilling(const uint Type = ORDER_FILLING_FOK)
  {
   const ENUM_SYMBOL_TRADE_EXECUTION ExeMode = (ENUM_SYMBOL_TRADE_EXECUTION)::SymbolInfoInteger(_Symbol, SYMBOL_TRADE_EXEMODE);
   const int FillingMode = (int)::SymbolInfoInteger(_Symbol, SYMBOL_FILLING_MODE);
   return((FillingMode == 0 || (Type >= ORDER_FILLING_RETURN) || ((FillingMode & (Type + 1)) != Type + 1)) ?
          (((ExeMode == SYMBOL_TRADE_EXECUTION_EXCHANGE) || (ExeMode == SYMBOL_TRADE_EXECUTION_INSTANT)) ?
           ORDER_FILLING_RETURN : ((FillingMode == SYMBOL_FILLING_IOC) ? ORDER_FILLING_IOC : ORDER_FILLING_FOK)) :
          (ENUM_ORDER_TYPE_FILLING)Type);
  }
//+------------------------------------------------------------------+
 
Fast235:

Why don't you like GetTickCount(); it doesn't slow down the whole code unlike Sleep, you can use at least 500ms if the ping is high,

It's an active loop and it eats the processor. What if there are 50 Expert Advisors of this kind in the terminal? There are 8 of them on one symbol where all 8 will send orders on the hairpin.

 
traveller00:

It's an active cycle and it eats the CPU. What if there are 50 such Expert Advisors in the terminal? There are 8 of them on one pair where on the hairpin all 8 of them will send orders.

It is activated for half a second and only after the order is sent there is no command for it and then it checks for the presence of the open positions first

I optimized my code, it became faster and started to open 2 positions at a time) at first Sleep helped, but it was slowing things down, I have 7 characters
 
fxsaber:

I haven't tried MT4-style myself yet. Theoretically it should work. I have not had a chance to look at it yet.

It works. It was interesting to compare two versions (with and without position waiting).


With position waiting after OrderSend.

#include <MT4Orders.mqh>

#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void OnStart()
{
  while (OrdersTotal() < 30)
    OrderSend(_Symbol, OP_BUY, 0.1, Ask, 0, 0, 0);      
    
  Print(OrdersTotal());
}


Without waiting for the position, the result is immediate.

#include <fxsaber\TradesID\ByPass.mqh>
#include <MT4Orders.mqh>

#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void OnStart()
{
  BYPASS ByPass;
  
  MT4ORDERS::OrderSend_MaxPause = 0; // Запрет на ожидание позиции после OrderSend
  
  while (OrdersTotal() < 30)
    if (ByPass.Is())
      ByPass += OrderSend(_Symbol, OP_BUY, 0.1, Ask, 0, 0, 0);      
    
  Print(OrdersTotal());
}


I was sure that the second variant was faster. It turned out to be equal in time of execution.


When waiting for position ByPass.Is(), the code returned false once, while without waiting it returned 740 times. All in all, the crutch seems to work.

 
Seems to be the only working solution presented.

Forum on trading, automated trading systems and trading strategy testing

The great and terrible MT4 forever (or how to build your migration strategy)

Igor Makanu, 2021.05.10 10:28

it seems to work:

#include <Trade\Trade.mqh>
void OnStart()
{
   CTrade Trade;
   while(PositionsTotal() < 30)
   {
      if(OrdersTotal() > 0) continue;
      if(!Trade.Buy(0.01)) continue;
      if(OrdersTotal() == 0 && PositionsTotal() >= 30) return;
   }
}

But very slow, and the solution is so-so.

Its speed is ok. Lack of synchronisation 37 times.

 
fxsaber:

Its speed is normal. Lack of synchronisation 37 times.

I checked on fx: this script opened 10 orders 5 times fast, and the last time I was fast, when I opened 10 orders for 10 seconds on the demo, the closing of orders was not fast either.

Here is a scratch on the log for order 11143290:

LL 0 11:19:31.444 Trades '20615687': order #11143290 buy 0.1 / 0.1 EURUSD at market done in 1580.643 ms

PO 0 11:19:33.621 Trades '20615687': deal #1865643 buy 0.1 EURUSD at 1.21460 done (based on order #11143290)

CL 0 11:19:33.622 Trades '20615687': market buy 0.1 EURUSD

JF 0 11:19:33.679 Trades '20615687': accepted market buy 0.1 EURUSD

QO 0 11:19:33.679 Trades '20615687': market buy 0.1 EURUSD placed for execution

KM 0 11:22:41.224 Trades '20615687': market sell 0.1 EURUSD, close #11143290 buy 0.1 EURUSD 1.21460

DR 0 11:22:41.280 Trades '20615687': accepted market sell 0.1 EURUSD, close #11143290 buy 0.1 EURUSD 1.21460

KQ 0 11:22:41.282 Trades '20615687': market sell 0.1 EURUSD, close #11143290 buy 0.1 EURUSD 1.21460 placed for execution

ON 0 11:22:43.824 Trades '20615687': market sell 0.1 EURUSD, close #11143290 buy 0.1 EURUSD 1.21460

DO 2 11:22:43.880 Trades '20615687': market sell 0.1 EURUSD, close #11143290 buy 0.1 EURUSD 1.21460 [Order to close this position already exists]

JN 0 11:22:46.280 Trades '20615687': market sell 0.1 EURUSD, close #11143290 buy 0.1 EURUSD 1.21460

OL 2 11:22:46.336 Trades '20615687': market sell 0.1 EURUSD, close #11143290 buy 0.1 EURUSD 1.21460 [Order to close this position already exists]

 
Igor Makanu:

I just checked on the fx...n.

I'll have to have a look at that server. It would be good to check out the crutch suggested here, for whom it seems important.

To come back to this topic after a while would be very reluctant. Better to point out the bugs right away if there are any.

 
fxsaber:

I'll have to have a look at this server. It would be good to check out the crutch suggested here, for whom it seems important.

I'd hate to come back to this topic after a while. Better to immediately point out the bugs, if any.

In the PM threw the server