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

 

예, 주문을 다시 선택해야 합니다.

   int buy_ticket= 0 ;
   total= 0 ;
   for (i = OrdersTotal ()- 1 ; i >= 0 ; i--)
   if ( OrderSelect (i, SELECT_BY_POS)                
    &&  OrderMagicNumber()  == magicNumber            
    &&  OrderSymbol()       == Symbol ())
    {             
      total++;
       if (OrderType()==OP_BUY)
         buy_ticket=OrderTicket();
    }
    
   if (buy_ticket> 0 && OrderSelect (buy_ticket,SELECT_BY_TICKET))
     {
     //Do stuff
     }

위의 코드를 사용하여 티켓 번호를 저장할 새 변수를 만든 다음 티켓 번호로 거래를 선택할 수 있습니다.

 
GumRai :

예, 주문을 다시 선택해야 합니다.

위의 코드를 사용하여 티켓 번호를 저장할 새 변수를 만든 다음 티켓 번호로 거래를 선택할 수 있습니다.

대박!!!!!! 감사합니다. 몇 주 후에 모든 것이 작동합니다. 나는 많은 것을 배웠다. 모두 감사합니다!!!
 
Trader3000 :
대박!!!!!! 감사합니다. 몇 주 후에 모든 것이 작동합니다. 나는 많은 것을 배웠다. 모두 감사합니다!!!

미안하지만 내가 너무 빨리 말했다. Trailingstop은 때때로 시작되므로 코드가 여전히 어딘가에서 손상되었다고 생각합니다. 다음은 전체 EA입니다. 누군가 확인 하고 실수를 발견하면 알려주시겠습니까? 고맙습니다

 #define magicNumber   12345

// Kicks in when position reaches at least TrailingStop pips of profit.

extern string Label_Trailingstart = "Pip threshold to activate Trailing stop" ;
extern double TrailingStart = 10 ;
extern string Label_Trailingstop = "Pips trailing behind" ;
extern double TrailingStop = 5 ;

//Set it to some value above 0 to activate Hedge
extern double Hedge = 10 ;
extern double Multiplier = 3 ;

extern string Label_StopLoss = "Set StopLoss of original trade" ;
extern double StopLoss = 11 ;

extern string Label_Stoploss1 = "Set Stoploss of Hedge trade" ;
extern string Label_Stoploss2 = "Value should be less than 'Hedge'" ;
extern string Label_Stoploss3 = "otherwise a second Hedge trade will open" ;
extern double Stoploss = 9 ;

extern string Label_Percentage = "Lotsize percentage of Equity" ;
extern double Percentage = 1 ;
extern double Lotsize = 0.01 ;

int i, result, total;
double stoplevel;

int init()
{
   stoplevel=(MarketInfo( Symbol (),MODE_STOPLEVEL))/ 10 ;   // get broker's stoplevel
   if (StopLoss<=stoplevel) StopLoss=stoplevel;     // we compare our StopLoss with
   if (Stoploss<=stoplevel) Stoploss=stoplevel;     // stoplevel and adjust it when error occured
   if (TrailingStop<=stoplevel) TrailingStart=stoplevel+TrailingStop;   // we compared our TakeProfit
                                                       // as we compared our StopLoss
   if ((StopLoss || Stoploss || TrailingStop) < stoplevel)
   {
   MessageBox ( "Please note: If your inputs for StopLoss, Stoploss" +
               "\nand/or TrailingStop are below the minimum levels" +
               "\nrequired by your broker, they will automatically" + 
               "\nbe increased to " + StringConcatenate (stoplevel)); 
   }                                                             
   return ( 0 );
}
 
int deinit()
{
   return ( 0 );
}
 
int start()
{ 
   //double Lots = NormalizeDouble(AccountEquity()*Percentage*Lotsize/100, 2);
   
   int buy_ticket= 0 ;
   int sell_ticket= 0 ;
   total= 0 ;
   for (i = OrdersTotal ()- 1 ; i >= 0 ; i--)
   if ( OrderSelect (i, SELECT_BY_POS)                
    &&  OrderMagicNumber()  == magicNumber            
    &&  OrderSymbol()       == Symbol ())
    {             
      total++;
       if (OrderType()==OP_BUY)
         buy_ticket=OrderTicket();
       if (OrderType()==OP_SELL)
         sell_ticket=OrderTicket();   
    }
           if (total== 0 && Close[ 1 ]>Close[ 2 ])
           {
              result= OrderSend ( Symbol (), OP_BUY, 0.01 , Ask, 3 , Ask - StopLoss* Point * 10 , 0 , "Original" , magicNumber, 0 , Blue);
               Print ( "Error setting Original order: " , GetLastError ());     
           }
           
     if (buy_ticket> 0 && OrderSelect (buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_BUY) 
       {
         if (Bid - OrderOpenPrice() > NormalizeDouble (TrailingStart * Point * 10 , Digits ))
         {
           if (OrderStopLoss() < Bid - NormalizeDouble (TrailingStop * Point * 10 , Digits ))
           {
               if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid - NormalizeDouble (TrailingStop * Point * 10 , Digits ),
              OrderTakeProfit(), Blue)) 
               Print ( "Error setting Buy trailing stop: " , GetLastError ()); 
           }
         }
             else if (OrderOpenPrice() > Bid + NormalizeDouble (Hedge* Point * 10 , Digits ))
             if (total == 1 )
            {
            result= OrderSend ( Symbol (), OP_SELL, NormalizeDouble (OrderLots() * Multiplier, 2 ), Bid, 3 ,
            Bid + Stoploss* Point * 10 , 0 , "Hedge" , magicNumber, 0 , Blue);
             Print ( "Error setting Sell Hedge: " , GetLastError ());
            }
       }
     else if (sell_ticket> 0 && OrderSelect (buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_SELL)
       {
         if (OrderOpenPrice() - Ask > NormalizeDouble (TrailingStart * Point * 10 , Digits )) 
         {
           if (OrderStopLoss() > Ask + NormalizeDouble (TrailingStop * Point * 10 , Digits ))
           {
               if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask + NormalizeDouble (TrailingStop * Point * 10 , Digits ),
              OrderTakeProfit(), Red))
               Print ( "Error setting Sell trailing stop: " , GetLastError ()); 
           }
              }
                 else if (OrderOpenPrice() < Ask - NormalizeDouble (Hedge* Point * 10 , Digits ))
             if (total == 1 )
            { 
            result= OrderSend ( Symbol (), OP_BUY, NormalizeDouble (OrderLots() * Multiplier, 2 ), Ask, 3 ,
            Ask - Stoploss* Point * 10 , 0 , "Hedge" , magicNumber, 0 , Red);
             Print ( "Error setting Buy Hedge: " , GetLastError ());
            }  
            }
     return ( 0 );
}
 
   if (buy_ticket> 0 && OrderSelect (buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_BUY) 
       {
         //Code
       }
     else if (sell_ticket> 0 && OrderSelect (buy_ticket,SELECT_BY_TICKET) && OrderType() == OP_SELL)
       {
         //If there is an open buy order code here will not be executed
         //The else is not necessary
       }

,

 
GumRai :

,

지적해주셔서 정말 감사합니다. 나는 실수를 수정했고 지금은 작동합니다. 다른 질문이 있습니다. 내 손절매가 브로커의 STOP_LEVEL보다 작을 때 메시지 상자가 팝업되도록 하려고 하는데 그 이상인데도 팝업이 뜹니다. '초기화' 섹션이 아닌 '시작' 섹션에 넣으려고 했으나 거기에서도 작동하지 않습니다. 누가 보시고 무엇이 잘못되었는지 알려주시겠습니까? 고맙습니다

 int init()
{
   stoplevel=(MarketInfo( Symbol (),MODE_STOPLEVEL))/ 10 ;   // get broker's stoplevel
   if (StopLoss<=stoplevel) StopLoss=stoplevel;     // we compare our StopLoss with
   if (Stoploss<=stoplevel) Stoploss=stoplevel;     // stoplevel and adjust it when error occured
   if (TrailingStop<=stoplevel) TrailingStart=stoplevel+TrailingStop;   // we compared our TakeProfit
                                                       // as we compared our StopLoss
   if ((StopLoss || Stoploss || TrailingStop) < stoplevel)
   {
   MessageBox ( "Please note: If your inputs for StopLoss, Stoploss" +
               "\nand/or TrailingStop are below the minimum levels" +
               "\nrequired by your broker, they will automatically" + 
               "\nbe increased to " + StringConcatenate (stoplevel)); 
   }                                                             
   return ( 0 );
}
 
   if ((StopLoss || Stoploss || TrailingStop) < stoplevel)

말이 안 된다

말입니까?

   if ((StopLoss  < stoplevel || TrailingStop) < stoplevel)
 
GumRai :

말이 안 된다

말입니까?

다시 한번 감사드립니다. 문제가 해결되었습니다. :)
 

안녕하세요 여러분, 또 난관에 부딪혔습니다. 매우 이상하고 왜 이런 일이 일어나는지 이해할 수 없습니다. 위에서 언급했듯이 EA는 잘 작동했지만 이제는 단순히 이것에서 변경하고 싶습니다.

result= OrderSend ( Symbol (), OP_BUY, 0.01 , Ask, 3 , Ask - StopLoss* Point * 10 , 0 , "Original" , magicNumber, 0 , Blue);

에게

result= OrderSend ( Symbol (), OP_BUY, 0.01 , Ask, 3 , 0 , 0 , "Original" , magicNumber, 0 , Blue);

다른 것은 건드리지 않지만 이 간단한 변경 후에는 트레일링 스톱이나 헤지가 트리거되지 않습니다. 이상해. 전체 코드는 위에 있습니다

 
당신이 하나가 없을 때 어떻게 스톱을 추적 할 수 있습니까?
 

답변 감사합니다만 이해가 안되네요. 후행 정류장 코드는 여기

{
         if (Bid - OrderOpenPrice() > NormalizeDouble (TrailingStart * Point * 10 , Digits ))
         {
           if (OrderStopLoss() < Bid - NormalizeDouble (TrailingStop * Point * 10 , Digits ))
           {
               if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid - NormalizeDouble (TrailingStop * Point * 10 , Digits ),
              OrderTakeProfit(), Blue)) 

Stoploss가 있으면 EA가 작동하고 Trailingstop과 헤지가 시작되지만 Stoploss를 0으로 변경하면 아무 것도 작동하지 않습니다. Stoploss가 Trailingstop과 헤지에 영향을 미치는 방법과 이유를 모르겠습니다.

사유: