MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 1646

 
EVGENII SHELIPOV # :

마카르 좋은 하루 !!!

귀하의 추천에 따라 void OnTick() 함수에서 TrailingGroupOrder() 함수를 첨부하여 그룹 주문의 후행을 수정하는 명령을 보낼 수 있는 위치를 찾았습니다. 그리고 보라, 그룹 주문의 추적이 작동하기 시작했습니다. 그러나 기쁨은 길지 않았습니다. 자세히 보니 최소 티켓이 있는 주문만 추적되고 있었습니다.

나는 문제가 한 번에 모두가 아니라 첫 번째(최소) 순서만 수정하는 데 있다고 높은 확률로 가정할 수 있습니다.

Makar, 그리드의 모든 주문이 한 번에 수정되도록 만드는 방법을 알려주세요????

void OnTick() 함수에서 TrailingGroupOrder()를 망친 위치를 보여주세요.
 
MakarFX # :
void OnTick() 함수에서 TrailingGroupOrder()를 망친 위치를 보여주세요.


 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 # :

빨간색으로 강조 표시됨

 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 ));       
}

노란색으로 강조 표시되어 시작 부분으로 이동

 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 # :

빨간색으로 강조 표시됨

노란색으로 강조 표시되어 시작 부분으로 이동

Makar는 어제 당신이 나에게 보낸 옵션입니다. 그 변형에서 매우 간단하고 주문도 잘못 마감되었습니다.

 
EVGENII SHELIPOV # :

Makar는 어제 당신이 나에게 보낸 변형입니다. 변형 주문이 올바르게 마감되지 않았다는 점에서 매우 간단합니다.

내 마감 조정은 효과가 없습니다.

그리고 한 가지 더 - TrailingGroupOrder() 함수에서 "tr"이란 무엇입니까?

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

Makar는 어제 당신이 나에게 보낸 옵션입니다. 그 변형에서 매우 간단하고 주문도 잘못 마감되었습니다.

"제대로 닫히지 않는다"는 것은 무엇을 의미합니까?
 
MakarFX # :
"제대로 닫히지 않는다"는 것은 무엇을 의미합니까?

모든 주문이 트롤에서 즉시 종료되는 것은 아니지만 최소 티켓이 있는 주문만 차례로 종료됩니다.

 
EVGENII SHELIPOV # :

모든 주문이 트롤에서 즉시 종료되는 것은 아니지만 최소 티켓이 있는 주문만 차례로 종료됩니다.

내일 확인하겠습니다
 

모두에게 좋은 하루입니다. 저는 그룹 주문을 추적하는 코드를 작성 중입니다. 후행에 대한 코드 논리는 다음과 같습니다.

두 번째 및 다음 주문을 연 후 주문 수정 ModifyOrders() 명령이 전송됩니다. 여기에서 함수 시작 부분에서 평균을 계산한 다음 이익 실현을 계산하고 모든 주문은 이익만 취하도록 수정합니다.

그런 다음 void OnTick() 함수에서 Stop Loss가 후행 중지로 수정되는 TrailingGroupOrder() 함수를 호출합니다.

문제는 최소 티켓이 있는 하나의 주문만 수정된다는 것입니다. 그리드의 모든 주문을 수정하고 TP 또는 SL로 마감하는 것은 올바르지 않습니다. 이 문제를 해결하는 데 도움이 됩니다. 미리 감사드립니다.

 //+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
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 # :

모두에게 좋은 하루입니다. 저는 그룹 주문을 추적하는 코드를 작성 중입니다. 후행에 대한 코드 논리는 다음과 같습니다.

이게 왜 중복임?

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

이렇게 될 수 있을까

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


또한 어떤 매개변수가

TrailingStep                
TakeProfitGroupOrder        
TrailingStopGroupOrder