Download MetaTrader 5

Incorrect order

To add comments, please log in or register
Interested in Signals activity? Come and track!
Minh
140
Minh 2014.05.05 19:30 

Hi guy. can someone tell me why this is happening?

Incorrect closed price

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[1] >= 10)
{
    buy();
}
if(Close[1] <= 5)
{
    closebuy();
}






//===============================Buy order code.
   int ticket = OrderSend(Symbol(), OP_BUY, vol, Ask, Slippage, 0,0, "",magic,0,clrNONE);
   if(ticket<0)
     {
      Print("OrderSend failed when try to BUY with error #",GetLastError());
      RefreshRates();
     }
   else
   {
      Print("OrderSend placed successfully");
   }

//================================Close order code

    int PositionIndex;
    int TotalNumberOfOrders;
    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() );
             RefreshRates();
             }
          }
       }
qjol
3243
qjol 2014.05.05 19:35  
you buy at ask and the chart draw the bid
Minh
140
Minh 2014.05.06 00:09  
int ticket = OrderSend(Symbol(), OP_BUY, vol, Ask, Slippage, 0,0, "",magic,0,clrNONE)
So what should I do to make it close at correct price? I notice not only the buy order but the sell order also.And apparently change from Ask=>Bid doesn't work.
Ian Venner
2584
Ian Venner 2014.05.06 03:55  
nguye235:
So what should I do to make it close at correct price? I notice not only the buy order but the sell order also.And apparently change from Ask=>Bid doesn't work.
Nothing much you can do about it other than try to get an account with tighter spreads, or write code to place the order if the price is lower than that.
BigFisherman
125
BigFisherman 2014.05.06 04:04  
nguye235:
So what should I do to make it close at correct price? I notice not only the buy order but the sell order also.And apparently change from Ask=>Bid doesn't work.



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".

Minh
140
Minh 2014.05.06 06:25  

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?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.06 06:52  

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.

Keith Watford
Moderator
9644
Keith Watford 2014.05.06 07:15  
nguye235:

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?


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?

Minh
140
Minh 2014.05.06 16:09  
deysmacro:

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.


So the spread is not because of the ea but rather the market then. So is there someway to limit the spread?

GumRai:


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?


Personally, they way I count pip is: for gold 1 pip = 1cent = 0.01. For thing like gpbusd, 1 pip = 0.0001

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.06 16:19  
Actually those spreads are set by the broker.
Keith Watford
Moderator
9644
Keith Watford 2014.05.06 21:56  
nguye235:

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

12
To add comments, please log in or register