STOP & REVERSE Orders

MQL4 Experts Integration

Job finished

Execution time 17 hours

Specification

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);

  }

  }

}

}

Responded

1
Developer 1
Rating
(88)
Projects
143
39%
Arbitration
21
19% / 48%
Overdue
30
21%
Free
Similar orders
I am looking for simple automated trade for NT8 . I want to place an Oco order at the open 9:30 Buy above the previous bar high and sell below the previous bar close. I want to set my own target and stop. Just this one trade
Overview: We are seeking a highly skilled Python Developer with experience in finance and trading software development, specifically with expertise in MetaTrader 4 (MT4). The project involves creating a Python script that connects to an MT4 account to extract historic trades and graphically present historical drawdown data (got from third party data) on < 15 min timeframe. Project Objectives: Develop a Python script
Seeking a freelance developer to bridge MetaTrader 4 (MT4) with eToro. Your task is to create a seamless connection to execute trades across both platforms. This will allow my ea's to copy trades onto the platform, i'm looking for something similar to the program CMAM that allows fixed lots and auto balance risk options based on equity and balance
Hi Everybody. I need to refine a code, written with my limited knowledge, in Tradingview for automated trading to entry orders in MT4 via Pineconnector that generates an alarm containing entry price, TP and SL (the latter two in value and not in pips) per single trade. The code to be refined already calculates the entry price (the entry is at the opening of the candle following the occurrence of the specific
I'm only seeking experienced developers who have successfully completed projects similar to this. I require someone to develop a copy-trading system that can execute trades on clients' mt4/mt5 upon my posting on platforms like Telegram or spreadsheets . Additionally, I need a feature for tracking and recording the trading signals that I send. I'll provide further details and examples during our discussion
I am looking for a coder to code my custom Ninjatrader 8 strategy to make it work perfectly your professioalism is needed in the project Kindly cotact me now and let Proceed
Hi there, can you create an addon for Ninja Trader that replicates the Level 2 window? See image attached. I am looking to change the row colours based on the size

Project information

Budget
20- USD
Deadline
to 3 day(s)