double price = iClose(Symbol(), PERIOD_H1, 1); // // int ticket = OrderSend(Symbol(), OP_BUY, 1, price, 5, stoploss, takeprofit, "buy", 16384, 0, clrGreen);
price is unlikely to be a valid entry price for either a buy or a sell.
Buys are opened at the current Ask and Sells at the current Bid.
I am surprised that you only get this problem in the tester
Buy orders open at the Ask price, not the Bid price. The iClose function returns a Bid price.
The reason you are not getting an error on the live account is because the broker is probably using Market Execution which simply ignores your requested opening price and opens at the current market price. On other brokers that use Instant Execution, your code would give the same error.
Remember the following rules:
- Buy Order, opens at Ask, closes at Bid (spread is calculated when you open)
- Sell Order, opens at Bid, closes at Ask (spread is calculated when you close)
I've got OrderSend 138 only if I run it in tester, not in live demo. I've try to adjust slippage point to no avail. Anyone get any idea why this happen?
double price = iClose(Symbol(), PERIOD_H1, 1); if (up > down && up > sideway){ double stoploss = NormalizeDouble(price-piploss*Point, Digits); double takeprofit = NormalizeDouble(price+pipgain*Point, Digits); int ticket = OrderSend(Symbol(), OP_BUY, 1, Ask, 5, stoploss, takeprofit, "buy", 16384, 0, clrGreen); if (ticket<0){ Print("Order send error: ", GetLastError()); } else{ Print("Order success"); } } else if (down > up && down > sideway) { double stoploss = NormalizeDouble(price+piploss*Point, Digits); double takeprofit = NormalizeDouble(price-pipgain*Point, Digits); int ticket = OrderSend(Symbol(), OP_SELL, 1, Bid, 5, stoploss, takeprofit, "sell", 16384, 0, clrGreen); if (ticket<0){ Print("Order send error: ", GetLastError()); } else{ Print("Order success"); } } else { Print("sideway"); } }

- 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've got OrderSend 138 only if I run it in tester, not in live demo. I've try to adjust slippage point to no avail. Anyone get any idea why this happen?