Deleting Limit orders or Pending orders

 

Hi, I am still learning coding and need some help. I am trying to create an EA where an order is opened once the criteria is met, in addition it also opens a Limit order a certain amount of pips away from the current open order.

I want the pending order to be removed/deleted once the open order has taken the profit and closed, therefor no need for the pending order to exist.

This is what I have currently.


{
     int result=0;
     if((iRSI(NULL,0,6,PRICE_CLOSE,1)<14)&&(iRSI(NULL,0,6,PRICE_CLOSE,0)<15)) // Here is your open buy rule
     {
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"My EA",MagicNumber,0,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit/AccountBalance()*10000*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        result=OrderSend(Symbol(),OP_BUYLIMIT,Lots*2,Ask-10,Slippage,0,0,"My EA",MagicNumber,0,Blue);
        if(result>0)
        return(0);

     }

Can anyone please assist me with what I need to add to this code to close the OP-BUYLIMIT order if the OP_BUY order closes.

 

Check the OrderCloseTime() to see if it has closed

Check if the OP_BUYLIMIT still exists as an OP_BUYLIMIT with OrderType(), if it does, delete it.

Do not use an EA generator, they create poor quality code and if you really want to learn how to code, you will learn bad habits.

result=OrderSend(Symbol(),OP_BUYLIMIT,Lots*2,Ask-10,Slippage,0,0,"My EA",MagicNumber,0,Blue);

 Ask-10??

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

    • We hate EA builder
    • You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
    • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
    • EA builder makes bad code counting up while closing multiple orders.
    • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
    • EA builder makes bad code Not adjusting for 4/5 digit brokers
    • EA builder makes bad code not adjusting for ECN brokers.
    • EA builder makes bad code not checking return codes.
    • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/reboot.)