execute a new entry only if there has not been closed order on the current bar

To add comments, please log in or register
Jing Wang
294
Jing Wang  

Hi guys,

need some help here.

I made an momentum based EA  (nothing exciting, I know). When take profit has occurred, The EA is supposed to wait for a fresh bar to enter the next trade. So here is my code at the begining of the start()

 

bool CanTrade = True;

int OHTotal = OrdersHistoryTotal();

 

 for (int hi = 0; hi < OHTotal; hi ++) {

      bool hasclosedtrade = OrderSelect(hi, SELECT_BY_POS, MODE_HISTORY);

      if(hasclosedtrade && OrderCloseTime() >= Time[0]  &&  OrderMagicNumber() == MagicNumber) {

         CanTrade = False;

         }

         return 0;

         } 

 

It does not work. What have I done wrong?

Ernst Van Der Merwe
5755
Ernst Van Der Merwe  
bool CanTrade = false;

int OHTotal = OrdersHistoryTotal();

 for (int hi = 0; hi < OHTotal; hi ++) {

      bool hasclosedtrade = OrderSelect(hi, SELECT_BY_POS, MODE_HISTORY);

      if(hasclosedtrade && OrderCloseTime() < Time[0]  &&  OrderMagicNumber() == MagicNumber) {

         CanTrade = true;

         }
      
     }
deltatangoxray
24
deltatangoxray  

MagicNumber is an undeclared variable in your code above. What are you initializing this variable as?

OrderMagicNumber() == MagicNumber

Thank you.

execute a new entry only if there has not been closed order on the current bar
execute a new entry only if there has not been closed order on the current bar
  • www.mql5.com
Hi guys, need some help here. I made an momentum based EA (nothing exciting, I know...
To add comments, please log in or register