EA to match manual orders

Back to topics list To post a new topic, please log in or register
avatar
120
DeanDeV 2016.07.05 19:49
 

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!  

avatar
108
eddie 2016.07.05 20:13 #
 

Hi!


Show us your real code and not such nonsense.

avatar
120
DeanDeV 2016.07.05 20:16 #
 
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?  

avatar
108
eddie 2016.07.05 21:53 #
 

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 ?


avatar
120
DeanDeV 2016.07.05 22:15 #
 
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);
  }
Back to topics list  

To add comments, please log in or register