Download MetaTrader 5

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

To add comments, please log in or register
No PC at hand? Communicate with friends using your mobile phone!
Jing Wang
271
Jing Wang 2016.08.18 15:16 

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
4732
Ernst Van Der Merwe 2016.08.19 08:28  
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
10
deltatangoxray 2016.09.02 04:15  

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