Hi guy. can someone tell me why this is happening?
As in the picture, the system buy at incorrect price. The candle not even reach that high. How come this happen? It also happen when closing order as well. It close at very weird price. Here is portion of the code i believe to be the source but have no idea why.
if(close >= 10)
if(Close <= 5)
//===============================Buy order code.
int ticket = OrderSend(Symbol(), OP_BUY, vol, Ask, Slippage, 0,0, "",magic,0,clrNONE);
Print("OrderSend failed when try to BUY with error #",GetLastError());
Print("OrderSend placed successfully");
//================================Close order code
TotalNumberOfOrders = OrdersTotal();
// Close all buy open order
for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)
if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;
if( OrderMagicNumber() == magic
&& OrderSymbol() == Symbol()
&& OrderType() == OP_BUY)
if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage ) )
Print("Order Close failed when try to close buy order, order number: ", OrderTicket(), " Error: ", GetLastError() );
int ticket = OrderSend(Symbol(), OP_BUY, vol, Ask, Slippage, 0,0, "",magic,0,clrNONE)
That's how MT4 Bid chart works. It shows Bid & your market Buy trade entered on Ask. A better way will be to turn on Ask Line in your chart from menu "Tools > Options > Charts" & click "Show ask line".
I don't worry how the chart display. The thing concern me is that the order was created at incorrect price which lead to money loss.
In this case, my EA send an order when the candle end its time ==> which I think the price for the buy order should be around 1316.60 not at 1317.10. That's 50 pips different.Am i misunderstood something?
Yes, you don't notice that gold, silver have a very wide spread? Low spreads usually GBPUSD and EURUSD.
If you want to play gold/silver, you need to have big starting money too.
Open a new order window on your chart and you will see the difference between Ask and Bid.
50 cent spread for Gold is quite normal. Personally I equate that to 5 pips, not 50.
Think if Gold was priced in 1/1000 of an ounce, it would be 1.31660/1.31710, not so different than EURUSD
If EURUSD was priced at 1.31660/1.31710 would you call that a 50 pip or 5 pip spread?
So the spread is not because of the ea but rather the market then. So is there someway to limit the spread?
Personally, they way I count pip is: for gold 1 pip = 1cent = 0.01. For thing like gpbusd, 1 pip = 0.0001
You are free to count pips any way that you like, but, if you use 0.01 a 50 pip spread on Gold sounds much larger than it actually is
As far as I am aware, with most brokers for 1 lot
Gold - if 1 pip = 0.01, pip value is $1
Gold - if 1 pip = 0.1, pip value is $10
GBPUSD - if 1 pip = 0.0001, pip value is $10
That is why I prefer to use 0.1 for Gold, so that pip value for 1 lot is similar to other symbols