STOP & REVERSE Orders

MQL4 EA 통합

작업 종료됨

실행 시간 17 시간

명시

Hi, I am trying to insert STOP & REVERSE Orders into the void UpdateBE() of my EA with the following trial and error self-coding, but seems not right...


I am not sure how to use the proper return function, is it just return or return(0) ? and also where to place the return function correctly.


1. I want my EA to close the current open order and open the new reversed order (buy to sell or sell to buy) at certain price level from the opening price.


2. I want my EA to keep doing it but maximum 3 times (if the STOP & REVERSE has been triggered for 3 times- adjustable to 5 times), 

but just one pending stop & reverse order per 1 time.


I am not a coder so I need a coder to help me with this. Thanks in advance.


Regards,

Joe




void UpdateBE()

{

if(UpdateToBE1 <= 0)

return;


for(int i = OrdersTotal() - 1; i >= 0; i--)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

  {

  if(!IsThisChartOrder())

  continue;

 

  if(OrderType() == OP_BUY && OrderOpenPrice() > OrderStopLoss() && Bid - OrderOpenPrice() >= (UpdateToBE1 * Poin))

  {

  OrderModifySafe(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + (BE_LockPLPip1 * Poin), OrderTakeProfit(), 0);

  }

  else if(OrderType() == OP_SELL && OrderOpenPrice() < OrderStopLoss() && OrderOpenPrice() - Ask >= (UpdateToBE1 * Poin))

  {

  OrderModifySafe(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - (BE_LockPLPip1 * Poin), OrderTakeProfit(), 0);

  }

 

  if(OrderType() == OP_BUY && OrderOpenPrice() > OrderStopLoss() && Bid - OrderOpenPrice() >= (UpdateToBE2 * Poin))

  {

  OrderModifySafe(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + (BE_LockPLPip2 * Poin), OrderTakeProfit(), 0);

  }

  else if(OrderType() == OP_SELL && OrderOpenPrice() < OrderStopLoss() && OrderOpenPrice() - Ask >= (UpdateToBE2 * Poin))

  {

  OrderModifySafe(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - (BE_LockPLPip2 * Poin), OrderTakeProfit(), 0);

  }

 

  if(StopReverse_ON)

  {

  //if(OrdersTotal() > 3)

  //   return;

 

  double lots = CalculateLotSize();

  lastOrderTime = TimeCurrent();

 

  if(OrderType() == OP_BUY && OrderOpenPrice() > OrderStopLoss() && Bid < OrderOpenPrice()

  && NormalizeDouble(Bid - OrderStopLoss(), Digits) <= NormalizeDouble((StopReverse_PreparePip * Poin), Digits))

  {

                        OrderClose(OrderTicket(), OrderLots(), OrderStopLoss() + (StopReverse_PreparePip * Poin), Slippage);

  return;

  //OrderSendSafe(Symbol(), OP_SELL, lots, OrderStopLoss(), Slippage, OrderStopLoss() + (StopLoss * Poin), OrderStopLoss() - (TakeProfit1 * Poin), "Reversed 1 BUY ", EAMagicNo, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);

  OrderSendSafe(Symbol(), OP_SELLSTOP, lots, OrderStopLoss() + (StopReverse_PreparePip * Poin), Slippage, OrderStopLoss() + (StopLoss * Poin), OrderStopLoss() - ((TakeProfit1+10) * Poin), "Reversed 2 BUY ", EAMagicNo, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);

  return;

  }

  else if(OrderType() == OP_SELL && OrderOpenPrice() < OrderStopLoss() && Ask > OrderOpenPrice()

  && NormalizeDouble(OrderStopLoss() - Ask, Digits) <= NormalizeDouble((StopReverse_PreparePip * Poin), Digits))

  {

                        OrderClose(OrderTicket(), OrderLots(), OrderStopLoss() - (StopReverse_PreparePip * Poin), Slippage);

  return;

  //OrderSendSafe(Symbol(), OP_BUY, lots, OrderStopLoss(), Slippage, OrderStopLoss() - (StopLoss * Poin), OrderStopLoss() + (TakeProfit1 * Poin), "Reversed 1 SELL ", EAMagicNo, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Green);

  OrderSendSafe(Symbol(), OP_BUYSTOP, lots, OrderStopLoss() - (StopReverse_PreparePip * Poin), Slippage, OrderStopLoss() - (StopLoss * Poin), OrderStopLoss() + ((TakeProfit1+10) * Poin), "Reversed 2 SELL ", EAMagicNo, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Green);

  return;

  }

  return; //return(0);

  }

  }

}

}

응답함

1
개발자 1
등급
(88)
프로젝트
143
39%
중재
21
19% / 48%
기한 초과
30
21%
무료

프로젝트 정보

예산
20- USD
기한
 3 일