关闭半数地段。 - 页 4

 
DomGilberto:
我真不敢相信我在犯这些菜鸟的错误......。让我很恼火!是的,我现在得到了它的打印和选择订单。这是在打印方面起作用的代码--但是手数仍然没有被关闭?我还把日志信息粘贴在下面。

2013.07.31 11:13:52 2013.02.01 16:00 trendfishing_play_ground EURUSD,H1: Order Select returned the error of 0 // Not sure what is going on here?

if(OrderSelect(c,SELECT_BY_TICKET,MODE_TRADES)==true)

C是一个位置,而不是一个票号......。

 

(facepalm - I obviously need a break from it!) ok sorted that and it's now selecting the order.这是现在的日志打印 - "Close_Half_Order" 错误 = 0?这就是实际的OrderClose函数 的失败。这与 "要关闭的手数 "部分的小数点后的 "000 "数字无关,是吗?

2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Close_Half_Order Last Error = 0
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.18
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 9
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.09000
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.37931
 
DomGilberto:

(facepalm - I obviously need a break from it!) ok sorted that and it's now selecting the order.这是现在的日志打印 - "Close_Half_Order" 错误 = 0?这就是实际的OrderClose函数的失败。这与 "要关闭的手数 "部分的小数点后的 "000 "数字无关,是吗?

大括号,大括号,大括号。...有时你需要使用它们,有时你不需要。

OrderClose()并没有失败。. .

            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                if(OrderType()==OP_BUY)
                  if(OpenOrdersThisPair(Symbol())==1)   //  if this is true . . . 

                bool Close_Half_Order = OrderClose(OrderTicket(),half,FirstTarget_Buy,3,CLR_NONE); // . . .  do this.

            if(Close_Half_Order!=TRUE)Print("Close_Half_Order Last Error = ", GetLastError());  //  do this whatever happens . . .

所以如果OrderType()不是OP_BUY,最后一行仍然会被执行,因此错误为0 ... ...像这样添加大括号。

            if(OrderMagicNumber() == MagicNumber)
              if(OrderSymbol() == Symbol())
                if(OrderType() == OP_BUY)
                  if(OpenOrdersThisPair(Symbol()) == 1) 
                     {
                     bool Close_Half_Order = OrderClose(OrderTicket(), half, FirstTarget_Buy, 3, CLR_NONE);
                     if(Close_Half_Order != TRUE) Print("Close_Half_Order Last Error = ", GetLastError() );  // only executed if the OrderClose() was also executed
                     } 
 
一致的缩进也有助于你清楚地看到正在发生的事情
 
嗯,仍然不想关闭@"Close_Half_Order"?也没有得到任何错误信息?
 
DomGilberto:
嗯,仍然不想关闭@"Close_Half_Order"?也没有收到任何错误信息?
您的订单类型 是什么?
 
OP_BUY?

  if(OrderSelect(OrdersTotal(),SELECT_BY_TICKET,MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1){
         
         double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );{
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
         }
         
         double minLot  = MarketInfo(Symbol(), MODE_MINLOT);{
                Print("The minimum lots are: ", DoubleToStr( minLot, Digits ));
                }
                        
         double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);{
                Print("The Lotstep is: ", DoubleToStr( lotStep, Digits ));
                }
                
         double half    = MathCeil(OrderLots()/2/lotStep)*lotStep;{
                Print("The Lots to close is: ", DoubleToStr( half, Digits ));
                }
      for( int c=OrdersTotal()-1; c >=0; c-- )
      {
         if(OrderSelect(c,SELECT_BY_POS,MODE_TRADES)==true){
            Print("Order Ticker Number = ",OrderTicket());
            Print("Order Lots Open = ", OrderLots());
            } 
         else{
           Print("Order Select returned the error of ", GetLastError()); // Order Select does not seem to want to work?
            continue;
            }
            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                if(OrderType()==OP_BUY)
                  if(OpenOrdersThisPair(Symbol())==1){ 
                bool Close_Half_Order = OrderClose(OrderTicket(),half,FirstTarget_Buy,3,CLR_NONE);
                if(Close_Half_Order!=TRUE)Print("Close_Half_Order Last Error = ", GetLastError());
                }
      } 
   }
 
DomGilberto:
OP_BUY?


你之前说过挂单,你在测试时是否真的有一个OP_BUY开着?
 

顺便说一句,这些大括号除了混淆视听之外,没有任何作用......。

         double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );  {  
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
         }  
         
         double minLot  = MarketInfo(Symbol(), MODE_MINLOT);  {  
                Print("The minimum lots are: ", DoubleToStr( minLot, Digits ));
                }  
                        
         double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);  {  
                Print("The Lotstep is: ", DoubleToStr( lotStep, Digits ));
                }  
                
         double half    = MathCeil(OrderLots()/2/lotStep)*lotStep;  {  
                Print("The Lots to close is: ", DoubleToStr( half, Digits ));
                }  
 

我输入了一个挂单 "OP_BUYSTOP",但我的印象是,当触发时,这个挂单会改变为 "OP_BUY"?

我以为如果它被触发,订单类型 将是 "OP_BUY"?

毕竟,我只对订单被触发后的情况感兴趣?

为什么这些大括号令人困惑?你是指左括号的位置吗?如果是这样的话,这似乎是一个单独的问题,因为我已经被纠正过多次了?