Help: Why The EA does not close a trade - page 2

 
crossy:


Thanks onewithzachy,

First I think that you have a small mistake with:

for(int cnt = OrdersTotal() -1 ; cnt >= 0; cnt--)

You have to add the green and bold correction.

But, I do not understand how the following line can help us?

#include "..\libraries\stdlib.mq4"

Thanks, Y.

Your right with the count, however, if we write it like I wrote, the OrderSelect() will return false, and the for loop continue to the next count.

That include will print the error in this code ...

Print("failed to close buy position ", ErrorDescription(GetLastError())  ); 

.. so that we know why your EA does not close any orders :(.

You can also write that include like this ...

#include <stdlib.mqh>

There is example at MetaEditor script folder entitled trade.mq4.


I supposed you know where to put the include, right ?. Put it on top of your EA (just like global variable or just like that trade.mq4).

The stdlib.mq4 is located at MetaEditor > Navigator Window (Ctrl + D) > files tab > libraries folder > stdlib.mq4.

Wow, I hope you don't mind I went detail there, coz i don't know if you already know or don't know :)

 
onewithzachy:

Your right with the count, however, if we write it like I wrote, the OrderSelect() will return false, and the for loop continue to the next count.

That include will print the error in this code ...

.. so that we know why your EA does not close any orders :(.

You can also write that include like this ...

There is example at MetaEditor script folder entitled trade.mq4.


I supposed you know where to put the include, right ?. Put it on top of your EA (just like global variable or just like that trade.mq4).

The stdlib.mq4 is located at MetaEditor > Navigator Window (Ctrl + D) > files tab > libraries folder > stdlib.mq4.

Wow, I hope you don't mind I went detail there, coz i don't know if you already know or don't know :)


Thanks onewithzachy,

I did as you suggested, and I wait for the correct stuation. I will update.

 
crossy:


Thanks onewithzachy,

I did as you suggested, and I wait for the correct stuation. I will update.

Mmm...., I'm not big fan of back testing, however, RaptorUK suggest in other thread (click here), that we can debug our code using backtesting.
 
onewithzachy:
Mmm...., I'm not big fan of back testing, however, RaptorUK suggest in other thread (click here), that we can debug our code using backtesting.


The EA is multipairs, so backtesting is impossible.

Anyway, I can get the relevant situation very fast. An I got already results. I will update..

Thanks

 
crossy:


The EA is multipairs, so backtesting is impossible.

Not backtesting . . debugging . . . even with a portfolio based EA debugging may still be possible.
 

Thanks Raptor,

I notice that the ORDERSELECT is a bool variable, and sometime the MT4 doesn't succeed

to do it. Because of that onewithzachy recomanded to do:

for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES) == true &&
OrderSymbol()==Pair &&
OrderType()==OP_BUY)
{
// code to close
}
}

My quastion is: if the ORDERSELECT is false how can I do the "cnt" LOOP again, without missing...?

I hope you understand me.

Y.

 
crossy:

Thanks Raptor,

I notice that the ORDERSELECT is a bool variable, and sometime the MT4 doesn't succeed

to do it. Because of that onewithzachy recomanded to do:

for(int cnt=0; cnt<OrdersTotal(); cnt++ )

My quastion is: if the ORDERSELECT is false how can I do the "cnt" LOOP again, without missing...?

I hope you understand me.

Y.

If you are closing Orders you MUST count down . . . NOT up.
 
RaptorUK:
If you are closing Orders you MUST count down . . . NOT up.


Sorry Raptor, I just made a Copy_paste from a previose post, but I changed it within my code.

Anyway, Do you have any idea about my pre question?

 
crossy:


Sorry Raptor, I just made a Copy_paste from a previose post, but I changed it within my code.

Anyway, Do you have any idea about my pre question?

Show your code and I can give an opinion.
 
RaptorUK:
Show your code and I can give an opinion.


Rap, It is 4016 code lines....

Anyway, My question is a tecnical one. I was learnt once FORTRAN, nad there you had numbers for desired code lines, So you could do

"GO to 120", and the code went to that line again.

Here if Orderselect is FALSE how the EA can go back to the code line: for(int cnt=OrdersTotal(); cnt > 0; cnt-- )

???