EA to match manual orders

 

Hey guys,

So I have been struggling with this code, and not sure why. All I simply want is my EA to match whatever orders I place. Below is the function I have been using, however, it doesn't seem to match all the orders I place. Not sure if there is a more accurate way for this?

int ThisBarTrade=0;

void function()
   {
    int m;
    if(OpenOrdersThisPair(Symbol())==1){     //only match when there is only one open order
    if(Bars!=ThisBarTrade){        //counter placing multiple orders at once 
     ThisBarTrade=Bars;
     if(OrderSelect(m,SELECT_BY_POS,MODE_TRADES)){
      if(OrderSymbol()==Symbol())
      if(OrderMagicNumber()==0)       //manual orders
      if(TimeCurrent() - OrderOpenPrice() <= 1){      //first second of order being placed
       if(OrderType()==0){buy}
       if(OrderType()==1){sell}}}}}
   }

int OpenOrdersThisPair(string pair)
  {
   int total=0;
   
   for(int a=OrdersTotal()-1; a>=0; a--){
    if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES))
    if(OrderType()<=1)
    if(OrderSymbol()==pair) total++;}
   return(total);
  }

 

Thanks!  

 

Hi!


Show us your real code and not such nonsense.

 
eddie:

Hi!


Show us your real code and not such nonsense.

Good day Peter,

The above function() gets called in the start() function. Simple. 'not such nonsense' is rather unnecessary and irrelevant don't you think?  

 

How do you call it when you subtract OrderOpenPrice from TimeCurrent or selecting an order without initialize "m" ?

Have you tried to test or debug your code ?

 
eddie:

How do you call it when you subtract OrderOpenPrice from TimeCurrent or selecting an order without initialize "m" ?

Have you tried to test or debug your code ?


My apologies, see below..

 

int ThisBarTrade=0;

void function()
   {
    int m;
    if(OpenOrdersThisPair(Symbol())==1){     //only match when there is only one open order
    if(Bars!=ThisBarTrade){        //counter placing multiple orders at once 
     ThisBarTrade=Bars;
     for(m=OrdersTotal()-1; m>=0; m--){
      if(OrderSelect(m,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()==Symbol())
      if(OrderMagicNumber()==0)       //manual orders
      if(TimeCurrent() - OrderOpenTime() <= 1){      //first second of order being placed
       if(OrderType()==0){buy}
       if(OrderType()==1){sell}}}}}
   }

int OpenOrdersThisPair(string pair)
  {
   int total=0;
   
   for(int a=OrdersTotal()-1; a>=0; a--){
    if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES))
    if(OrderType()<=1)
    if(OrderSymbol()==pair) total++;}
   return(total);
  }