找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 9|回复: 0

请教各位大神,我想在这段代码中增加一个功能,请问怎么改写,谢谢

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-24 15:27:00 | 显示全部楼层 |阅读模式
请教各位大神,我想在这段代码中增加一个功能, 当订单的盈利大于当前一半的止盈点数时,将止损改为平保止损,如果价格又回到一半止盈点数以内,依然保持平保止损,请问怎么改写,谢谢   


我在自己改写过一个,写出来,他一直把止损改来改去,一会儿是平保止损,一会儿是当前设置的止损,而且价格回到一半盈利后他就保持当前止损了


请指正,谢谢


// 计算上线和下线的新位置

   double currentAsk = Ask + 上线点数 * Point;

   double currentBid = Bid - 下线点数 * Point;


// 更新上线和下线的位置

   ObjectSet("上线", OBJ_HLINE, currentAsk);

   ObjectSet("下线", OBJ_HLINE, currentBid);


// 获取当前的买价和卖价

   double CurrentAsk = Ask;

   double CurrentBid = Bid;


// 遍历所有活动订单

   int ordersCount = OrdersTotal();

   for(int i = 0; i < ordersCount; i++)

     {

      // 选择活动订单

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

         continue;


      // 检查订单是否与当前交易品种匹配以及订单类型(买单或卖单)

      if(OrderSymbol() != Symbol() || OrderType() != OP_BUY&& OrderType() != OP_SELL)

         continue;


      // 检查买单的止损和止盈价格

      if(OrderType() == OP_BUY)

        {

         // 计算新的止损和止盈价格

         double newStopLoss = OrderOpenPrice() - SL * Point;

         double newTakeProfit = OrderOpenPrice() + TP * Point;

         double halfnewTakeProfit = OrderOpenPrice() + TP * Point*0.5;

         // 检查当前价格是否超过了止损或止盈价格


         if(currentAsk > newStopLoss ||currentBid < newTakeProfit)

           {

            // 修改订单的止损和止盈价格

            OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, newTakeProfit, 0);

           }


        }

      // 检查卖单的止损和止盈价格

      else

         if(OrderType() == OP_SELL)

           {

            // 计算新的止损和止盈价格

            double newStopLoss = OrderOpenPrice() + SL * Point;

            double newTakeProfit = OrderOpenPrice() - TP * Point;

             double halfnewTakeProfit = OrderOpenPrice() - TP * Point*0.5;

            // 检查当前价格是否超过了止损或止盈价格

            if(currentAsk < newStopLoss ||currentBid > newTakeProfit)  

              {

               // 修改订单的止损和止盈价格

               OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, newTakeProfit, 0);

              }


           }

     }


  }
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-12 14:40 , Processed in 0.092147 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表