I'v created this function that will allow the EA to place another order when a current buy order exceeds 50 pips. The function works on testing but problem is it places the order too early for example when the first order has moved only 30 pips. What is the problem?
Thank
s.
You need to first make sure that you're working with the most recently opened order, and you can do that by looping through the orders and finding the one with the highest open time (aka most recently placed) and the selecting the order by its ticket number. Then the logic should be Bid - open price > 500*Point
bool NTAB(const int points) { int recent_ticket = -1; datetime recent_open_time = 0; for(int i=OrdersTotal()-1;i>=0;i--) { if( OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == _Symbol && OrderMagicNumber()== MagicNumber && OrderType() == OP_BUY && OrderOpenTime() > recent_open_time ) { recent_open_time = OrderOpenTime(); recent_ticket = OrderTicket(); } } if(OrderSelect(recent_ticket,SELECT_BY_TICKET)) return (Bid-OrderOpenPrice() >= (double)points*_Point); return false; }
You need to first make sure that you're working with the most recently opened order, and you can do that by looping through the orders and finding the one with the highest open time (aka most recently placed) and the selecting the order by its ticket number. Then the logic should be Bid - open price > 500*Point
Sorry, code giving errors, could you help refine it. Thanks.
Sorry, code giving errors, could you help refine it. Thanks.
No errors on my end.
No errors on my end.
thanks it works..

- 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'v created this function that will allow the EA to place another order when a current buy order exceeds 50 pips. The function works on testing but problem is it places the order too early for example when the first order has moved only 30 pips. What is the problem?
Thank
s.