简体   繁体   English

如何使用 OrderModify() 修改所有当前打开的 position 的获利?

[英]How do i modify TakeProfit of all current open position using OrderModify()?

I have opened up to five buy trades with their individual take profit.我已经开设了多达五笔买入交易,他们各自的获利了结。 I want to change the take profit of the first four buy trades to the take profit of number five buy trade.我想将前四次买入交易的止盈更改为第五次买入交易的止盈。 modifyAllBuyOrdTP() is the function created to modify the take profit while findTpL_BuyOrd() function will get the take profit of the last trade that just finished opened. modifyAllBuyOrdTP()是为修改止盈而创建的 function,而findTpL_BuyOrd() function 将获得刚刚完成的最后一笔交易的止盈。 It is not working in strategy tester.它在策略测试器中不起作用。 I will be grateful to anyone that can help me on this problem.我将感谢任何可以帮助我解决这个问题的人。 Thank you in advance.先感谢您。

void modifyAllBuyOrdTP(){
       
       if(CountTradesBuy()>=2){
          for(int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--)
          {
             OrderSelect(l_pos_4, SELECT_BY_TICKET);
             if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)
                continue;
             if(OrderTakeProfit() == findTpL_BuyOrd())
                continue;
             if(OrderStopLoss() == 0 && OrderTakeProfit() != findTpL_BuyOrd() && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber){
               if(OrderType() == OP_BUY){
                   ModifyStopsByPrice(OrderTicket(),0,findTpL_BuyOrd());//Print(" b tp ",findTpL_BuyOrd());
               }
             }
          }
      }
   }
    
double findTpL_BuyOrd(){
   double l_ord_TP = 0;
      for(int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--)
      {
         OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)
            continue;
         if(OrderTakeProfit() == 0)
            continue;
         if(OrderTakeProfit()!=0 && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber){
           if(OrderType() == OP_BUY){
               l_ord_TP = OrderTakeProfit();
               break;
           }
         }
      }
  return l_ord_TP;
}

In modifyAllBuyOrdTP() function you should select orders by SELECT_BY_POS if you iterating over them.modifyAllBuyOrdTP() function 中,如果您对它们进行迭代,您应该通过SELECT_BY_POS订购 select 订单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM