Why this behavior?

 

Dear generous mt4 expert,

I use a modified public EA (see attached) and I set spacing to 30 pips so that the positions are 30 pips apart.

When I run the EA, sometimes it gives the correct result (see below):  all positions are 30 pips apart;

 

sometimes it gives the incorrect result (see attached): the positions are only 1 to 6 pips apart.

 

What causes this random behavior?

How to correct it?

Thank you very much for your advice.

EAgreat 

Files:
 
EAgreat:

sometimes it gives the incorrect result (see attached): the positions are only 1 to 6 pips apart.

What causes this random behavior?

It's never random, it's what was coded incorrectly. Print out the variables when it makes trades and find out why.