arsouille:
If you want to count them all and have the count stored in Compteur you will need to remove the break; otherwise when the first one is found the break will . . . . " terminates the execution of the nearest nested outward switch, while, or for operator. " and your for loop will end.Hello,
Can you tell me your opinion on this piece of code please.
Its goal is to count the total number of active orders (op_buy and op_sell only, no pending) in progress on several EAs.
You have additional sets of ( ) that you don't need, but they won't hurt.
arsouille:
Hello,
Can you tell me your opinion on this piece of code please.
Also you could think about to have the code block in a function and passing the magic numbers within an array to it. You could fill the array with external values (magic numbers) and you would not need to change the code block(s) if the number of controled magic numbers do change.
Thank you,
RaptorUK, you do not count your answers, and our ignorance does not tire, a big thank you to you
Your code | for(Position_Index = Total_Orders - 1; Position_Index >= 0 ; Position_Index --) { if ( ! OrderSelect(Position_Index, SELECT_BY_POS, MODE_TRADES)) continue; if ( ((OrderType() == OP_BUY) || (OrderType() == OP_SELL)) && ((OrderMagicNumber()==Magic_Number) || (OrderMagicNumber()==Other_EA_Magic_Num...) ) { Compteur = Compteur + 1; break; } } |
Easier to Read | for(Position_Index = Total_Orders - 1; Position_Index >= 0 ; Position_Index --) if( OrderSelect(Position_Index, SELECT_BY_POS, MODE_TRADES) &&( OrderType() == OP_BUY || (OrderType() == OP_SELL // Or use OrderType() <= OP_SELL ) &&( OrderMagicNumber()==Magic_Number || (OrderMagicNumber()==Other_EA_Magic_Number_1 || (OrderMagicNumber()==Other_EA_Magic_Number_2 ) ){ Compteur = Compteur + 1; } // for |
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
Hello,
Can you tell me your opinion on this piece of code please.
Its goal is to count the total number of active orders (op_buy and op_sell only, no pending) in progress on several EAs.
Thanks, Emmanuel.