int start(){ ... } void OnTick(){ ... }
One or the other, not both. Start using the new Event Handling Functions.
Event Handling Functions - Functions - Language Basics - MQL4 ReferenceOrderPrint
Prints information about the selected order in the log.
void OrderPrint();
OrderPrint - Trade Functions - MQL4 Reference"Order Info: "+ OrderPrint()
What do you think string+void is?- You can't use OrderPrint to do anything but write to the log. For a file, you have to write it yourself.
Hello @whroeder1
Thanks for the help, I made some changes and it is "half working" now:
int start() { Alert("Watching Orders."); int a = OrdersTotal(); while (True) { OrderSelect(a,SELECT_BY_POS,MODE_TRADES); OrderPrint(); //Alert("OrderPrint is activated."); Print("Order comment: "+OrderComment()); } }
I have some questions:
1) By now, this is printing the same order a hundred times, how can I add the OrderTicket to a list? (So I can check before printing if it was printed before.)
2) I want to retrieve everything printed from OrderPrint() (Is easiest thant using all parameters like OrderComment, OrderTicket..), is it possible to pass it to FileWrite?
- How do you add a ticket to a list? You enlarge the list and put it there. learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
- Learn to code and you will know the answer.
int a = OrdersTotal(); while (True) { OrderSelect(a,SELECT_BY_POS,MODE_TRADES);
If there are N orders, their positions are [0..N-1] Your OrderSelect always fails. Check your return codes for errors and report them.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
@whroeder1 , thank your for your help!
Just giving a feedback for everyone who reaches this topic:
I've a made a few changes to the code, in the current version everytime that the Orders number change, it will be printed how much orders are open and the comment from the last open order.
If anyone (like me) want to print just when the order wasn't printed before, you need to create a if before the Print and check if ticket is in the array, if is not, you print the order. (I'm still searching how to check the array).
int start() { int TicketArray[]; int a = OrdersTotal(); Alert("Watching Orders."); while (True) if (a!= OrdersTotal()&&(a>0)){ a = OrdersTotal(); Print(OrdersTotal()); //You can see how much orders are open. OrderSelect(a-1,SELECT_BY_POS,MODE_TRADES); // Select the order int ticket = OrderTicket(); // Saves the ticket of the selected order Print("Order comment: "+OrderComment()); // Prints order comment //Adds ticket to the array ArrayResize(TicketArray, ArraySize(TicketArray)+1); TicketArray[ArraySize(TicketArray)-1] = ticket; } }
string OrderToString( void ) { static const string Types[] = {"buy", "sell", "buy limit", "sell limit", "buy stop", "sell stop", "balance"}; const int digits = (int)SymbolInfoInteger(OrderSymbol(), SYMBOL_DIGITS); return("#" + (string)OrderTicket() + " " + (string)OrderOpenTime() + " " + ((OrderType() < ArraySize(Types)) ? Types[OrderType()] : "unknown") + " " + DoubleToString(OrderLots(), 2) + " " + OrderSymbol() + " " + DoubleToString(OrderOpenPrice(), digits) + " " + DoubleToString(OrderStopLoss(), digits) + " " + DoubleToString(OrderTakeProfit(), digits) + " " + ((OrderCloseTime() > 0) ? ((string)OrderCloseTime() + " ") : "") + DoubleToString(OrderClosePrice(), digits) + " " + DoubleToString(OrderCommission(), 2) + " " + DoubleToString(OrderSwap(), 2) + " " + DoubleToString(OrderProfit(), 2) + " " + ((OrderComment() == "") ? "" : (OrderComment() + " ")) + (string)OrderMagicNumber() + (((OrderExpiration() > 0) ? (" expiration " + (string)OrderExpiration()) : ""))); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I'm trying to recover the last open order on Metatrader and write into a file.
I'm getting this error: Expression has no effect, expression of 'void' type is illegal.
Could someone give a me help here?
Thanks for your help!
CODE: