For the error description, I use
#include <stdlib.mqh>
void CloseLongTicket() { for(int i=OrdersTotal()-1;i>=0;i--) if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true) { if(OrderType() == OP_BUY) { bool order = OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed); if (order == false) Alert("Close Long Error = ",ErrorDescription(GetLastError())); } } return; }
You need the {} as highlighted
thanks,
and is return; necessary ? compile with and without return;
i ask this because i get confused whit this code ! it gives me error too.
int BuyPosIndex() { for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true) { if(OrderType() == OP_BUY) return(i); } } return(i); }
return is necessary except for a void function.
int BuyPosIndex() { int i; for(i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderType()==OP_BUY) return(i); } } return(i); }
You need to declare int i before the loop or it is only local to the loop
Otherwise, you could just return(-1) for the final return
thank you very much.
This does nothing | use #include <stdlib.mqh> |
---|---|
#import "stdlib.ex4" #import | #import "stdlib.ex4" string ErrorDescription(int error_code); int RGB(int red_value,int green_value,int blue_value); bool CompareDoubles(double number1,double number2); string DoubleToStrMorePrecision(double number,int precision); string IntegerToHexString(int integer_number); |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I get 2 errors on this function
which is :
1.'order' - undeclared identifier
2.'ErrorDescription' - function not defined
can anybody explain what are these errors and how can I fix them ? and is return; necessary or not ?