Download MetaTrader 5
To add comments, please log in or register
Do you have questions to the application's developer - ask them in Comments section
Keith Watford
Moderator
8873
Keith Watford 2014.04.01 23:51  
angevoyageur:

There is no change, it has always been so. Slippage doesn't mean that you can set an other price than bid/ask. See documentation of OrderSend.

At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price.

Slippage means that if the price (bid/ask) is no more available when your order is executed, then you accept a slippage of x points.


Yes a market order will only be opened at the current Bid or Ask. But that is not the same as saying that the requested price MUST be Bid or Ask.

The documentation goes on to say

If the requested price is out of date, but present in the thread, the order will be opened at the current price and only if the current price lies within the range of price+-slippage.

In my code, the entry price is the close price of a sell order that has just been closed.

double new_order_entry = OrderClosePrice();

Now, as sell orders have to be closed at Ask, then obviously, new_order_entry must be a valid price. Although, to be honest, I don't really know what "present in the thread" means. Does it mean that sometime during the current call to void OnTick(), That specific value for Ask must have been retrieved?

The order was closed at 2014.04.01 13:58:36 and the first OrderSend was rejected at 2014.04.01 13:58:36:296

So less than 0.3 of a second between obtaining the "Ask" from the closed order and sending the order.

Yes, the "Ask" price was out of date and differed by 8 Points, but well within the slippage range of 30 Points.

This seems totally ridiculous to me, but if that is how it is to be, I will have to adjust my code.

I didn't want to simply use Ask, as I wanted to restrict entry price within 30 points of the sell order's close price

I think that this will do the trick

   
               RefreshRates();
               if(Ask>new_order_entry)
                  {
                  double diff=Ask-new_order_entry;
                  newSlippage=Slippage-(int)MathRound(diff/Point);
                  }
               if(newSlippage>=0)
                  {
                  ticket=OrderSend(Symbol(),OP_BUY,lotsize,Ask,newSlippage,Ask-stoploss,
                         Ask+takeprofit,"reverse "+(string)LastTicket,MagicNumber,0,clrNONE);
                  if(ticket==-1)
                     {
                     Print("Error opening Buy @ ",Ask,"-Current Ask is ",Ask,". Slippage=",newSlippage,ErrorDescription(GetLastError()));
                     }
whroeder1
13982
whroeder1 2014.04.02 00:00  

Don't print just the ErrorDescription, print the number for us coders.

Print ALL your values to OrderSend. 130 is not just slippage (which you don't adjust for 4/5 digit brokers) and Bid AND Ask as entry is relative to one but the SL is relative to the other.

Keith Watford
Moderator
8873
Keith Watford 2014.04.02 00:20  
qjol:

there are a lot of brokers calling themselves ECN and ignoring slippage

try to change a server


I think that you may have misunderstood, I didn't pick a good title for this topic.

It is about my OrderSends being rejected despite the current Ask being within the bounds of my entry price +/- slippage.

This just seems ridiculous to me. They may as well not bother with an entry price parameter for market orders and simply have it default to Bid or Ask.

Keith Watford
Moderator
8873
Keith Watford 2014.04.02 01:22  
WHRoeder:

Don't print just the ErrorDescription, print the number for us coders.

We have different opinions, which is fair enough.

It annoys me when people post about "I am getting error 12345" without giving the description because I often have to look it up.

The error number in this case is 129 - Invalid price.

WHRoeder:


Print ALL your values to OrderSend. 130 is not just slippage (which you don't adjust for 4/5 digit brokers) and Bid AND Ask as entry is relative to one but the SL is relative to the other.

For the purpose of this thread, I have printed just the necessary values related to the issue which is that my order entry price is invalid unless it is EXACTLY the same as the current/latest Ask. I Print the Order price and the slippage so that people reading this thread can see that the latest Ask is within the confines of the Order price +/- slippage.

The error is not 130

Yes, I do adjust the slippage for 4/5 digit brokers, do you think that my slippage was intended to be 30 pips

I have no idea what this means "and Bid AND Ask as entry is relative to one but the SL is relative to the other."

Ian Venner
2583
Ian Venner 2014.04.02 03:26  

If the requested price is out of date, but present in the thread, the order will be opened at the current price and only if the current price lies within the range of price+-slippage.

I would take that to mean, the price used must be the latest price the EA's thread has. This will be the price as it was when the EA's start function was triggered by the arrival of the tick or the price the last time the EA called RefreshRates(). If ticks are arriving close together that price might be out of date by the time the EA finishes calculating but the terminal will still allow it to be sent to the broker as long as slippage covers the difference. Of course it might still be rejected by the broker if it is even more out of date by the time it is received.

I would not take it to mean the EA can send any price it wants as long as the slippage covers the difference. It has always had to be the prices the EA has in the Bid and Ask.

/ /12
To add comments, please log in or register