You seem to be placing a market order not a true limit order. This operates as "buy at market price" with a maximum deviation or slippage tolerance rather than a hard price limit. This is why it appears (but not actually) you're getting the upper limit plus spread, but it's really just a market order with 5 pips allowed for spread.
To do a hard price limit you'd add price validation.
// Place a BUY LIMIT order instead OrderSend(_Symbol, OP_BUYLIMIT, volume, UpperLimit + 5, 3, 0, 0); // Add Price Validation Before Market Orders: mql4RefreshRates(); if (Ask <= UpperLimit + 5) { OrderSend(_Symbol, OP_BUY, volume, Ask, 3, 0, 0); } // Implement Strict Slippage Control: mql4double maxPrice = UpperLimit + 5; RefreshRates(); if (Ask <= maxPrice) { int slippage = (int)((maxPrice - Ask) / Point); OrderSend(_Symbol, OP_BUY, volume, Ask, slippage, 0, 0); }
Note that this would be for MetaTrader 4. You left out like the most important bit of information known to man when asking this sort of thing: what version of MetaTrader you're using. MT5 would be different.
You seem to be placing a market order not a true limit order. This operates as "buy at market price" with a maximum deviation or slippage tolerance rather than a hard price limit. This is why it appears (but not actually) you're getting the upper limit plus spread, but it's really just a market order with 5 pips allowed for spread.
To do a hard price limit you'd add price validation.
Note that this would be for MetaTrader 4. You left out like the most important bit of information known to man when asking this sort of thing: what version of MetaTrader you're using. MT5 would be different.

- 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 have a problem with algo trading. Specifically with this command: