I would like to open an order at the price of the close of the previous candle, is it possible to do that in some way?
When I try to do it, mt4 gives me error 138 which means that "the broker replied with a “Requote” signal to your expert advisor’s OrderSend() function. That means that the price used in the order is outdated compared to the current market price."
- Of course it's possible - check for a new bar and open.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum - Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
// Compute the open, takeprofit and stoploss values for the order double openPriceBuy = NormalizeDouble(Ask, Digits); double stopLossBuy = NormalizeDouble(minCandlestick-50*_Point, Digits); double takeProfitBuy = NormalizeDouble(openPriceBuy + (openPriceBuy-stopLossBuy)*3, Digits); // Compute the lot double lotAmountBuy = NormalizeDouble((5000*0.01)/(NormalizeDouble(10000*(openPriceBuy-stopLossBuy),1)*0.66),0); int ticket = OrderSend(Symbol(), OP_BUY, lotAmountBuy*0.1 ,openPriceBuy, 2, stopLossBuy, takeProfitBuy, "Order buy", magicNumber, 0, Green);
This is the piece of the code. If I put:
Close[1]
Instead of Ask in the openPriceBuy, the EA gives me error138.
This is the piece of the code. If I put:
Close[1]
Instead of Ask in the openPriceBuy, the EA gives me error138.
You buy at Ask, Close[1] is the closing Bid price.
Close[1] is the previous Bid price. Open[0] is the current Bid price (assuming no missed ticks,) at the start of the bar. Don't use either.
Either the Bid and the Open give me error number 138. Why is that?
I replaced instead of Ask in the openPriceBuy
Either the Bid and the Open give me error number 138. Why is that?
I replaced instead of Ask in the openPriceBuy
Both of the 2 posts previous to yours have answered that question.
When the new bar opens it should be the same price as the close of the previous bar, is there a particular reason behind your idea? If maybe you mean that once the current price has moved then only if it returns to the close price of the previous bar to open a trade, this can just be done using an if statement. Either way I suggest an if statement
Either the Ask or Bid will be different, if not there will not be the new tick to open the new bar.
No, it should not. You get a new candle when something changes. The two will usually be different (one tick.)
The problem is the one listed in the photo below. If I put the Bid instead of Ask It gives me Error138
- 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 would like to open an order at the price of the close of the previous candle, is it possible to do that in some way?
When I try to do it, mt4 gives me error 138 which means that "the broker replied with a “Requote” signal to your expert advisor’s OrderSend() function. That means that the price used in the order is outdated compared to the current market price."