Как заставить безубыточный запуск более одного раза за одну запись - PullRequest
0 голосов
/ 19 июня 2019

Я сейчас пытаюсь заставить безубыточный код срабатывать более одного раза, пример EA вход 1.28000 и стоп лосс 1.28500 если текущая цена достигает 1.175000 (50 пунктов), sl движется к безубыточности, например 1.28000 (5 пунктов).

EA больше не будет изменять порядок после выполнения условия.

как запустить безубыточность еще раз, если цена достигнет 1,17000 (100 пунктов), скользя к (1,175000) (50 пунктов)

и снова цена достигает 1.165000 (150 пунктов), скользя к 1.17000 (100 пунктов)

Я хочу сделать

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 пунктов от входа

1 Ответ

1 голос
/ 20 июня 2019

Здесь вы можете поместить все 3 уровня безубыточности в одну функцию.

Примечание: вы можете использовать 1 for-loop как для OP_BUY, так и для OP_SELL

Вот мой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());
        }
     }

  }

Я сам не проверял это в сделке, но он должен работать.

...