Need Help with code - page 2

 
2cent:

You have to do: if(OrdersTatal() > 0) { ... }





But I may have another orders with different symbols

I need to check if I already have open position with the same symbol, if so check for trail stop if not Open position.

 
vaknineyal: I change the code to look like that ... but it still doesn't open any order
You may want to read the Book so that you have an idea of Loops and Functions.
 
vaknineyal: But I may have another orders with different symbols I need to check if I already have open position with the same symbol, if so check for trail stop if not Open position.

Use a proper order select loop. It usually looks like this. Click link below

https://www.mql5.com/en/forum/139654.

https://www.mql5.com/en/forum/145507.

 
ubzen:
You may want to read the Book so that you have an idea of Loops and Functions.

I already read most of it ... I am new with programming .... if cannot help thats OK, but please stop send me to read the book, I post here because I don't understand why it's not work for me.

Thanks.

 
vaknineyal: I already read most of it ... I am new with programming .... if cannot help thats OK, but please stop send me to read the book, I post here because I don't understand why it's not work for me.
So you want someone to write the codes for you?
 
ubzen:
So you want someone to write the codes for you?


No Thanks .... leave it I will find an answer by my self

Thanks any way.

 
vaknineyal:


But I may have another orders with different symbols

I need to check if I already have open position with the same symbol, if so check for trail stop if not Open position.


Yeah yeah, I forgot. Here is what you do:

for(int i = 0; i < OrdersTotal(); i++) {
        OrderSelect(i, SELECT_BY_POS);
        if(OrderSymbol() == Symbol()) {
                /* your code goes here */
        }
}



 

As already pointed out, you need a proper loop for your OrderSelect, using a random number such as 12345 will achieve nothing.

double LowPrice = iLowest(Symbol(),0,MODE_LOWER,10,0); 
double HighPrice = iHighest(Symbol(),0,MODE_UPPER,10,0);

These do not return price values, they return the shift of the bar with the highest and lowest values.

Use MODE_HIGH and MODE_LOW, not MODE_UPPER and MODE_LOWER

Reason: