Please do not double post, I have deleted your other topic.
OrderSelect returns a bool, so you should only work with the selected order if it returns true.
if(OrderSelect() ) { //do something } else { //Print the error - GetLastError() }
.
Please do not double post, I have deleted your other topic.
OrderSelect returns a bool, so you should only work with the seleted order if it returns true.
.
If you don't understand the answer, you don't understand your own code.
So start to learn coding in C and MQL4 or pay someone to do it for you.
where i have to use this code can u please explain me in details i am new here and also new in making expert adviser
Anybody who wrote code like that would not need to ask for more explanation.
It would be a waste of time explaining in detail as you did not write that code and you would not understand.
If you want to learn coding start with something much simpler.
See where he gave you the logic.
=if(OrderSelect() ) {
//do something } else { //Print the error - GetLastError()
}
Your code just does
OrderSelect(blah blah blah);
You need to put it in an if statement so like your code
void closeallorders() { for(int i=0; i< OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(OrderType() == OP_BUY||OrderType() == OP_SELL) { int j=0; while(j!=5)// try 5 times to ensure excution { OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Pink); j++; }
becomes this (and you can't close an order 5 times so this checks the boolean whether it was closed or not.
void closeallorders() { for(int i=0; i< OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {if(OrderType() == OP_BUY||OrderType() == OP_SELL) { int j=0;bool closed = false;while(j!=5 && closed==false)// try 5 times to ensure excution { closed = OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Pink); j++; }}
}
}
if(OrderType() == OP_BUY||OrderType() == OP_SELL) { int j=0;bool closed = false;while(j!=5 && closed==false)// try 5 times to ensure excution { closed = OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Pink); j++; }
You can't usually close a Sell at Bid
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Pink)
will work no matter if it is a Buy or a Sell.
Also when re-trying, you should re-select the order to make sure that OrderClosePrice() is current, or RefreshRates() if closing at Bid or Ask.
- You must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
- and check OrderSelect. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- You must RefreshRates after sleep and between multiple server calls if you want to use the Predefined Variables (Bid/Ask) or OrderClosePrice() instead.
You can't usually close a Sell at Bid
will work no matter if it is a Buy or a Sell.
Also when re-trying, you should re-select the order to make sure that OrderClosePrice() is current, or RefreshRates() if closing at Bid or Ask.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use