OrderSelect() a silly question

 

Hi Guys i have a question:

lets say i want to loop through my orders inside a function and return a value if this condition is valid...

please have a look at this code

int test()
{
int tradecases;
tradecases = 0;
   


    for (int i= 0; i< OrdersTotal();i++) {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    
//  -- Single Order
       if ((OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) ||
           (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1))
         {
           tradecases = 0;
         }  



// --- Multiple open orders with different Magic

       if ((OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1  &&
            OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 2) ||
           (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 2 &&
            OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1))
         {
           tradecases = 1;
         } 

return (tradecases );
}

is the second case possible? i mean when i do the loop it stop at the first order or actually it continue through all the orders?

Thanks

 
break interupts the loop. without this command both cases check all the orders except that it is safer to countdown with i-- from OrdersTotal()-1
 

Thanks for the quick reply!

so looping like this is safer?

for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

do you mean bracket? {} to interrupt?

Ickyrus:
break interupts the loop. without this command both cases check all the orders except that it is safer to countdown with i-- from OrdersTotal()-1
 

I go to the search box in the top right hand corner of these web pages and I type in the word break and bingo there appears lots of information about the break command or operator (russian - english translation reasoning perhaps)

The documentation on break is https://docs.mql4.com/basis/operators/break

 
Ickyrus:

I go to the search box in the top right hand corner of these web pages and I type in the word break and bingo there appears lots of information about the break command or operator (russian - english translation reasoning perhaps)

The documentation on break is https://docs.mql4.com/basis/operators/break


Oh yeah i thought you were talking about the brackets...i dont need to break the loop i just want to know if OrderSelect() will loop and exit at the first condition met or actually it will loop through all the orders.. if you see in the code i ve posted, the second case to be true needs to have 2 orders of different types and from different magic numbers to return 1, i just want to know if this is the correct way to code it

 
Ickyrus:
break interupts the loop. without this command both cases check all the orders except that it is safer to countdown with i-- from OrdersTotal()-1

your second example wont do what you want it to. You only select ONE order at a time and you only check that ONE order if either of the conditions you are checking are true then tradecases will equal 1 but you wont know if both orders your are checking for are in your orders list or not. You will only know that it has either none of the conditions you are checking for or that you found at least ONE order that satisfied your condition, you won't know if both were satisfied.
 
Ickyrus:

your second example wont do what you want it to. You only select ONE order at a time and you only check that ONE order if either of the conditions you are checking are true then tradecases will equal 1 but you wont know if both orders your are checking for are in your orders list or not. You will only know that it has either none of the conditions you are checking for or that you found at least ONE order that satisfied your condition, you won't know if both were satisfied.

yeah thats what i thought......do you know how i can accomplish that?
 
yes - but you should have a go first clue flag variables.
 
AtApi:

yeah thats what i thought......do you know how i can accomplish that?

How about just checking each order individually and using a scoring system like this from Derk Wehler's synergy indi.

Just check for order type & magic numbers and assign a value to each,

Then check if (value total >= somenumber) tradecases = ?;

int MA_TrendSum = 0;
        
        // We are looking for the general trend here, so check 
        // whether lines are headed up or down, comparing this 
        // candle with the prev and the prev prev
        if (MA_Hi_0 > MA_Hi_1)  MA_TrendSum += 3;
        if (MA_Lo_0 > MA_Lo_1)  MA_TrendSum += 3;
        if (MA_Hi_0 > MA_Hi_2)  MA_TrendSum += 2;
        if (MA_Lo_0 > MA_Lo_2)  MA_TrendSum += 2;
        if (MA_Hi_1 > MA_Hi_2)  MA_TrendSum += 1;
        if (MA_Lo_1 > MA_Lo_2)  MA_TrendSum += 1;
                
        if (MA_Hi_0 < MA_Hi_1)  MA_TrendSum -= 3;
        if (MA_Lo_0 < MA_Lo_1)  MA_TrendSum -= 3;
        if (MA_Hi_0 < MA_Hi_2)  MA_TrendSum -= 2;
        if (MA_Lo_0 < MA_Lo_2)  MA_TrendSum -= 2;
        if (MA_Hi_1 < MA_Hi_2)  MA_TrendSum -= 1;
        if (MA_Lo_1 < MA_Lo_2)  MA_TrendSum -= 1;

        // If we have 6 out of 12, consider it to have a direction
        if (MA_TrendSum >= 6)
                return(OP_BUY);
        else if (MA_TrendSum <= -6)
                return(OP_SELL);
        else
                return(-1);
 

A computer program is like a recipee you follow each instruction step by step you learn more if you try following the instructions as if you were the computer. So try it out on paper see a variable name write its name down and next to the name the number thats in it. See a comparason check your current values and decide if the comparason is true or false, if its true you work on the line of code or the code block started with { and finishing the actions of the code block at } the word else means that if you did worked the true part then you skip the nexe line or code block. if the comparason was false you skip the next like or code block and move on to the next line.

It is doubtful that you ever did VB programming as you said in another post - of if you did, it would have been in the same way you are programming now.

There are only four basic elemets to programming

Input output assignment and the IF something THEN something ELSE something different. the ELSE part is optional.

all other statements are just variations on using these four ideas in combination.

 
Hey guys thanx for your reply i think i got misunderstood...my question was related to the OrderSelect() ... after all for the second example i could always nest another loop with ifs... or i can always create an array of open orders and then use OrderTicket() to pinpoint my orders ... my goal is to set cases depending on what is open in my basket....also i understand that the logic of programming remain the same regarding the language i use but some languages are more powerful than others... Ickyrus you mentioned VB, but i personally think that mq4 is much higher level compared to VB that means more limited in term of user interactivity,like for example the limitation of OrderSelect() to only select ONE order at a time with very few condition or flags limiting the manipulations of my query....but this off course remain in the skill of the programmer... anyway i really appreciate any constructive critics.. Thanks Guys
Reason: