ea can not open new position at the time of hitting tp

 

Terminal : mt5

Spread: 1

when one of my positions hits tp, at the same price I want to open new position, but ea can not open new position (tp hits correctly).

Example :

I opened 1 buy at 1.13000 with tp 1.13040 and sell at 1.12999 with tp 1.12959; when price at 1.13040 exactly at the same time two opposite positions should opened

at 1.13000

Please help me

 
ridwan hoque: I opened 1 buy at 1.13000 and sell at 1.12999; when price at 1.13040 exactly 

Price is never exactly anything. You are forgetting the spread.

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

 
William Roeder #:

Price is never exactly anything. You are forgetting the spread.

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

Thanks for reply, I know about spread and mentioned at the beginning of this thread, however. I think I should more clarify my question.

Example:

buyOrder1 = 13000 (tp:13040) [running]

sellOrder1 = 12999 (tp:12559) [running]

when buyOrder1 is closed at tp price, my ea has a request by OrderSend() function to open 

two new orders 

buyOrder2 = 13040 [to be executed]

sellOrder2 = 13039 [to be executed]

but when the market price is 13070 (greater than 13040 with spread),

what happens: just buyOrder1 closed with tp,

what expected: buyOrder1 should be closed along with buyOrder2 and sellOrder2 to be opened.

this is the problem,

after reaching even crossing the price more than 10-20 points more than set price(13040) no orders opened, but tp closes the first order correctly

 
ridwan hoque #:

Thanks for reply, I know about spread and mentioned at the beginning of this thread, however. I think I should more clarify my question.

Example:

buyOrder1 = 13000 (tp:13040) [running]

sellOrder1 = 12999 (tp:12559) [running]

when buyOrder1 is closed at tp price, my ea has a request by OrderSend() function to open 

two new orders 

buyOrder2 = 13040 [to be executed]

sellOrder2 = 13039 [to be executed]

but when the market price is 13070 (greater than 13040 with spread),

what happens: just buyOrder1 closed with tp,

what expected: buyOrder1 should be closed along with buyOrder2 and sellOrder2 to be opened.

this is the problem,

after reaching even crossing the price more than 10-20 points more than set price(13040) no orders opened, but tp closes the first order correctly

Do you know how to use the debugger?
 
ridwan hoque #: what expected: buyOrder1 should be closed along with buyOrder2

The second order will not close unless its TP is the same.

 
William Roeder #:

The second order will not close unless its TP is the same.

what expected: buyOrder1 should be closed along with buyOrder2 and sellOrder2 to be opened

explain:

1. buyOrder1 should be closed 

2.  buyOrder2 and sellOrder2 to be opened

Reason: