如何使收支平衡在一个条目中触发多次

How to make Break even trigger more than one time in one entry

我现在试图让收支平衡代码触发不止一次, 示例 EA 入场价为 1.28000,止损价为 1.28500 如果当前价格达到 1.175000(50pips),sl 移动至收支平衡,例如 1.28000(5pips)。

EA满足条件后不再修改订单

所以如果价格达到 1.17000(100pips),如何再次触发盈亏平衡,止损移动到 (1.175000)(50pips)

价格再次达到 1.165000(150pips),止损线移动到 1.17000(100pips)

我想

BE_B_M(sl move to(example:5)) 

BE_B_T(price reach(example:50)) 

作为变量,每次价格达到目标变量都会更改为下一个值 所以变成了

BE_B_M(sl move to(example:50)) and BE_B_T(price reach(example:100)) 

整个代码如下

extern double  BE_T_1      = 50;   
extern double  BE_M_1      = 5;  

extern double  BE_T_2      = 100;   
extern double  BE_M_2      = 50;

extern double  BE_T_3      = 150;   
extern double  BE_M_3      = 100;

double BE_S_M; 
double BE_S_T;

void MOVE_BE_1()

  {
   for(int b=OrdersTotal()-1;b>=0;b--)
     {

      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()!=M_Number)continue;
      if(OrderSymbol()==Symbol())
         if(OrderType()==OP_BUY)
            if(Bid-OrderOpenPrice()>BE_S_T*Pips)
               if(OrderOpenPrice()>OrderStopLoss())
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(BE_S_M*Pips),OrderTakeProfit(),0,CLR_NONE))
                     Print("eror");
     }

   for(int s=OrdersTotal()-1;s>=0;s--)
     {
      if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()!=M_Number)continue;
      if(OrderSymbol()==Symbol())
         if(OrderType()==OP_SELL)
            if(OrderOpenPrice()-Ask>BE_S_T*Pips)
               if(OrderOpenPrice()<OrderStopLoss())
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(BE_S_M*Pips),OrderTakeProfit(),0,CLR_NONE))
                     Print("eror");
     }

  }

我预计 sl 将在价格从入场起每 50 个点移动后移动

在这里您可以将所有 3 个收支平衡水平放在一个函数上。

注意:OP_BUYOP_SELL

都可以使用 1 for-loop

这是我的 OnInit()

// Global variable
double point;

int OnInit()
  {
   if(Digits == 5 || Digits == 3) point=Point*10;
   else point=Point;
   return(INIT_SUCCEEDED);
  }

这里是BreakEven()函数

//+------------------------------------------------------------------+
//| Break even the trade at 3  levels                                |
//+------------------------------------------------------------------+
void BreakEven()
  {
   // get the stop level for that symbol
   double stopLevel = SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL)*Point;

   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderMagicNumber()!=M_Number)continue;
      if(OrderSymbol()!=Symbol())continue;

      if(OrderType()==OP_BUY)
        {
         double profitPips=Bid-OrderOpenPrice();
         double newSL=OrderStopLoss();

         if(profitPips>=BE_T_1*point && OrderStopLoss()<OrderOpenPrice()) // Break Even
           {
            newSL=OrderOpenPrice()+BE_M_1*point;
           }
         else if(profitPips>=BE_T_3*point) // 150/100
           {
            newSL=OrderOpenPrice()+BE_M_3*point;
           }
         else if(profitPips>=BE_T_2*point) // 100/50
           {
            newSL=OrderOpenPrice()+BE_M_2*point;
           }

         if(newSL>=OrderStopLoss()+Point && newSL<Bid-stopLevel)
            if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(newSL,Digits),OrderTakeProfit(),0))
               Print("Error at BE: ",GetLastError());
        }
      else if(OrderType()==OP_SELL)
        {
         double profitPips=OrderOpenPrice()-Ask;
         double newSL=OrderStopLoss();
         if(profitPips>=BE_T_1*point && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0)) // Break Even
           {
            newSL=OrderOpenPrice()-BE_M_1*point;
           }
         else if(profitPips>=BE_T_3*point) // 150/100
           {
            newSL=OrderOpenPrice()-BE_M_3*point;
           }
         else if(profitPips>=BE_T_2*point) // 100/50
           {
            newSL=OrderOpenPrice()-BE_M_2*point;
           }

         if(newSL<=OrderStopLoss()-Point && newSL>Ask+stopLevel)
            if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(newSL,Digits),OrderTakeProfit(),0))
               Print("Error at BE: ",GetLastError());
        }
     }

  }

我自己没有在交易中测试过这个,但它应该有用。