I want to place 2 pending orders that one's execution cancel the other. how can I do it?

 

moreover, the price I want to execute the order in is 2  dollars above and below to a specific price of a time. how can I do it?

 
  1. Sepehr Mohammadi: moreover, the price I want to execute the order in is 2  dollars above and below to a specific price of a time. how can I do it?

    Open an order 2 dollars below, and another 2 dollars plus the spread above; that is how you do it.

  2. Sepehr Mohammadi: I want to place 2 pending orders that one's execution cancel the other. how can I do it?

    There is no OCO. When one opens, close all pending orders; you write some code.

  3. There is no need to create pending orders in code.

    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
    2. Don't worry about it unless you're scalping M1 or trading news.
    3. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
 
You need open both sell and buy pending order with same lot. Then cancel the other if one triggered. But you must be very calculative to balance your returns else you will be $0 dollars at end of day 
 
Lungile Mpofu #:
You need open both sell and buy pending order with same lot. Then cancel the other if one triggered. But you must be very calculative to balance your returns else you will be $0 dollars at end of day 

Why would you be $0 dollars at end of day ?

 
Sepehr Mohammadi #: I have no idea how I should write its code in EA. Do you have any suggestion?

MT4: Learn to code it.
MT5: Begin learning to code it.

If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2019)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help (2017)