since j is not i
Hi Marco
Sorry didnt understand your reply.
In my code, you can see that I assign OrderTicket() to both a variable and an element in the array.
When I try to do the Print statement in the same loop, only the variable seems to hold the value,
while the array element prints as '0'.
The value of 'j' is not significant here as I am assigning and printing with the same j value in the loop.
Anytime you have a multitude of arrays with individual types all pointed at the same data/index should be a huge red flag that you're using the wrong datatype. In this case you really need to group your data into an array of structs or objects that represent your collection. Also, storing the ticket number and then looping the pool kind of defeats the purpose of having the ticket saved. Just so I don't leave you hanging on that here's a snippet of what I mean...
Here is an example of how you could group your data and encapsulate your ticket logic.
#include <Arrays\List.mqh> #define foreach_ticket(I,L) for(Ticket*I = L.GetFirstNode(); CheckPointer(I); I=I.Next()) //+------------------------------------------------------------------+ class Ticket : public CObject { public: int ticket; double high_profit; bool select(){ return OrderSelect(SELECT_BY_TICKET,ticket); } bool is_open(){ if(this.select() && OrderCloseTime()==0) return true; return false; } bool refresh(){ if(this.is_open()){ if(OrderProfit() > this.high_profit) this.high_profit = OrderProfit(); return true; } return false; } }; CList tickets; //+------------------------------------------------------------------+
... and here's an example of how you could cleanly call it in your code.
void OnStart() { foreach_ticket(ticket, tickets){ if(ticket.refresh()){ OrderPrint(); //ticket is selected so this will print correctly Print("Hightest profit = ", ticket.high_profit); } } }
Hi Marco
Sorry didnt understand your reply.
In my code, you can see that I assign OrderTicket() to both a variable and an element in the array.
When I try to do the Print statement in the same loop, only the variable seems to hold the value,
while the array element prints as '0'.
The value of 'j' is not significant here as I am assigning and printing with the same j value in the loop.
You can print it and it can look correctly, but on the next pass in loop i you overwrite the value of [j] with the value of the last order because you are still on j.
try printing in the j loop in stead of the i loop.
Hi Folks
I am writing a program to keep a record of the Order Ticket numbers in an array.
There is an issue that I cant seem to resolve.
The code is attached. When I print out the orderticket directly from the the OrderTicket() function
or from the order_ticket variable, it is correct. However, when I print out the value stored in the
array orders{j], it always shows '0'.
Both order_ticket and orders[] are declared as ulong.
Thanks in advance for the help!
for(j=0;j<orders_count;j++) { for(i=0;i<OrdersTotal();i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=Symbol()) continue; if(OrderMagicNumber()!=magicnumber[j]) continue; prev_big_order_profit = OrderProfit(); big_order_type = OrderType(); running_profit += prev_big_order_profit; order_ticket = OrderTicket(); //----- int n = ArrayBsearch(orders, order_ticket); if( orders[n] != order_ticket ) { n = ArraySize(orders); if( ArrayResize(orders, n+1) == n+1 ) orders[n] = order_ticket; } //----- Print("OrderTicket: ", OrderTicket()); Print("order_ticket: ", order_ticket); Print("Orders[" + n + "]: ", orders[n]); Print("Prev Big Order Profit: ", prev_big_order_profit); Print("Running Profit: ", running_profit); } }
Something like this. Did not check, but it seems logical.
- 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 Folks
I am writing a program to keep a record of the Order Ticket numbers in an array.
There is an issue that I cant seem to resolve.
The code is attached. When I print out the orderticket directly from the the OrderTicket() function
or from the order_ticket variable, it is correct. However, when I print out the value stored in the
array orders{j], it always shows '0'.
Both order_ticket and orders[] are declared as ulong.
Thanks in advance for the help!