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

 
fxsaber:

There is probably no such flag inside.

Apparently not.

but I think MQ may well make one, especially since it would be one flag per terminal, i.e. for all programmes.

 
Artyom Trishkin:
I'll probably propose it. But much later. Due to subjective circumstances. Unfortunately. In the meantime, consider yourself a demagogue. Not forbidden.

Still relevant? Will your version of the solution be?

 
Igor Makanu:

Still relevant? Will your version of the solution be?

You quoted my post, which said "much later". For me, "much later" means no sooner than a year at least. Not because this is the time it takes to find a solution, but simply because of subjective circumstances, unfortunately.

 
Artyom Trishkin:

it won't be for at least a year.

OK, so it's not relevant.

 
You can probably still think of problems that are simple in terms of their conditions, and whose solutions cause unexpected difficulties.
 
fxsaber:
You can probably still come up with simple problems, the solution of which causes unexpected difficulties.

The script monitors for excess risk: if the total of positions and pending orders exceeds two - report it and exit.


Concise code:

void OnStart()
{
  while (!IsStopped())
    if ((PositionsTotal() + OrdersTotal() > 2)) // Если (риск превышен) число отложек/позиций больше двух,
    {
      Alert("Risk exceeded!");                  // сообщаем      
      ExpertRemove();                           // и выходим.
    }
}


We look at the script behavior depending on the manual actions. Before doing so (before running the script), let us mark the number of positions on the account PosTotal, orders - OrdTotal.

Script PosTotal/OrdTotal Action Script result
01 0/0 Open a position. Works.
02 0/0 Place a pending position. It works.
03 0/1 Puts a hold on hold. 03 0/1 Putting a pause.
04 0/1 Open a position. Alert (not always).
05 0/1 Deletes a pending position. Works.
06 1/0 Putting a pending order. Works.
07 1/0 Opening of a position. Alert (not always).
08 1/0 Close position. Working.
09 1/1 Deleting a pending position. Working.
10 1/1 Closing a position. Alert.
11 0/2 Deletes a pending position. Working.
12 2/0 Closing a position. Alert.


Seems like a very simple task, but alerts. What are variants of solution?


Probably, it is on simple tasks like this that we should work on our understanding of MT5.

 
fxsaber:

The script monitors for excess risk: if the total of positions and pending orders exceeds two - report it and exit.


Concise code:


We look at the script behavior depending on the manual actions. Before doing so (before running the script), let us mark the number of positions on the account PosTotal, orders - OrdTotal.

Script PosTotal/OrdTotal Action Script result
01 0/0 Open a position. Works.
02 0/0 Place a pending position. It works.
03 0/1 Putting a pause. 03 0/1 Putting a pause.
04 0/1 Open a position. Alert (not always).
05 0/1 Deletes a pending position. Works.
06 1/0 Putting a pending order. Works.
07 1/0 Opening of a position. Alert (not always).
08 1/0 Close position. Working.
09 1/1 Deleting a pending position. Working.
10 1/1 Closing a position. Alert.
11 0/2 Deletes a pending position. Working.
12 2/0 Closing a position. Alert.


Seems like a very simple task, but alerts. What are the variants of solution?


Probably, it is on simple tasks like this that we should work on our understanding of MT5.

What does MQ5 have to do with it? The condition of exiting the loop: IsStopped and no more than two orders. Then the script works, and if the condition does not work, the script works too.

 
Алексей Тарабанов:

What does this have to do with MQ5? Condition for exiting the loop: IsStopped and no more than two orders. Then the script works, and if the condition does not work, the script works too.

The code even contains comments.

 
fxsaber:

The script monitors the risk: if the total number of positions and pending orders exceeds two, report it and exit.

A concise code:


Seems like a very simple task, but alerts. What are variants of solution?


Probably this is the type of simple tasks we should use to develop our MT5 understanding.

i think i need to do something like this:

void OnStart()
{
   while (!IsStopped())
   {
      //--- посчитаем ордера
      int orders = 0;
      for(int i = 0; i < OrdersTotal(); i++)
         if(OrderGetTicket(i) > 0 && OrderGetInteger(ORDER_TYPE) < ORDER_TYPE_CLOSE_BY) orders++;
      
      if(orders + PositionsTotal() > 2) break;     // выходим
   }
   if(!_StopFlag) Alert("Risk exceeded!");         // сообщаем
}
 
Igor Makanu:

probably something like that needs to be done:

Certainly, you have to filter the orders. It is not an easy thing to do.

ZS It's an interesting situation on the forum. Active responses to questions. It's different here, apparently.
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
  • 2016.11.09
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...