-
Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
Of course, it does. You find the second order and save the price, you continue looping and find the first order and save that price. Why does this surprise you?
-
Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
Of course, it does. You find the second order and save the price, you continue looping and find the first order and save that price. Why does this surprise you?
if(OrderComment()==CountOrdersBuy())
{
PriceBuy=OrderOpenPrice();
}
- You selected an order and read the comment.
- Then you selected all orders and returned the count.
- The OrderOpenPrice is now position zero, any symbol, any type.
- You selected an order and read the comment.
- Then you selected all orders and returned the count.
- The OrderOpenPrice is now position zero, any symbol, any type.
Fixed! Thanks!
double LastPriceBuy() { double PriceBuy=0; for(int g=OrdersTotal()-1; g>=0; g--) { if(OrderSelect(g,SELECT_BY_POS,MODE_TRADES)) PriceBuy=OrderOpenPrice(); if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderComment()==CountOrdersBuy()) return PriceBuy; } return 0; }
But you still have an OrderSelect loop inside an OrderSelect loop; a potential problem (e.g. move the assignment next to the return, and you've broken it), and is n² slower to execute. Eliminate it and simplify your code.
int nBuy=CountOrdersBuy(); for(int g=OrdersTotal()-1; g>=0; g--) if( OrderSelect(g,SELECT_BY_POS) && OrderType() == OP_BUY && OrderComment()== nBuy && OrderSymbol() == _Symbol ){ return OrderOpenPrice(); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I have an open order counter, which works, and I want to know the open price for the last opened order... so I made something like this
So, "LastPriceBuy()" only gives correct number when I open the first order. On the second one, still shows first order price,
But if I make a new order with the wrong number in comment, it shows "0" so, it does check on "if(OrderComment()==CountOrdersBuy())".
Any idea? Thanks!