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

 
Tenimagalon:
I see that we are having a real discussion. Alex, you are involved in it as well:)) Well, Mr. programmers, do you have a consensus? Look, the main function is to close orders of the same type based on total profit. 4 positions are opened, 2 of them in EURUSD (buy and sell) and 2 of USDCHF (buy and sell).If buy orders get a profit it closes them, leave the sell order alone or leave the sell order alone.

Catch

double MyProfit=1000; // уровень профита
//+--------------------------------------------------------------------------------------------------------------------+
//| Expert tick function                                                                                               |
//+--------------------------------------------------------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Open_Pr("",0)>MyProfit)DelOrders("",0); // закрываем покупки
   if(Open_Pr("",1)>MyProfit)DelOrders("",1); // закрываем продажи
//---
  }
//+--------------------------------------------------------------------------------------------------------------------+
//|  Суммарный профит в валюте депозита открытых позиций                                                               |
//| or_ty=0 - ордера типа BUY                                                                                          |
//| or_ty=1 - ордера типа SELL                                                                                         |
//+--------------------------------------------------------------------------------------------------------------------+
double Open_Pr(string sy="", int or_ty=0)
  { double p = 0;
   if (sy == "0") sy = Symbol();
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
        {
         if(OrderSymbol() == sy || sy == "")
           {
            if(OrderType()==or_ty) {p+=OrderProfit()+OrderSwap()+OrderCommission();}
           }
        }
     }
   return(p);
  }
//+--------------------------------------------------------------------------------------------------------------------+
//| Функция удаления и закрытия ордеров                                                                                |
//| or_ty=0 - ордера типа BUY                                                                                          |
//| or_ty=1 - ордера типа SELL                                                                                         |
//+--------------------------------------------------------------------------------------------------------------------+
void DelOrders(string sy="", int or_ty=0)
  {
   while(true)
     {
      bool find_order=false;
      //----
      if (sy == "0") sy = Symbol();
      for(int pos=OrdersTotal()-1;pos>=0;pos--)
      if(OrderSelect(pos,SELECT_BY_POS)==true)
      if(OrderSymbol() == sy || sy == "")
        {
         find_order=true;
         //----
         if(OrderType()==or_ty)
           {
            RefreshRates(); int slip=(int)(((Ask-Bid)/Point)*2);
            if(OrderClose(OrderTicket(),OrderLots(),Bid,slip,clrBlue)==false){}
           }
         //----
         if(OrderType()==or_ty)
           {
            RefreshRates(); slip=(int)(((Ask-Bid)/Point)*2);
            if(OrderClose(OrderTicket(),OrderLots(),Ask,slip,clrRed)==false){}
           }
         Alert("Все ордера закрыты!");
        } 
      if(find_order==false) Alert("Нет ордеров!");break;
     } 
  }
//+--------------------------------------------------------------------------------------------------------------------+
 
Tenimagalon:
I see that we are having a real discussion. Alex, you are involved :)) Well, mister programmers, do you have a consensus? Look, the problem is to close orders of the same type for a total profit. 4 positions are opened, 2 of them on EURUSD (buy and sell) and 2 of USDCHF (buy and sell).If buy orders get a profit it closes them, leave the sell order alone or leave the sell order alone.

like this? :)

1

 
MakarFX:

Catch

Ummm interesting. thanks a lot :)
 
Taras Slobodyanik:

like this? :)


If you have 3 positions opened at different pairs, i.e. 2 Bai and one sit, then yes, in this case the robot will close the pairs when the total profit is achieved. If you try to open 4 positions on 2 pairs, you will never get the total profit in this case, the expert closes the pairs of orders, either buy or sell. But he closes the buy EURUSD and buy USDCHF or any other selected pair.
 
Taras Slobodyanik:

like this? :)


Did you makethe dialog box yourself or the SB?
 
Tenimagalon:
If you have 3 positions opened at different pairs, i.e. 2 Bai and one Sell, then yes, in this case the robot will close the positions when the total profit is achieved. If you try to open 4 positions on 2 pairs, you will never get the total profit in this case, the expert closes the pairs of orders, either buy or sell. But he closes the buy EURUSD and buy USDCHF or any other selected pair.

here are a lot of bays and selves)

2

 
MakarFX:
Did you make the dialog box yourself or SB?

Are there any panels?

ps. unless there are objects if you do

 
Taras Slobodyanik:

Are there any panels?

Yes, that's why I'm asking.

If you did it yourself, please share the code (collapse, expand, move)

 
Taras Slobodyanik:

here are a lot of bays and selves)

Taras :) You should open 4 positions one by one on EUR, one by one on CHF, then two more, one sell on EUR, one sell on CHF. And look when buy and sell reach to the common profit the bot will close both of them or not. And in your screens I see orders for one instrument that should not be a priori.
 
Tenimagalon:
Taras :) You should open 4 positions in one step. 1 long in EUR, one long in CHF, then two more, one sell in EUR, one sell in CHF. And look when buy and buy reaches the total profit the bot will close both of them or not. And in your screens I see orders for one instrument that should not be a priori.

grouping pairs by either buy or sell is wrong

For example on one pair (buy) there could be a buy of the dollar and on the other pair (sell) there could be a sell of the dollar.

Reason: