Hi,
I am trying to make a function that determines if any open order is losing more money than a cutoff point (say, $-1000).
The function is then supposed to store the OrderTicket() and the OrderProfit() in two separate arrays, and exit with return (1) to signify that the cutoff point has been reached.
Before it stores the values in those arrays, it should check the OrderTicket() array to see whether this order is already filed.
If the OrderTicket number is already stored in the array, it is supposed to determine if the order has lost an ADDITIONAL $1000, and if so: replace value in the OrderProfit() array with a fresh value, and exit with return(1) to signify that a NEW cutoff point has been reached. If the order has not lost an additional $1000 (called Cutoff) then it should return(0) to signify that no order has lost an additional $1000.
I think I pretty much have it working (not sure??), but for some reason the array gets filled with a lot of '0' values along with the legitimate values. The output of the array is as follows:
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I am trying to make a function that determines if any open order is losing more money than a cutoff point (say, $-1000).
The function is then supposed to store the OrderTicket() and the OrderProfit() in two separate arrays, and exit with return (1) to signify that the cutoff point has been reached.
Before it stores the values in those arrays, it should check the OrderTicket() array to see whether this order is already filed.
If the OrderTicket number is already stored in the array, it is supposed to determine if the order has lost an ADDITIONAL $1000, and if so: replace value in the OrderProfit() array with a fresh value, and exit with return(1) to signify that a NEW cutoff point has been reached. If the order has not lost an additional $1000 (called Cutoff) then it should return(0) to signify that no order has lost an additional $1000.
I think I pretty much have it working (not sure??), but for some reason the array gets filled with a lot of '0' values along with the legitimate values. The output of the array is as follows:
The following is my actual code:
int CheckForResume() { ResumeCheck = TimeLocal()+(PERIOD_M1*60)*5; } int arraycount1 =1; int arraycount2 =1; bool found = false; int k; for (int i = 0; i<OrdersTotal();i++) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL)) { if (OrderProfit()< Cutoff) { for (k=0; k<ArraySize(ResumeArrayTickets); k++) { if ((ResumeArrayTickets[k] == OrderTicket()) && ResumeArrayTickets[k] !=0) { found = true; if (ResumeArrayPrices[k] + Cutoff < OrderProfit()) { return (0); } else { Print ("ELSE"); arraycount1 = ArrayResize(ResumeArrayTickets,ArraySize(ResumeArrayTickets) + 1); arraycount2 = ArrayResize(ResumeArrayPrices,ArraySize(ResumeArrayPrices) + 1); ResumeArrayTickets[k] = OrderTicket(); ResumeArrayPrices[k] = OrderProfit(); return (1); } } } if (found == false) { arraycount1 = ArrayResize(ResumeArrayTickets,ArraySize(ResumeArrayTickets) + 1)' arraycount2 = ArrayResize(ResumeArrayPrices,ArraySize(ResumeArrayPrices) + 1); ResumeArrayTickets[k] = OrderTicket(); ResumeArrayPrices[k] = OrderProfit(); return (1); } } } return (0); } }