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

 
EVGENII SHELIPOV #:

Hello all, I am writing code for a trawl of group orders . The code logic for a trawl is as follows :

Under what conditions should the trawl for group orders start?

 
EVGENII SHELIPOV #:

Hello all, I am writing code for a trawl of group orders . The code logic for the trawl is as follows :



  int order[]={1,2,3,4,5,6,7,8,9,10};



void Tral_BU_Stop() {
 
  int j;
  for (int i=OrdersTotal()-1; i>=0; i--) {
  if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==True){
  if (OrderMagicNumber()==Mg&&OrderSymbol()==Symbol()&&OrderType() ==OP_BUYSTOP){
  j++;
  if ( Bid<=OrderOpenPrice()-DistPoint*order[j]*Po){
  bool modb=OrderModify(OrderTicket(),Bid+(DistPoint*order[j])*Po,OrderStopLoss(),OrderTakeProfit(),0,clrGreen);}} }}}
//================
  void Tral_SEL_Stop() {
  
  int j;
  for (int i=OrdersTotal()-1; i>=0; i--) {
  if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==True){
  if (OrderMagicNumber()==Mg&&OrderSymbol()==Symbol()&&OrderType() ==OP_SELLSTOP){
  j++;
  if (Ask>OrderOpenPrice()+DistPoint*order[j]*Po){
  bool mods=OrderModify(OrderTicket(),Ask-(DistPoint*order[j])*Po,OrderStopLoss(),OrderTakeProfit(),0,clrRed);}} }}} 

Change the values and you will be happy

 
Aleksandr Egorov #:

Change the values and you'll be happy, I think you'll figure it out

What is "Ro"?
DistPoint*order[j]*Po
 
MakarFX #:
What is "Ro"?

abbreviated point

 
MakarFX #:

Under what conditions should the trawl for group orders begin?




//+----------------------------------------------------------------------------+
//| Трейлинг стоп групповых ордеров                                            |
//+----------------------------------------------------------------------------+
void TrailingGroupOrder()
  {
   for(int i = OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            if(Or derType() == OP_BUY && Bid - GetAveragePrice() > TrailingStopGroupOrder*Point)
              {
               if(Bid - GetAveragePrice() > TrailingStopGroupOrder*Point || OrderStopLoss() == 0)
                 {
                  if(OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder)*Point || OrderStopLoss() == 0)
                    {
                     if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - TrailingStopGroupOrder*Point, Digits), tp, 0))
                        Print("Ошибка модификации групповых ордеров на покупку!");
                    }
                 }
              }
            if(OrderType() == OP_SELL && GetAveragePrice() - Ask > TrailingStopGroupOrder*Point)
              {
               if(GetAveragePrice() - Ask > TrailingStopGroupOrder*Point || OrderStopLoss() == 0)
                 {
                  if(OrderStopLoss() > Ask + (TrailingStep + TrailingStopGroupOrder)*Point || OrderStopLoss() == 0)
                    {
                     if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStopGroupOrder*Point, Digits), tp, 0))
                        Print("Ошибка модификации групповых ордеров на продажу!");
                    }
                 }
              }
           }
        }
     }
  }

int                         TrailingStep                   = 1;       // Шаг для TrailingStop
extern int                  TakeProfitGroupOrder           = 30;      // Тейкпрофит групповых ордеров
extern int                  TrailingStopGroupOrder         = 10;      // Трейлинг стоп груповых ордеров
 
Aleksandr Egorov #:

Point.

In this case, when the second order is opened, a stop-loss order will be placed and there may be no possibility to open the third order in the grid...

 
EVGENII SHELIPOV #:

I meant under what conditions it starts

TrailingGroupOrder()
 
MakarFX #:

I meant under what conditions it starts

 if(CountTrade()>1)
     {
      TrailingGroupOrder();
     }
 
MakarFX #:

In this case, when the second order is opened, a stop-loss order will be placed and there may be no possibility to open a third order in the grid...

As far as I know, you cannot place a stop before the order is opened

and there is no way to do group modification without it

j++;
  if (Ask>OrderOpenPrice()+DistPoint*order[j]*Po){
  bool mods=OrderModify(OrderTicket(),Ask-(DistPoint*order[j])*Po,OrderStopLoss(),OrderTakeProfit(),0,clrRed);}
 
MakarFX #:

Why this duplication

You can do it like this.


And also show me what parameters

You're right, Makar, but most of this code isn't mine. I took it from a self-study book. All the more so, this substitution doesn't solve the question at hand.

Reason: