关闭半数地段。 - 页 2

 

我需要阅读MathFloor和你的链接--这对我来说都是新的,我正在努力理解它。我明天会解决这个问题。

谢谢大家。

 
         if(Bid == btp-OrderOpenPrice()/2+OrderOpenPrice()){ // need to double check this.
               
               
         double  minLot  = MarketInfo(Symbol(), MODE_MINLOT),
                 lotStep = MarketInfo(Symbol(), MODE_LOTSTEP),
                 Lots    = OrderLots(),
                 half_close = MathFloor(Lots/2/lotStep)*lotStep;
                 
                    
               
         for(int q=OrdersTotal()-1; q >=0; q--)
         {
            if(OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==true){
              Print(" Stop loss value for the order is ", OrderStopLoss());
              Print("lots for the order ",OrderLots());
            }
            else if(OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==false){
              Print(" OrderSelect failed error code is ",GetLastError());
            }
            if(OrderMagicNumber()==MagicNumber)
             if(OrderSymbol()==Symbol())
              if(OrderType()==OP_BUYSTOP)
               if (half_close > minLot)

                
               CloseHalfLong = OrderClose(OrderTicket(),half_close,Bid,3,CLR_NONE);
               if(CloseHalfLong!=TRUE)Print("LastError = ", GetLastError());
         }
         } 
谁能给我一点指导,告诉我哪里出了问题?我现在才开始看这个。除了我写的那一行之外,谁能给我指出正确的方向?
 
有什么想法吗?
 
DomGilberto:
有什么想法吗?
你想关闭OrderLots()的一半?但在你选择一个订单之前,你怎么能使用OrderLots()?
 
哎呀--是的,已经整理好了,笑。但这并没有改变什么?

我错过了什么吗?
 
DomGilberto:
哎呀--是的,已经分类了,笑。但这并没有改变什么?

我是不是错过了什么?

为什么即使你的OrderSelect()失败了,你还在做以下工作?

if(OrderMagicNumber()==MagicNumber)
             if(OrderSymbol()==Symbol())
              if(OrderType()==OP_BUYSTOP)
               if (half_close > minLot)

你没有关闭一个挂起的订单,你的错误报告告诉你什么?

 

我相信你正试图两次选择相同的交易

这不应该是 "其他 "吗?

else if(OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==false){

如果你第一次尝试选择交易时失败了,但第二次却成功了,你可能会得到相互矛盾的信息。

 
我没有得到任何错误...

我对它感到有点沮丧......。我一直得到 "OrderModify error 1"--但我稍后会研究一下。除此之外,什么都没有!
            if(OrderSelect(NewOrder,SELECT_BY_TICKET,MODE_TRADES)==true){
              Print(" Stop loss value for the order is ", OrderStopLoss());
              Print("lots for the order ",OrderLots());
            }
            else if(OrderSelect(NewOrder,SELECT_BY_TICKET,MODE_TRADES)==false){
              Print(" OrderSelect failed error code is ",GetLastError());
            }
            
            double  minLot = MarketInfo(Symbol(), MODE_MINLOT),
            lotStep     = MarketInfo(Symbol(), MODE_LOTSTEP),
            sizeCurr    = OrderLots(),
            sizeClose   = MathFloor(sizeCurr/lotStep)*lotStep/2,
            sizeRem     = sizeCurr - sizeClose;
           //if (sizeClose < minLot)                                     return(false);
            //if (sizeRem   < minLot){ sizeClose = sizeCurr;
                 
           if(OrderTakeProfit()-OrderOpenPrice()/2+OrderOpenPrice() == Bid) // Does this make sense? I am wanting this "if" statement to be true, if price (bid) reaches the price in this comparison statement?

             if(OpenOrdersThisPair(Symbol())==1)
               
               CloseHalfLong = OrderClose(OrderTicket(),sizeClose,Bid,3,CLR_NONE);
                
                if(CloseHalfLong!=TRUE)Print("Last Error = ", GetLastError());
         
         } 
,我
的印象是MathFloor只是把答案四舍五入到整数?所以我不确定MathFloor是否正确?我使用的经纪商将使用0.01作为手数步长...(IBFX开始进行正向测试 - 所以是纳米级的)
 
DomGilberto:
我没有得到任何错误...

我对它感到有点沮丧......。我一直收到 "OrderModify error 1"--但我稍后会研究一下。除此以外,什么都没有! 我的印象是MathFloor只是将答案四舍五入到整数?所以我不确定MathFloor是否正确?我所使用的经纪商将使用0.01作为手数...(IBFX开始进行正向测试 - 所以是纳米级的)

你为什么不打印你的变量来看看发生了什么? 你发布的代码中没有OrderModify(),这有什么关系?

停止编码,看看你的代码,逐行阅读,了解它到底在做什么,如果这不是你想要的,那么你有一个问题需要解决。

 

MathFloor是否将小数点后的数字四舍五入到最近的整数?

FirstTarget作为 "OrderClose() "中的一个自定义参数 是否有意义 - 假设 "sizeClose "是正确的?(见引用的代码)

你的代码没有帮助 - 对不起。

你可以打印自定义变量吗?如果可以,我一定是做错了,因为它没有在日志中显示出来。

OrderModify是不相关的,你是对的。

           double FirstTarget = OrderTakeProfit()-OrderOpenPrice()/2+OrderOpenPrice();
              CloseHalfLong = OrderClose(OrderTicket(),sizeClose,FirstTarget,3,CLR_NONE);