미결 주문 총액 문제 - 페이지 4

 

안녕하세요 여러분

미안하지만 내가 너무 빨리 말했다. RefreshRates()를 추가하면 차이가 있는 것처럼 보이지만 여전히 동일한 문제가 있습니다. 때로는 두 가지 보류 주문 을 모두 열 때도 있고 두 가지 중 하나만 열 때도 있고 아무 것도 열지 않을 때도 있습니다. 주문을 열지 않거나 둘 다 열지 않을 때 여전히 오류 130이 발생하지만 실제로 둘 다 열리면 오류가 없습니다. 또한 내 입력이 MODE_STOPLEVEL 미만인 쌍에서 프로그램이 요청한 대로 내 입력을 조정하더라도 주문을 열지 않고 항상 오류 130이 발생한다는 사실을 알게 되었습니다. 값을 인쇄하고 있으며 예상대로 조정됩니다. 그래서 내 OrderSend가 실제로 작동하지 않는 이유를 알아 내려고 노력하고 있습니다.

스톱레벨이 5인 EURUSD와 같은 쌍에서는 일반적으로 두 주문을 모두 보내지만 항상 그런 것은 아닙니다. 그러나 stoplevel이 10인 EURAUD와 같은 쌍에서는 절대 주문을 보내지 않습니다.

 extern int TrailingStart= 20 ;
extern int TrailingStop= 5 ;

extern int Hedge= 10 ;
extern double Multiplier= 3 ;

extern int StopLossOriginal= 11 ;

extern int StopLossHedge= 9 ;

extern double Percentage= 1 ;
extern double Lotsize= 0.01 ;
extern double MyMaxlots= 30 ;

extern datetime StartTime1 = D'2016.03.25 16:50' ;

extern int Pipmove= 5 ;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
//---
  {
   int TS=TrailingStart-TrailingStop;
   double stoplevel=(MarketInfo( Symbol (),MODE_STOPLEVEL))/ 10 ;
   if (StopLossOriginal<stoplevel || StopLossHedge<stoplevel || TS<stoplevel)
     {
       MessageBox ( "Please note: Your inputs for StopLossOriginal, StopLossHedge and/or" +
                 "\nTrailingStop are below the minimum levels required by your broker," +
                 "\nand have been increased automatically to " + StringConcatenate (stoplevel)+ " Pips" );
     }
   return ( 0 );
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return ( 0 );
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int TS=TrailingStart-TrailingStop;
   Print ( "TS = " ,TS);
   int sloss=StopLossOriginal-Pipmove;
   int stoplevel=(MarketInfo( Symbol (),MODE_STOPLEVEL))/ 10 ;
   Print ( "stoplevel = " ,stoplevel);
     
   double Lots = NormalizeDouble (AccountEquity()*Percentage*Lotsize/ 100 , 2 ),
          point= Point * 10 ,
          Price=Pipmove*point,
          SL=(StopLossOriginal-Pipmove)*point,
          MinLots = MarketInfo( Symbol (),MODE_MINLOT),
          MaxLots = MarketInfo( Symbol (),MODE_MAXLOT),
          HedgeLots= NormalizeDouble (OrderLots()*Multiplier, 2 );
          
   if (sloss<=stoplevel) SL=stoplevel*point;
   Print ( "SL = " ,SL);
   if (StopLossHedge<=stoplevel) StopLossHedge=stoplevel;
   Print ( "StopLossHedge = " ,StopLossHedge);
   if (TS<=stoplevel) TrailingStart=(stoplevel+TrailingStop); 
   Print ( "TrailingStart = " ,TrailingStart);     
          
   datetime time1=StartTime1- 3300 ;      

   if (Lots>MaxLots) Lots=MaxLots;
   if (Lots<MinLots) Lots=MinLots;
   if (HedgeLots>MaxLots) HedgeLots=MaxLots;
   if (Lots>MaxLots || Lots<MinLots || HedgeLots>MaxLots)
     {
       MessageBox ( "Lotsize have been adjusted automatically" );
     }

   int buy_ticket= 0 , sell_ticket= 0 , buystop_ticket= 0 , sellstop_ticket= 0 , total= 0 ;
   for ( int i= OrdersTotal ()- 1 ; i>= 0 ; i--)
       if ( OrderSelect (i,SELECT_BY_POS) && OrderMagicNumber()==magic && OrderSymbol()== Symbol ())
        {
         total++;
         if (OrderType()==OP_BUYSTOP) buystop_ticket=OrderTicket();
         if (OrderType()==OP_SELLSTOP) sellstop_ticket=OrderTicket();
         if (OrderType()==OP_BUY) buy_ticket=OrderTicket();
         if (OrderType()==OP_SELL) sell_ticket=OrderTicket();
        }

   if (total== 0 && Time[ 0 ]==time1)
     {
      buy_ticket= OrderSend ( Symbol (),OP_BUYSTOP,Lots,Ask+Price, 30 , 0 , 0 , "Pending" ,magic, 0 ,Lime);
      OrderModify(OrderTicket(),OrderOpenPrice(),Ask-SL,OrderTakeProfit(),Yellow);
       Print ( "Buystop = " , GetLastError ());
       Sleep ( 1000 );
      RefreshRates();
       Sleep ( 1000 );
      sell_ticket= OrderSend ( Symbol (),OP_SELLSTOP,Lots,Bid-Price, 30 , 0 , 0 , "Pending" ,magic, 0 ,Red);
      OrderModify(OrderTicket(),OrderOpenPrice(),Bid+SL,OrderTakeProfit(),Yellow);
       Print ( "Sellstop = " , GetLastError ());
     }

나는 또한 이것을 시도했지만 차이가 없습니다.

buy_ticket= OrderSend ( Symbol (),OP_BUYSTOP,Lots,Ask+Price, 30 ,Ask-SL, 0 , "Pending" ,magic, 0 ,Lime);
      RefreshRates();
sell_ticket= OrderSend ( Symbol (),OP_SELLSTOP,Lots,Bid-Price, 30 ,Bid+SL, 0 , "Pending" ,magic, 0 ,Red);

그리고 이렇게 해도 차이가 없습니다.

 if (total== 0 ) // && (Time[0]==time1)
 

모든 도움에 감사드립니다. 마침내 작동하게 되었습니다. 일관되게 작동하게 할 수 있는 유일한 방법은 다음과 같이 변경하는 것입니다.

 if ( total== 0 )
     {
      buystop_ticket= OrderSend ( Symbol (),OP_BUYSTOP,Lots,Ask+Price, 30 ,Ask-SL, 0 , "Pending" ,magic, 0 ,Lime);
       Print ( "buystop = " , GetLastError ());
      RefreshRates();
     }
   if ( total== 1 )
     {
      sellstop_ticket= OrderSend ( Symbol (),OP_SELLSTOP,Lots,Bid-Price, 30 ,Bid+SL, 0 , "Pending" ,magic, 0 ,Red);
       Print ( "sellstop = " , GetLastError ());
     }

또한 보류 중인 주문 이 활성화되기 전의 Pipmove 레벨도 stoplevel보다 높아야 한다는 것도 알아냈습니다. 이제 모든 것이 작동하는 것 같습니다. 감사합니다.

 
Trader3000 :

모든 도움에 감사드립니다. 마침내 작동하게 되었습니다. 일관되게 작동하게 할 수 있는 유일한 방법은 다음과 같이 변경하는 것입니다.

또한 보류 중인 주문이 활성화되기 전의 Pipmove 레벨도 stoplevel보다 높아야 한다는 것도 알아냈습니다. 이제 모든 것이 작동하는 것 같습니다. 감사합니다.

아니오, 하나의 거래가 열려 있는 한 이제 계속 판매 중지를 열 것이기 때문에 이것은 작동하지 않습니다.
 
간단한 대답은 현재 가격 에 너무 가까운 보류 중인 주문을 열려고 하지 않는 것입니다. 5포인트는 일반적으로 1/2핍입니다.
 
GumRai :
간단한 대답은 현재 가격에 너무 가까운 보류 중인 주문을 열려고 하지 않는 것입니다. 5 포인트는 일반적으로 반 핍입니다.

답변 감사합니다. 내 계산은 실제로 핍 단위이므로 보류 중인 주문은 최소 50포인트( 현재 가격 에서 5핍 떨어져 있음)이지만 스톱레벨에서 최소 1핍 더 멀리 이동하면 작동하는 것 같습니다. 즉, 50 EURUSD에 포인트. 차트로 드래그한 후 첫 번째 거래를 제외하고 두 거래가 모두 열리는 것처럼 보입니다. 하지만 지금은 괜찮습니다. 내 코드는 이제 다음과 같습니다.

 extern int TrailingStart= 20 ;
extern int TrailingStop= 5 ;
extern int Hedge= 10 ;
extern double Multiplier= 3 ;
extern int StopLossOriginal= 11 ;
extern int StopLossHedge= 9 ;
extern double Percentage= 1 ;
extern double Lotsize= 0.01 ;
extern double MyMaxlots= 30 ;
extern datetime StartTime1 = D'2016.03.25 14:50' ;
extern int Pipmove= 5 ;
int i,TS=TrailingStart-TrailingStop,stoplevel=(MarketInfo( Symbol (),MODE_STOPLEVEL))/ 10 ; //stoplevel has been converted from points to pips (/10)

int start()
  {
   double Lots = NormalizeDouble (AccountEquity()*Percentage*Lotsize/ 100 , 2 ),
          point= Point * 10 ,
          Price=Pipmove*point,
          SL=StopLossOriginal*point,
          MinLots = MarketInfo( Symbol (),MODE_MINLOT),
          MaxLots = MarketInfo( Symbol (),MODE_MAXLOT),
          HedgeLots= NormalizeDouble (OrderLots()*Multiplier, 2 );

   if (StopLossHedge<stoplevel) StopLossHedge=stoplevel;
   if (TS<stoplevel) TrailingStart=(stoplevel+TrailingStop);
   if (Pipmove<stoplevel+ 1 ) Pipmove=stoplevel+ 1 ;
   if (StopLossOriginal<=StopLossHedge) StopLossOriginal=StopLossHedge+ 1 ;

   datetime time1=StartTime1- 300 ;

   int buy_ticket= 0 ,sell_ticket= 0 ,buystop_ticket= 0 ,sellstop_ticket= 0 ,total= 0 ;
   for (i= OrdersTotal ()- 1 ; i>= 0 ; i--)
       if ( OrderSelect (i,SELECT_BY_POS) && OrderMagicNumber()==magic && OrderSymbol()== Symbol ())
        {
         total++;
         if (OrderType()==OP_BUYSTOP) buystop_ticket=OrderTicket();
         if (OrderType()==OP_SELLSTOP) sellstop_ticket=OrderTicket();
         if (OrderType()==OP_BUY) buy_ticket=OrderTicket();
         if (OrderType()==OP_SELL) sell_ticket=OrderTicket();
        }

   if (total< 1 && Time[ 0 ]==time1)
     {
      buystop_ticket= OrderSend ( Symbol (),OP_BUYSTOP,Lots,Ask+Price, 30 ,Ask-SL, 0 , "Pending" ,magic, 0 ,Lime);
      RefreshRates();
      sellstop_ticket= OrderSend ( Symbol (),OP_SELLSTOP,Lots,Bid-Price, 30 ,Bid+SL, 0 , "Pending" ,magic, 0 ,Red);
     }

나는 별개이지만 비슷한 문제에 부딪쳤다. 보류 중인 주문 중 하나가 실행되면 두 가지 중 하나가 발생할 수 있습니다. 다른 보류 주문이 삭제되는 지점에서 TrailingStop을 트리거합니다. 또는 그 거래가 나에게 불리한 경우 반대 방향으로 헤지를 열어야 합니다. 코드를 작성하는 방법에 따라 둘 이상의 헤지를 열거나 전혀 헤지를 열지 않을 것입니다. 나는 다음 두 가지를 포함하여 모든 것을 시도했습니다.

 if ( OrderSelect (buy_ticket,SELECT_BY_TICKET) && OrderType()==OP_BUY)
     {
       if (Bid-OrderOpenPrice()>TrailingStart*point)
        {
         if (OrderStopLoss()<Bid-TrailingStop*point)
           {
             if (OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*point,OrderTakeProfit(),Blue))
              {
               if ( OrderSelect (sellstop_ticket,SELECT_BY_TICKET) && OrderType()==OP_SELLSTOP)
                 {
                   if (OrderDelete(sellstop_ticket,Orange))
                     return ( 0 );
                 }
              }
           }
        }
       if (OrderOpenPrice()>Bid+Hedge*point && buy_ticket== 1 && sell_ticket<= 1 )
            {
              sell_ticket= OrderSend ( Symbol (),OP_SELL,HedgeLots,Bid, 3 ,Bid+StopLossHedge*point, 0 , "Hedge" ,magic, 0 ,Red);
            }  
        }
//Same for Sell

또는:


 //Same up to here:
else if ( total<= 2 && OrderOpenPrice()>Bid+Hedge*point)
        {
         sell_ticket= OrderSend ( Symbol (),OP_SELL,HedgeLots,Bid, 3 ,Bid+StopLossHedge*point, 0 , "Hedge" ,magic, 0 ,Red);
        }

이를 위해 별도의 for 루프를 사용해야 합니까? 고맙습니다

 

안녕하세요 여러분

몇 주 동안 시도했지만 아직 진전이 없습니다. 특정 조건에서 EA가 원래 거래에 대해 둘 이상의 헤지 거래를 시작한다는 점을 제외하고 모든 것이 지금 작동합니다. 원래 거래의 SL은 11핍이고 헤지 거래의 SL은 9핍입니다. 때때로 헤지 거래는 원래 거래가 아직 열려 있는 동안 9핍에서 중단됩니다. 그런 다음 원래 거래가 아직 열려 있는 동안 두 번째 헤지 거래와 세 번째 및 네 번째 헤지 거래를 엽니다. 나는 단순히 헤지 거래의 양을 하나로 제한하고 싶고 중단되면 원래 거래에 어떤 일이 일어나는지 기다리십시오.

이것은 내가 얻는 결과 유형입니다.

576 2015.01.15 11:39 구매 중지 29 0.48 1.16786 1.16616 0.00000 0.00 4834.24

577 2015.01.15 11:39 판매 중지 30 0.48 1.16642 1.16812 0.00000 0.00 4834.24

578 2015.01.15 11:39 팔다 30 0.48 1.16642 1.16812 0.00000 0.00 4834.24

579 2015.01.15 11:39 삭제 29 0.48 1.16786 1.16616 0.00000 0.00 4834.24

580 2015.01.15 11:42 구입 31 1.44 1.16743 1.16653 0.00000 0.00 4834.24

581 2015.01.15 11:42 s/l 31 1.44 1.16653 1.16653 0.00000 -129.60 4704.64

582 2015.01.15 11:44 구입 32 1.44 1.16742 1.16652 0.00000 0.00 4704.64

583 2015.01.15 11:44 s/l 30 0.48 1.16812 1.16812 0.00000 -81.60 4623.04

584 2015.01.15 11:48 수정하다 32 1.44 1.16742 1.16893 0.00000 0.00 4623.04

바이스톱 및 셀스톱 주문 (29 및 30)이 원래대로 열립니다. 그런 다음 가격이 떨어지고 매도 주문(30)이 채워지고 바이스톱(29)이 삭제됩니다. 그런 다음 가격이 다시 오르고 헤지(martingale) 주문(31)이 트리거됩니다(3*lotsize). 그런 다음 가격이 다시 떨어지고 헤지(31)가 중단되지만 30이 아직 열려 있기 때문에 또 다른 헤지(32) 등을 트리거합니다. 주문 32가 트리거되는 것을 방지하려면 어떻게 해야 합니까? 고맙습니다


 

안녕하세요 여러분. 이 문제를 해결하려고 시도한 지 한 달이 넘었고 프로그래밍 방식으로 코딩하는 것이 불가능하다고 생각하기 시작했습니다. 그래서 누군가가 이것을 확인시켜 주면 나는 그것을 쉬고 계속 진행할 수 있습니다. 위 포스트에서 설명한 것처럼 헤지(마틴게일) 주문 수에 대해 딥 레벨 설정이 불가능한가요? 고맙습니다.

지금까지 내가 가진 최고는 다음과 같습니다.

 int start()
{
   int buy_ticket= 0 ;
   int sell_ticket= 0 ;
   int total= 0 ;
   for ( int i= OrdersTotal ()- 1 ; i>= 0 ; i--)
       if ( OrderSelect (i,SELECT_BY_POS) && OrderSymbol()== Symbol ())
     {
         total++;
         if (OrderType()==OP_BUY) buy_ticket=OrderTicket();
         if (OrderType()==OP_SELL) sell_ticket=OrderTicket();
        }
   /*if(total==1 && OrderSelect(buy_ticket,SELECT_BY_TICKET) && OrderType()==OP_BUY) <------- this blocked out code is irrelevant, but I want to put it here for completeness
     {
      if(Bid-OrderOpenPrice()>TrailingStart*point)
        {
         if(OrderStopLoss()<Bid-TrailingStop*point)
           {
            if(OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop *point,OrderTakeProfit(),Blue))
               return(0);
           }
        }*/
       else if (OrderOpenPrice()>Bid+Hedge*point)
        {
         sell_ticket= OrderSend ( Symbol (),OP_SELL,HedgeLots,Bid, 3 ,Bid+StopLossHedge*point, 0 , "Hedge" ,magic, 0 ,Blue);
         return ( 0 );
        }
     }
  }
 

이를 달성할 수 있는 다양한 방법이 있습니다.

헤지 오픈 시 클라이언트 단말의 Global Variable을 생성합니다.

주요 거래의 티켓 번호를 포함하는 이름을 지정하십시오.

해당 티켓 번호 또는 필요한 경우 헤지 카운트에 대해 헤지 거래가 열렸음을 나타내는 플래그 역할을 하는 값을 지정하십시오.

헤지를 열기 전에 GV를 확인하십시오 .


헤지와 주요 거래는 로트 크기가 다릅니다.

헤지를 개설하기 전에 미결제 주문 및 내역을 확인하여 주요 거래의 오픈 시간보다 늦은 OrderOpenTime()으로 해당 로트 크기로 반대 주문이 개설되었는지 확인하십시오.

 
GumRai :

이를 달성할 수 있는 다양한 방법이 있습니다.

헤지 오픈 시 클라이언트 단말의 Global Variable을 생성합니다.

주요 거래의 티켓 번호를 포함하는 이름을 지정하십시오.

해당 티켓 번호 또는 필요한 경우 헤지 카운트에 대해 헤지 거래가 열렸음을 나타내는 플래그 역할을 하는 값을 지정하십시오.

헤지를 열기 전에 GV를 확인하십시오.


헤지와 주요 거래는 로트 크기가 다릅니다.

헤지를 개설하기 전에 미결제 주문 및 내역을 확인하여 주요 거래의 오픈 시간보다 늦은 OrderOpenTime()으로 해당 로트 크기로 반대 주문이 개설되었는지 확인하십시오.

이 옵션을 살펴보고 알려 드리겠습니다. 감사합니다.
 

그래서 Global Variable을 통해 이를 달성하려고 시도했지만 이 코드를 추가한 이후로 헤지 거래가 전혀 열리지 않습니다. 문제는 EA가 GlobalVariableCheck를 수행하고 있지만 아직 생성되지 않았기 때문에 계속되지 않는다는 것입니다. 그러나 올바른 티켓 번호를 선택하고 인쇄합니다. 아마도 내가 잘못하고 있습니다. 관련 코드는 다음과 같습니다.

 //+------------------------------------------------------------------+
//|  Hedge                                                           |
//+------------------------------------------------------------------+
void Hedgetrade(){
int buy_hedge= 0 ,sell_hedge= 0 ,total= 0 ;
double Pip= Point * 10 ,HedgeLots= NormalizeDouble (OrderLots()*Multiplier, 2 ),SLHedge=StopLossHedge*Pip;
   for ( int i= OrdersTotal ()- 1 ; i>= 0 ; i--){
       if ( OrderSelect (i,SELECT_BY_POS,MODE_TRADES)&& OrderSymbol()== Symbol ()){
      total++;
       int ticket=OrderTicket();
       Print ( "ticket = " ,ticket);
     }          
         if (OrderType()==OP_BUY){
             if (buy_hedge== 0 && sell_hedge== 0 && OrderOpenPrice()>Bid+Hedge*Pip)
               GlobalVariableCheck (ticket);
               sell_hedge= OrderSend ( Symbol (),OP_SELL,HedgeLots,Bid, 3 ,Bid+SLHedge, 0 , "Hedge" , 0 , 0 ,Blue);
                   GlobalVariableSet (ticket, 1 );
                 }
         if (OrderType()==OP_SELL){
             if (sell_hedge== 0 && buy_hedge== 0 && OrderOpenPrice()<Ask-Hedge*Pip)
               GlobalVariableCheck (ticket);
               buy_hedge= OrderSend ( Symbol (),OP_BUY,HedgeLots,Ask, 3 ,Ask-SLHedge, 0 , "Hedge" , 0 , 0 ,Red);
                   GlobalVariableSet (ticket, 1 );
              }
            }
          }