Download MetaTrader 5

Help Needed.. EA executes only ones

To add comments, please log in or register
Publish your article. We will translate it into other languages!
Cosan Yegenoglu
28
Cosan Yegenoglu 2015.01.28 08:09 

Hi all,

I had an EA which worked fine. As I needed to avoid to open position on calendar events, I've added some more code into my EA. In order to test it, It simply opens a long position if EURUSD market rate is above 1.1300 and opens a short position if the EURUSD market rate is below 1.1300. It close the position if Bid > OrderOpenPrice (Ask < OrderOpenPrice for short trades). So whenever a position is closed a new one should be open (just for test purposes). When I compile the code, it opens a position and closes when Bid is greater than Order Open Price. But it never opens a new position. What can be wrong? You can find the code in the attachment. 

Thanks a lot..  

Cosan 

Files:
code.txt 49 kb
whroeder1
14537
whroeder1 2015.01.28 15:16  
  1. Check for errors. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Print your variables before and inside if statements and find out why.
  3. Your code
    datetime us1=D'2015.01.27 23:01'; 
    datetime us2=D'2015.01.27 17:00';
    datetime us3=D'2015.01.29 15:30';
    datetime us4=D'2015.01.30 15:30';
    datetime us5=D'2015.01.30 17:00';
    datetime us6=D'2015.02.02 17:00';
    datetime us7=D'2015.02.05 15:30';
    datetime us8=D'2015.02.06 15:30';
    datetime us9=D'2015.02.12 15:30';
    datetime us10=D'2015.02.12 15:30';
    datetime us11=D'2015.02.13 17:00';
    datetime us12=D'2015.02.18 21:00';
    datetime us13=D'2015.02.19 15:30';
    datetime us14=D'2015.02.25 17:00';
    datetime us15=D'2015.02.26 15:30';
    :
    int usverigel;
    
    if (((us1-now) < vksn) && (now<us1)) {usverigel = 1;} else
    if (((us2-now) < vksn) && (now<us2)) {usverigel = 1;} else
    if (((us3-now) < vksn) && (now<us3)) {usverigel = 1;} else
    if (((us4-now) < vksn) && (now<us4)) {usverigel = 1;} else
    if (((us5-now) < vksn) && (now<us5)) {usverigel = 1;} else
    if (((us6-now) < vksn) && (now<us6)) {usverigel = 1;} else
    if (((us7-now) < vksn) && (now<us7)) {usverigel = 1;} else
    if (((us8-now) < vksn) && (now<us8)) {usverigel = 1;} else
    if (((us9-now) < vksn) && (now<us9)) {usverigel = 1;} else
    if (((us10-now) < vksn) && (now<us10)) {usverigel = 1;} else
    if (((us11-now) < vksn) && (now<us11)) {usverigel = 1;} else
    if (((us12-now) < vksn) && (now<us12)) {usverigel = 1;} else
    if (((us13-now) < vksn) && (now<us13)) {usverigel = 1;} else
    if (((us14-now) < vksn) && (now<us14)) {usverigel = 1;} else
    if (((us15-now) < vksn) && (now<us15)) {usverigel = 1;} else
    :
    if (((us166-now) < vksn) && (now<us166)) {usverigel = 1;} else {usverigel = 0;}
    
    Learn to use arrays
    datetime us[]= {D'2015.01.27 23:01', D'2015.01.27 17:00', D'2015.01.29 15:30', D'2015.01.30 15:30',
                    D'2015.01.30 17:00', D'2015.02.02 17:00', D'2015.02.05 15:30' ,D'2015.02.06 15:30',
                    D'2015.02.12 15:30', D'2015.02.12 15:30' ,D'2015.02.13 17:00', D'2015.02.18 21:00',
                    D'2015.02.19 15:30', D'2015.02.25 17:00', D'2015.02.26 15:30' ...}
    :
    int usverigel = 0;
      for(int i=ArraySize(us) - 1, i >= 0; --i)
         if (((us[i]-now) < vksn) && (now<us[i])) {usverigel = 1;} 
    

  4. Don't use int's
    if (((us166-now) < vksn) && (now<us166)) {usverigel = 1;} else {usverigel = 0;}
    :
    if ((usverigel > 0) || (usverigec > 0) || (euverigel > 0) || (euverigec > 0)) {bool veri = true;} else {veri = false;}
    
    when you mean boolean
       if (((us[i]-now) < vksn) && (now<us[i])) {usverigel = true;}
    :
    if (usverigel || usverigec || euverigel || euverigec) {bool veri = true;} else {veri = false;}
    

  5. Your test
    if (usverigel || usverigec || euverigel || euverigec) {bool veri = true;} else {veri = false;}
    
    if (dam1 > dam2) {bool dnotrade = true;} else {dnotrade = false;}
    
    Simplify
    bool veri     = usverigel || usverigec || euverigel || euverigec;
    
    bool dnotrade = dam1 > dam2;
    
    x
Cosan Yegenoglu
28
Cosan Yegenoglu 2015.01.28 16:08  

Hi WHRoeder,

Thank you so much. I'll study these.. 

To add comments, please log in or register