Toute question des nouveaux arrivants sur MQL4 et MQL5, aide et discussion sur les algorithmes et les codes. - page 1646

 
EVGENII SHELIPOV #:

Bonne journée Makar ! !!

En suivant vos conseils, j'ai trouvé un endroit dans la fonction void OnTick() où je peux attacher la fonction TrailingGroupOrder() pour envoyer une commande pour modifier une traînée d'ordres groupés, et oh mon dieu la traînée d'ordres groupés a commencé à fonctionner. Cependant, ma joie n'a pas duré longtemps. En regardant de plus près, j'ai vu que seule la commande avec un ticket minimum est trilled.

Je peux très probablement supposer que le problème réside dans la modification de la première commande (minimale) uniquement et non de toutes les commandes en même temps.

Makar conseille comment faire en sorte que tous les ordres de la grille soient modifiés en même temps ????.

Montrez-moi où vous avez mis TrailingGroupOrder() dans la fonction void OnTick() ?
 
MakarFX #:
Montrez-moi où vous avez mis TrailingGroupOrder() dans la fonction void OnTick() ?


void OnTick()
{
     double JAW = iAlligator(Symbol(),TimeframesIndicators,13,8,5,8,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,0);
     double TEETH = iAlligator(Symbol(),TimeframesIndicators,13,8,5,8,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,0);
     double LIPS = iAlligator(Symbol(),TimeframesIndicators,13,8,5,8,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORLIPS,0);
     double DI_PLUSCurrent=iADX(Symbol(),TimeframesIndicators,14, PRICE_CLOSE,MODE_PLUSDI,0);
     double DI_MINUSCurrent=iADX(Symbol(),TimeframesIndicators,14, PRICE_CLOSE,MODE_MINUSDI,0);
     double MacdCurrent=iMACD(Symbol(),TimeframesIndicators,12,26,9, PRICE_CLOSE,MODE_MAIN,0);
     double MacdPrevious=iMACD(Symbol(),TimeframesIndicators,12,26,9, PRICE_CLOSE,MODE_MAIN,2 ); 
     double ATR = iATR(Symbol(), TimeframesVolatility, BarCount, 0);
     {
      if (CountTrade() == 0)
      {
        if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
        if(LIPS>TEETH&& TEETH>JAW&&DI_PLUSCurrent>18&&DI_PLUSCurrent>DI_MINUSCurrent&&MacdCurrent>MacdPrevious)                              
         {
           FirstLots = Lots();
           tp = NormalizeDouble(Ask + TakeProfitFirstOrder*Point, Digits);
           ticket = OrderSend(Symbol(), OP_BUY, FirstLots, Ask, slip, 0, tp, "1-ый ордер", Magic, 0, Blue); 
         }
        if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
        if(LIPS<TEETH&& TEETH<JAW&&DI_MINUSCurrent>18&&DI_MINUSCurrent>DI_PLUSCurrent&&MacdCurrent<MacdPrevious)                            
         {
           FirstLots = Lots();
           tp = NormalizeDouble(Bid - TakeProfitFirstOrder*Point, Digits);
           ticket = OrderSend(Symbol(), OP_SELL, FirstLots, Bid, slip, 0, tp, "1-ый ордер", Magic, 0, Red); 
         }
       }
      if (CountTrade() == 1) Trailing();
     }
      if (CountTrade() < MaxOrders)                                                           
       {
           int order_type = FindLastOrderType();
           if (order_type == OP_BUY)
           { 
              price = FindLastOrderPrice(OP_BUY);  
              if(Ask<= price - Step()*Point)
              {
                  lastlot = NormalizeDouble(GetMinLotOrder()*MathPow( MultiplierParameter, OrdersTotal()), 2);
                  ticket = OrderSend(Symbol(), OP_BUY, lastlot, Ask, slip, 0, 0, "Групповой ордер", Magic, 0, Blue);
                  if (ticket < 1)
                      Print ("Ошибка ордера на покупку");
                            ModifyOrders(OP_BUY);
              }
           }
             if (order_type == OP_SELL)
           { 
              price = FindLastOrderPrice(OP_SELL);  
              if(Bid>= price + Step()*Point)
              {
                  lastlot = NormalizeDouble(GetMinLotOrder()*MathPow( MultiplierParameter, OrdersTotal()), 2);
                  ticket = OrderSend(Symbol(), OP_SELL, lastlot, Bid, slip, 0, 0, "Групповой ордер", Magic, 0, Red);
                  if (ticket < 1)
                      Print ("Ошибка ордера на продажу!");
                            ModifyOrders(OP_SELL);
              }
           }
         }
         if(CountTrade()>1)
          {
           TrailingGroupOrder();
          } 
         double op = CalculiteProfit(); 
         if (op > FindLastLots() && Drawdown > DrawdownClosingMinMaxOrders)
           {
           ClosseMinMaxOrders();
           } 
      Comment("Всего открыто ордеров : " + DoubleToStr(OrdersHistoryTotal(), 0)+ "\n" +
              "Максимальное количество : " + DoubleToStr(MaxOrders, 0)+ "\n" +
              "Количество открытых ордеров: " + DoubleToStr(OrdersTotal(), 0)+ "\n" +
              "Осталось ордеров: " + DoubleToStr((MaxOrders - OrdersTotal()), 0)+ "\n" +
              "Баланс средств счета: " + DoubleToStr(AccountBalance(), 0)+ "\n" +
              "Свободные средства: " + DoubleToStr(AccountFreeMargin(), 0)+ "\n" +
              "Относительная текущая просадка: " + DoubleToStr(((AccountBalance() - AccountFreeMargin())/AccountBalance())*100, 2)+ "\n" +
              "Относительная максимальная просадка: " + DoubleToStr(GetMaxDrawdown(), 2)+ "\n" +
              "Текущая прибыль/убыток: " + DoubleToStr(AccountProfit(), 2)+ "\n" +
              "Абсолютная максимальная прибыль: " + DoubleToStr(GetMaxProfit(), 2)+ "\n" +
              "Абсолютный максимальный убыток (просадка): " + DoubleToStr(GetMaxLoss(), 2)+ "\n" +
              "Плечо: " + DoubleToStr(AccountLeverage(), 0)+ "\n" + 
              "Своп: " + DoubleToStr(OrderSwap(), 2)+ "\n" + 
              "Коммссия: " + DoubleToStr(OrderCommission(), 2)+ "\n" + 
              "Шаг: "  + DoubleToStr(Step(), 0)+ "\n" + 
              "Минимальный тикет ордера: " + DoubleToStr(GetTicketMinOrder(), 0)+ "\n" + 
              "Максимальный тикет ордера: " + DoubleToStr(GetTicketMaxOrder(), 0)+ "\n" + 
              "Профит минимальный  ордера: " + DoubleToStr(GetProfitMinOrder(), 2)+ "\n" +  
              "Профит максимального  ордера: " + DoubleToStr(GetProfitMaxOrder(), 2)+ "\n" +
              "Профит суммарный: " + DoubleToStr(CalculiteProfit(),2));       
}
 
EVGENII SHELIPOV #:

Supprimer les éléments surlignés en rouge

void OnTick()
{
     double JAW = iAlligator(Symbol(),TimeframesIndicators,13,8,5,8,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,0);
     double TEETH = iAlligator(Symbol(),TimeframesIndicators,13,8,5,8,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,0);
     double LIPS = iAlligator(Symbol(),TimeframesIndicators,13,8,5,8,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORLIPS,0);
     double DI_PLUSCurrent=iADX(Symbol(),TimeframesIndicators,14, PRICE_CLOSE,MODE_PLUSDI,0);
     double DI_MINUSCurrent=iADX(Symbol(),TimeframesIndicators,14, PRICE_CLOSE,MODE_MINUSDI,0);
     double MacdCurrent=iMACD(Symbol(),TimeframesIndicators,12,26,9, PRICE_CLOSE,MODE_MAIN,0);
     double MacdPrevious=iMACD(Symbol(),TimeframesIndicators,12,26,9, PRICE_CLOSE,MODE_MAIN,2 ); 
     double ATR = iATR(Symbol(), TimeframesVolatility, BarCount, 0);
     {
      if (CountTrade() == 0)
      {
        if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
        if(LIPS>TEETH&& TEETH>JAW&&DI_PLUSCurrent>18&&DI_PLUSCurrent>DI_MINUSCurrent&&MacdCurrent>MacdPrevious)                              
         {
           FirstLots = Lots();
           tp = NormalizeDouble(Ask + TakeProfitFirstOrder*Point, Digits);
           ticket = OrderSend(Symbol(), OP_BUY, FirstLots, Ask, slip, 0, tp, "1-ый ордер", Magic, 0, Blue); 
         }
        if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
        if(LIPS<TEETH&& TEETH<JAW&&DI_MINUSCurrent>18&&DI_MINUSCurrent>DI_PLUSCurrent&&MacdCurrent<MacdPrevious)                            
         {
           FirstLots = Lots();
           tp = NormalizeDouble(Bid - TakeProfitFirstOrder*Point, Digits);
           ticket = OrderSend(Symbol(), OP_SELL, FirstLots, Bid, slip, 0, tp, "1-ый ордер", Magic, 0, Red); 
         }
       }
      if (CountTrade() == 1) Trailing();
     }
      if (CountTrade() < MaxOrders)                                                           
       {
           int order_type = FindLastOrderType();
           if (order_type == OP_BUY)
           { 
              price = FindLastOrderPrice(OP_BUY);  
              if(Ask<= price - Step()*Point)
              {
                  lastlot = NormalizeDouble(GetMinLotOrder()*MathPow( MultiplierParameter, OrdersTotal()), 2);
                  ticket = OrderSend(Symbol(), OP_BUY, lastlot, Ask, slip, 0, 0, "Групповой ордер", Magic, 0, Blue);
                  if (ticket < 1)
                      Print ("Ошибка ордера на покупку");
                            ModifyOrders(OP_BUY);
              }
           }
             if (order_type == OP_SELL)
           { 
              price = FindLastOrderPrice(OP_SELL);  
              if(Bid>= price + Step()*Point)
              {
                  lastlot = NormalizeDouble(GetMinLotOrder()*MathPow( MultiplierParameter, OrdersTotal()), 2);
                  ticket = OrderSend(Symbol(), OP_SELL, lastlot, Bid, slip, 0, 0, "Групповой ордер", Magic, 0, Red);
                  if (ticket < 1)
                      Print ("Ошибка ордера на продажу!");
                            ModifyOrders(OP_SELL);
              }
           }
         }
         if(CountTrade()>1)
          {
           TrailingGroupOrder();
          } 
         double op = CalculiteProfit(); 
         if (op > FindLastLots() && Drawdown > DrawdownClosingMinMaxOrders)
           {
           ClosseMinMaxOrders();
           } 
      Comment("Всего открыто ордеров : " + DoubleToStr(OrdersHistoryTotal(), 0)+ "\n" +
              "Максимальное количество : " + DoubleToStr(MaxOrders, 0)+ "\n" +
              "Количество открытых ордеров: " + DoubleToStr(OrdersTotal(), 0)+ "\n" +
              "Осталось ордеров: " + DoubleToStr((MaxOrders - OrdersTotal()), 0)+ "\n" +
              "Баланс средств счета: " + DoubleToStr(AccountBalance(), 0)+ "\n" +
              "Свободные средства: " + DoubleToStr(AccountFreeMargin(), 0)+ "\n" +
              "Относительная текущая просадка: " + DoubleToStr(((AccountBalance() - AccountFreeMargin())/AccountBalance())*100, 2)+ "\n" +
              "Относительная максимальная просадка: " + DoubleToStr(GetMaxDrawdown(), 2)+ "\n" +
              "Текущая прибыль/убыток: " + DoubleToStr(AccountProfit(), 2)+ "\n" +
              "Абсолютная максимальная прибыль: " + DoubleToStr(GetMaxProfit(), 2)+ "\n" +
              "Абсолютный максимальный убыток (просадка): " + DoubleToStr(GetMaxLoss(), 2)+ "\n" +
              "Плечо: " + DoubleToStr(AccountLeverage(), 0)+ "\n" + 
              "Своп: " + DoubleToStr(OrderSwap(), 2)+ "\n" + 
              "Коммссия: " + DoubleToStr(OrderCommission(), 2)+ "\n" + 
              "Шаг: "  + DoubleToStr(Step(), 0)+ "\n" + 
              "Минимальный тикет ордера: " + DoubleToStr(GetTicketMinOrder(), 0)+ "\n" + 
              "Максимальный тикет ордера: " + DoubleToStr(GetTicketMaxOrder(), 0)+ "\n" + 
              "Профит минимальный  ордера: " + DoubleToStr(GetProfitMinOrder(), 2)+ "\n" +  
              "Профит максимального  ордера: " + DoubleToStr(GetProfitMaxOrder(), 2)+ "\n" +
              "Профит суммарный: " + DoubleToStr(CalculiteProfit(),2));       
}

Surligné en jaune, il faut l'amener en haut de la page.

void OnTick()
{
      if (CountTrade() == 1) Trailing();
      if (CountTrade() > 1 ) TrailingGroupOrder();

     double JAW = iAlligator(Symbol(),TimeframesIndicators,13,8,5,8,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,0);
 
MakarFX #:

Supprimer les éléments surlignés en rouge

Surligné en jaune, affichez-le

Makar est la variante que vous m'avez envoyée hier - il serait très simple dans cette variante les ordres sont également fermés de manière incorrecte

 
EVGENII SHELIPOV #:

Makar c'est la variante que vous m'avez envoyé hier - il aurait été très simple dans cette variante les ordres ne sont pas fermés correctement

Mes corrections n'affectent pas la clôture.

Une dernière chose : que signifie "tr" dans la fonction TrailingGroupOrder() ?

if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - TrailingStopGroupOrder*Point, Digits), tp, 0))
 
EVGENII SHELIPOV #:

Makar c'est la variante que vous m'avez envoyé hier - il aurait été très simple dans cette variante les ordres sont aussi fermés incorrectement

Comment ça, ils ne ferment pas correctement ?
 
MakarFX #:
Que voulez-vous dire par "ne se ferme pas correctement" ?

Toutes les commandes ne sont pas fermées en même temps à partir du chalut, mais seulement la commande avec le ticket le plus bas et ainsi de suite, une par une.

 
EVGENII SHELIPOV #:

Toutes les commandes ne sont pas fermées en même temps à partir du chalut, mais seulement la commande avec le ticket le plus bas et ainsi de suite, une par une.

Je le vérifierai demain
 

Bonjour à tous, Je suis en train d'écrire du code pour une recherche de commandes groupées. La logique du code est la suivante :

Après l'ouverture du deuxième ordre et des ordres suivants, nous recevons une commande pour modifier les ordres ModifyOrders() où nous calculons la moyenne et ensuite le calcul du takeprofit et modifions tous les ordres mais uniquement le takeprofit.

Ensuite, nous appelons la fonction TrailingGroupOrder() à partir de la fonction void OnTick() où le Stop Loss est modifié en Trailing Stop.

La question est que seul un ordre avec un ticket minimum est modifié ; ce n'est pas correct ; tous les ordres de la grille devraient être modifiés et clôturés au TP ou SL. Aidez-moi à comprendre. Merci d'avance.

//+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
void ModifyOrders(int otype)
  {
   for(int i = OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
           {
            if(otype == OP_BUY)
               tp = NormalizeDouble(GetAveragePrice() + TakeProfitGroupOrder*Point, Digits);
            if(otype == OP_SELL)
               tp = NormalizeDouble(GetAveragePrice() - TakeProfitGroupOrder*Point, Digits);
            if((otype == OP_BUY || otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero))
               tp = NormalizeDouble(GetAveragePrice(), Digits);
           }
        }
     }
   for(int i = OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
           {
            if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0))
               Print("Ордера успешно модифицированы!");
            else
               Print("Ошибка модификации ордеров!");
           }
        }
     }
  }
//+----------------------------------------------------------------------------+
//| Трейлинг стоп групповых ордеров                                            |
//+----------------------------------------------------------------------------+
void TrailingGroupOrder()
  {
   for(int i = OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            if(OrderType() == 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("Ошибка модификации групповых ордеров на продажу!");
                    }
                 }
              }
           }
        }
     }
  }


 
EVGENII SHELIPOV #:

Bonjour à tous, Je suis en train d'écrire du code pour une recherche de commandes groupées. La logique du code pour le chalut est la suivante :

Pourquoi cette duplication

            if(OrderType() == OP_BUY && Bid - GetAveragePrice() > TrailingStopGroupOrder*Point)
              {
               if(Bid - GetAveragePrice() > TrailingStopGroupOrder*Point || OrderStopLoss() == 0)
                 {
                  if(OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder)*Point || OrderStopLoss() == 0)
                    {

Vous pouvez le faire de cette façon

            if(OrderType() == OP_BUY && Bid - GetAveragePrice() > TrailingStopGroupOrder*Point)
              {
               if(OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder)*Point || OrderStopLoss() == 0)
                  {


Montrez également quels paramètres

TrailingStep                
TakeProfitGroupOrder        
TrailingStopGroupOrder