Little code to implement my EA to open only an order daily on an asset

 

Good morning,

i found a code to implement in my EA. My goal is simple: the EA must not opens more order if in the day there was an order on that asset or if an order in in progress.

EA: today 01 - March the EA opens an order on USDCHF...if it close it during the day no more orders must be opened.

Here is the code I found but it doens't work:-(

int TotalHistoryOrders() {

   int cnt = 0;

   int TotalOpenOrders = 0;

   cnt=OrdersHistoryTotal();

   if(cnt==0) {

      return(0);

   }

   else {

      for(;cnt>=0;cnt--) {

         RefreshRates();

         OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY);

         if(OrderSymbol()==Symbol()) {

            TotalOpenOrders++;

         }

      }

   }

   return(TotalOpenOrders);

}



int FoundRecentOpenedOrder(int TF) {

   int last_order_idx = (TotalHistoryOrders() - 1);

   OrderSelect(last_order_idx,SELECT_BY_POS,MODE_HISTORY);

   if (OrderOpenTime() >= iTime(Symbol(), TF, 1)) {

      return(TRUE);

   }

   return(FALSE);

}
 
Claudio Lasso:

Good morning,

i found a code to implement in my EA. My goal is simple: the EA must not opens more order if in the day there was an order on that asset or if an order in in progress.

EA: today 01 - March the EA opens an order on USDCHF...if it close it during the day no more orders must be opened.

Here is the code I found but it doens't work:-(

The code you show is only partial. After you insert this code into your EA, you also need to "call" this methods and use the results in your EA logic / code.

Can not say more without seeing the entire thing.

 
  1. Your code is looking at history - your variable should be called totalClosedOrders.
  2. Using OrdersTotal (or OrdersHistoryTotal) directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

Reason: