MQL4 How can I return the current profit on an open order based on the order comment

MQL4 How can I return the current profit on an open order based on the order comment

Manage alerts

Loading saved threads...

Dr.Prog · External communityPost link
External question — Stack Overflow Stack Exchange Author: Dr.Prog Original post: https://stackoverflow.com/questions/75230574 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm trying to return the current profit on an open order based on the order comment. Right now, my code below but is getting the profit of all open orders as opposed to just the order with a specific comment. So, what I want to return is the profit for the order that the order comment is "Testing". double Profit=0; for(int i=0; i<OrdersTotal(); i++ ) { if(OrderSelect(i, SELECT_BY_POS)==true) { if (OrderComment()=="Testing") Profit+= (OrderProfit()+OrderSwap()+OrderCommission()); }
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange Author: PaulB Original post: https://stackoverflow.com/a/75248906 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You should not use OrderComment() for isolating/identifying trades, the broker can overwrite/alter/delete the comments at any time for any reason. You should also count orders down, not up. If an order is deleted or created mid check, your function will exit with an error or produce unexpected results. All the above given, the following works when I've tested it. double Profit=0; for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS)) { if(OrderComment()=="Testing") Profit+= (OrderProfit()-OrderSwap()-OrderCommission()); } } Comment(Profit);
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Dr.Prog Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/75230574 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm trying to return the current profit on an open order based on the order comment. Right now, my code below but is getting the profit of all open orders as opposed to just the order with a specific comment. So, what I want to return is the profit for the order that the order comment is "Testing". double Profit=0; for(int i=0; i<OrdersTotal(); i++ ) { if(OrderSelect(i, SELECT_BY_POS)==true) { if (OrderComment()=="Testing") Profit+= (OrderProfit()+OrderSwap()+OrderCommission()); }

Cancel quote

Checking account access…