OrderSend problem with Bid price for OP_BUY and large slippage

 

I have a simple code, which I know isn't technically correct, but still I would like to know why exactly this happens...


Below i've used the Bid price. Basically the error is that it doesn't open Long positions, probably because it tries to get it at the wrong price (Should use Ask instead)

But! As slippage i've used 1000 points, which is 100 pips. This should theoretically work in even extreme market conditions, but says that the price is invalid.


If the slippage is so big, what's the difference between using the Bid and Ask prices?

(This code has been tested on a demo. Only opens short trades, i get an error 129 when opening Long)




   //signal is a double value that indicates buy or sell conditions. If positive you should buy, if negative you should sell.

   //There's an IF outside of this function that makes sure it cannot be called when Signal==0.0. 
   //This function is only called when there is a buy or sell signal.
   int OP = -1;
   if ( Signal > 0.0 ) OP = OP_BUY;
   if ( Signal < 0.0 ) OP = OP_SELL;
   lots = 0.01;


   int ticket = OrderSend( Symbol(), OP, lots, Bid, 1000, 0.0, 0.0, "Comment", 0, Green );
   if ( ticket == -1 )
      Print("OrderSend failed with error #",GetLastError());
 
Papler wrote >>

I have a simple code, which I know isn't technically correct, but still I would like to know why exactly this happens...

Below i've used the Bid price. Basically the error is that it doesn't open Long positions, probably because it tries to get it at the wrong price (Should use Ask instead)

But! As slippage i've used 1000 points, which is 100 pips. This should theoretically work in even extreme market conditions, but says that the price is invalid.

If the slippage is so big, what's the difference between using the Bid and Ask prices?

(This code has been tested on a demo. Only opens short trades, i get an error 129 when opening Long)


Error 129 means: Invalid Price

You are tryiing to open the trade at the wrong price. Even it the diffirence is 1 point. It is not about the slippage but about the correct entry price.

Change your code so it uses Ask when you are buying and Bid when you are selling. If you don't the problem will not go away.

whocares

 

Hmm is it perhaps that the server has a list of all history valid prices, and it only accepts if this price was valid sometime in the past?


Theoretically it should be possible to OP_BUY and set price at 0.000 and slippage to 100,000 and that would work :)


I know setting it to Ask when buying is how it should work, but I'm interested into why, because I really want and need to understand this system as much as possible.

 
Papler wrote >>

Hmm is it perhaps that the server has a list of all history valid prices, and it only accepts if this price was valid sometime in the past?

Theoretically it should be possible to OP_BUY and set price at 0.000 and slippage to 100,000 and that would work :)

I know setting it to Ask when buying is how it should work, but I'm interested into why, because I really want and need to understand this system as much as possible.

If you don't set it to Ask when you want to uy, your order will not be filled. Those are the rules. You can not negotiate the price with your broker, If you don't like find another place to spend your money. I don't want to sound rude but it is what it is.

Read this article about placing orders. https://book.mql4.com/build/trading

whocares

 

I think Papler's question is really about how it works.

As I understand it, the Bid and Ask pre-defined variables that hold double values. I think the point of Papler's question is: When they are used as parameters in an OrderSend() function how does the trade server know the name of the variable? Surely it just receives the value? And if the value is inside the slippage, why is ti a problem?

My attempt at an answer is:

I think the terminal checks order functions before they are sent to the trader server and I suspect the error 129 comes from the terminal. The variables Bid and Ask hold the price values that the terminal knows to be the latest valid prices so it won't accept values different from those. Hence the need for Bid in Sell orders and Ask in Buy orders.

The purpose of slippage is to account for the market moving between the time the terminal accepted the order for sending and the market server actually processing it.

Others have a better knowledge of this than me, so perhaps they can confirm or clarify.

Cheers

Jellybean

 
Jellybean wrote >>

I think Papler's question is really about how it works.

As I understand it, the Bid and Ask pre-defined variables that hold double values. I think the point of Papler's question is: When they are used as parameters in an OrderSend() function how does the trade server know the name of the variable? Surely it just receives the value? And if the value is inside the slippage, why is ti a problem?

My attempt at an answer is:

I think the terminal checks order functions before they are sent to the trader server and I suspect the error 129 comes from the terminal. The variables Bid and Ask hold the price values that the terminal knows to be the latest valid prices so it won't accept values different from those. Hence the need for Bid in Sell orders and Ask in Buy orders.

The purpose of slippage is to account for the market moving between the time the terminal accepted the order for sending and the market server actually processing it.

Others have a better knowledge of this than me, so perhaps they can confirm or clarify.

Cheers

Jellybean

Jellybean is correct. It is the terminal that will not pass the order to the server because the order is not corretly defined (Ask instead of Bid). It is the terminal that generates the error. Slippage also correct. It is as Jellybean says to allow for changes in price after the terminal passed the order to the server.

Sorry if I did not make myself clear. Good Catch Jellybean

 

Aha, I figure it could also be a safeguard against any mishaps that could occur.. terminal checks the data before it gets sent to the server, the slippage doesn't actually play a role here, slippage is (i figure) only used on the server.


I really want to write good code, and when shuffling around possibly millions, it's not a bad idea to know all how it works.


Thank you for this, that's the explanation I needed :)

 

From the Book.

The price is first checked at the terminal, that's the 129 you get with the wrong price.

Once it's sent to the broker, then slippage comes into play.

 

hello......you cant buy at BID.....only ASK !!!

Reason: