Ordersend error 130

 
ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Ask - 100 * Point, Ask + 100 * Point, NULL);

I have been using the above code to send order (USD/JP) when the RSI is above 70, but I always get error 130.

It seems like I might be violating the Bid - Stoplevel >= 40, but I also have a line of code 

ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - 1000 * Point, Ask + 1000 * Point, NULL);

to buy when RSI is below 30, and this is actually working.

I cannot figure out why.

I'd appreciate it if someone can help me

Also, I have set the spread to be 10

 
griffcho16:

I have been using the above code to send order (USD/JP) when the RSI is above 70, but I always get error 130.

It seems like I might be violating the Bid - Stoplevel >= 40, but I also have a line of code 

to buy when RSI is below 30, and this is actually working.

I cannot figure out why.

I'd appreciate it if someone can help me

I don't see how your OP_BUY example won't work since you used 1000 * Point... have you tried 1000 * Point for OP_SELL?

(note also that you used 'Ask' for SL and TP for both OP_BUY and OP_SELL...)

 
Seng Joo Thio:

I don't see how your OP_BUY example won't work since you used 1000 * Point... have you tried 1000 * Point for OP_SELL?

(note also that you used 'Ask' for SL and TP for both OP_BUY and OP_SELL...)

Yes, I have used 1000, but it still didn't work

 
griffcho16:

Yes, I have used 1000, but it still didn't work

Because the SL for a SELL order must be ABOVE opening price, and TP BELOW.
 
griffcho16:

Yes, I have used 1000, but it still didn't work

Oh! Now I see it - for OP_SELL, you need to add for SL and minus for TP...

 
Alain Verleyen:
Because the SL for a SELL order must be ABOVE opening price, and TP BELOW.
Ohhh, Thank you so much
 
ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - 1000 * Point, Ask + 1000 * Point, NULL);
You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer. Don't you want the same/specified amount for either direction?
  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at 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.)
Reason: