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

 

SanAlex:

I suspect that not everyone understands what we are talking about. - The profit is one thing - but the profits on each pair are different.

This is why the Expert Advisor has to be installed on each pair.

You don't have to download all charts.

//+--------------------------------------------------------------------------------------------------------------------+
//| Expert tick function                                                                                               |
//+--------------------------------------------------------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Open_Pr("EURUSD")>MyProfit)DelOrders("EURUSD");
   if(Open_Pr("GBPUSD")>MyProfit)DelOrders("GBPUSD");
   //...и так все нужные пары 
//---
  }

and add to the function of deleting and closing orders

//+--------------------------------------------------------------------------------------------------------------------+
//| Функция удаления и закрытия ордеров                                                                                |
//+--------------------------------------------------------------------------------------------------------------------+
void DelOrders(string sy="")
  {
   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()==OP_BUY)
           {
            RefreshRates(); int slip=(int)(((Ask-Bid)/Point)*2);
            if(OrderClose(OrderTicket(),OrderLots(),Bid,slip,clrBlue)==false){}
           }
         //----
         if(OrderType()==OP_SELL)
           {
            RefreshRates(); int slip=(int)(((Ask-Bid)/Point)*2);
            if(OrderClose(OrderTicket(),OrderLots(),Ask,slip,clrRed)==false){}
           }
         //----
         if(OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
         if(OrderDelete(OrderTicket(),clrRed)==false){}
         //----
         if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)
         if(OrderDelete(OrderTicket(),clrBlue)==false){}
         Alert("Все ордера закрыты!");
        } 
      if(find_order==false) Alert("Нет ордеров!");break;
     } 
  }
 
MakarFX:

You don't have to download all charts, you just put it on one chart and write in the code

and add to the function of deleting and closing orders

What about a signal to open?

 
SanAlex:

And the opening signals ?

What are you talking about?
 
MakarFX:
What do you mean?

these functions are auxiliary - and for an expert to work properly, it must also open

 
SanAlex:

These functions are auxiliary - for the Expert Advisor to work properly, it should also open

Originally, the question was - "Who has a function for closing orders of specified currencies according to total profit"?

The creation of a full-fledged Expert Advisor was out of the question)))

 
MakarFX:

The original question was "who has the function of closing orders of given currencies by total profit".

There was no question of creating a full-fledged Expert Advisor)))

this function is not working for you ! maybe it works for total profits ? - If so, we are talking about different functions

The snapshot does not close

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I wonder how his profit will appear - opening here and there on 2 pairs

I just saw his code - that's how he opens.

 
SanAlex:

well this function doesn't work for you ! maybe it works by total profit ?

MakarFX:

The original question was "who has the function of closing orders of given currencies by total profit".

 
MakarFX:

OK! I've fitted another feature - Sorry!!!

 
SanAlex:

Sorry!!!

It's ok))) This is a forum for everyone.

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