Refresh rates just before you send orders to make sure your order has the latest prices.
At present you are refreshing only after you have sent the order and it has failed.
As for the second part just use Ask and Bid
Refresh rates just before you send orders to make sure your order has the latest prices.
At present you are refreshing only after you have sent the order and it has failed.
As for the second part just use Ask and Bid
Ok great thanks
if(direction==1) RefreshRates() if(OrderSend(Symbol(),OP_BUY,GetLongContracts(),Ask,SLIPPAGE,GetStopLossLongPrice(),0,NULL,MagicNumber,0,Green) < 0) { Print("Order Send failed, error # ", GetLastError()); }
should it look like this ?
Better placement of Refreshrates but you need to use the OrderSend function correctly it returns an integer not a bool
- docs.mql4.com
Better placement of Refreshrates but you need to use the OrderSend function correctly it returns an integer not a bool
I Moved RefreshRates to where I said above and now it enters long and short ?
void OrderEntry(int direction) { if(direction==1) RefreshRates(); if(OrderSend(Symbol(),OP_BUY,GetLongContracts(),Ask,SLIPPAGE,GetStopLossLongPrice(),0,NULL,MagicNumber,0,Green) < 0) { Print("Order Send failed, error # ", GetLastError()); } if(direction==0) RefreshRates(); if(OrderSend(Symbol(),OP_SELL,(GetShortContracts()),Bid,SLIPPAGE,GetStopLossShortPrice(),0,NULL,MagicNumber,0,Green) < 0) { Print("Order Send failed, error # ", GetLastError()); } }
you need to add parentheses { } for the if statements.. or place RefreshRates() just once before the if statements
void OrderEntry(int direction) { if(direction==1) { RefreshRates(); if(OrderSend(Symbol(),OP_BUY,GetLongContracts(),Ask,SLIPPAGE,GetStopLossLongPrice(),0,NULL,MagicNumber,0,Green) < 0) { Print("Order Send failed, error # ", GetLastError()); } } if(direction==0) { RefreshRates(); if(OrderSend(Symbol(),OP_SELL,(GetShortContracts()),Bid,SLIPPAGE,GetStopLossShortPrice(),0,NULL,MagicNumber,0,Green) < 0) { Print("Order Send failed, error # ", GetLastError()); } } }
you need to add parentheses { } for the if statements.. or place RefreshRates() just once before the if statements
Hi this has helped a lot, I now get a lot less error 138s, although on live forward testing I still get a few of these errors along with error 133. I have done some research and it could be a drop in internet connection, although I wouldn't have thought that would have been the problem. what else could be causing these errors ?
Thanks
- You are double posting. You already have a topic open about this error. Why did you start a new thread about the same thing?
- There are many, many threads on the forum about error 138, Did you read them and learn from them?
- Did you ever bother to read up on what error 138 means? It means there is a "Requote" when using "Instant Execution" method for example.
- How do you solve it?
- The quickest and simplest method is to use an Account or Broker, that uses "Market Execution" instead of "Instant Execution" and your orders will always be filled at the current market price irrespective of the slippage.
- The more difficult method is to use the most recent market prices and submit the market order as quickly as possible with a very wide deviation/slippage parameter (research this in the OrderSend documentation), and when that gives a requote error, you quickly resubmit a new order with the latest refreshed market price. And you repeat this process until it is accepted or you stop when the market prices have drifted to far away from what you originally wanted.
Hi this has helped a lot, I now get a lot less error 138s, although on live forward testing I still get a few of these errors along with error 133. I have done some research and it could be a drop in internet connection, although I wouldn't have thought that would have been the problem. what else could be causing these errors ?
Thanks
Or maybe you can add option to retry OrderSend() ... add this error to list and then allow to retry couple of times
Retrying the OrderSend() with the same parameters is a waste of time and effort for a Requote. Obviously if it is a requote, then the market prices have changed and drifted too far away from the maximum deviation specified by the user. The parameters for the order are no longer valid and have to be recalculated and the conditions reevaluated to see if they still make sense according to the strategy rules or not, and only then resubmit the order under the new parameters and conditions.
Retrying the OrderSend() with the same parameters is a waste of time and effort for a Requote. Obviously if it is a requote, then the market prices have changed and drifted too far away from the maximum deviation specified by the user. The parameters for the order are no longer valid and have to be recalculated and the conditions reevaluated to see if they still make sense according to the strategy rules or not, and only then resubmit the order under the new parameters and conditions.
You are obviously right.
What I was saying is to retry OrderSend with the latest prices. Also maybe include IsTradeContextBusy() maybe..it also help to speedup filling requested order.
Because, as he is saying, he is only getting this error sometimes, not every time.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am getting order send error 138, I have done some research and i need to add the refresh rates functions, I have done this above but I still get errors ?
Did I put it in the wrong place ?
And when i want to use ask and bid prices should I do this
or this
Thanks for any help