How do i code the same EA to run on different currency pairs without interference?

Back to topics list To post a new topic, please log in or register
avatar
3
Topnotch 2015.07.17 09:14
 
I want to trade the same EA on different currency pairs(charts) and it seems there is a conflict.

I loaded my EA on EUR/USD and it placed an order, however it didn't place an order on GBP/USD when the entry condition was meet.

Please how do i code the same EA to run independently of each other, so i can place different trades on different currency charts.

I use magic numbers, i guess i would have to assign each instance of a running EA a unique magic number by editing the properties.


Please how do i add a filter? this is how my OrderSelect() is coded. Where Should i add a filter please?

 if(OrdersTotal()==0)
     {
        if(Ask > MA50)
        {
           if(PreviousCCI<=-100 && CurrentCCI>=-100)
           {
               int ticket1;
               ticket1 =OrderSend(Symbol(),OP_BUY,LotSize,Ask,5,0,0,"CCi&MA. Buy",MagicNumber,0,clrGreen);
               if(ticket1<0)
               {
               Alert("Error Sending order",GetLastError());
               }
               else
               {
               Alert("Ticket number is: ",ticket1);
            
               }
avatar
54
PomeGranate 2015.07.17 10:37 #
 
Topnotch:
Please how do i add a filter? this is how my OrderSelect() is coded. Where Should i add a filter please?

 if(OrdersTotal()==0)
     {
        if(Ask > MA50)
        {
           if(PreviousCCI<=-100 && CurrentCCI>=-100)
           {
               int ticket1;
               ticket1 =OrderSend(Symbol(),OP_BUY,LotSize,Ask,5,0,0,"CCi&MA. Buy",MagicNumber,0,clrGreen);
               if(ticket1<0)
               {
               Alert("Error Sending order",GetLastError());
               }
               else
               {
               Alert("Ticket number is: ",ticket1);
            
               }

 I cannot see an OrderSelect() call? However, it is clear that your EA will only handle one position at the same time, as your if-condition is based on number of open orders.

You probably wouldn't even need different magic numbers, as you can filter your OrderSelect() loop by symbol. Feel free to ask further questions, if this doesn't really help yet.

avatar
3
Topnotch 2015.07.17 15:28 #
 
PomeGranate:

 I cannot see an OrderSelect() call? However, it is clear that your EA will only handle one position at the same time, as your if-condition is based on number of open orders.

You probably wouldn't even need different magic numbers, as you can filter your OrderSelect() loop by symbol. Feel free to ask further questions, if this doesn't really help yet.

Thanks. i still need help. i further enhanced my code by add a global function as a filter please would this work?

int totaltrades()

  {

      int total=0;

for(int i=0; i<OrdersTotal(); i++)

   {

      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      Alert("error modifying order ",GetLastError());

      if(MagicNumber ==OrderMagicNumber())

      total++;

   }

      return(total);

 } 

  if(totaltrades()==0)

     {
        if(Ask > MA50)
        {
           if(PreviousCCI<=-100 && CurrentCCI>=-100)
           {
               int ticket1;
               ticket1 =OrderSend(Symbol(),OP_BUY,LotSize,Ask,5,0,0,"CCi&MA. Buy",MagicNumber,0,clrGreen);
               if(ticket1<0)
               {
               Alert("Error Sending order",GetLastError());
               }
               else
               {
               Alert("Ticket number is: ",ticket1);
            
               }

 

 

avatar
12995
WHRoeder 2015.07.18 14:10 #
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2.   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
          Alert("error modifying order ",GetLastError());
          if(MagicNumber ==OrderMagicNumber())
             total++;
    This give you the total open/pending orders for the MN. It is incompatible with the EA running on other charts. Filter by pair. If the EA could be placed on the same pair but different timeframes, you must use a range of magic numbers.
avatar
120
DeanDeV 2015.07.23 19:32 #
 
Topnotch:
I want to trade the same EA on different currency pairs(charts) and it seems there is a conflict.

I loaded my EA on EUR/USD and it placed an order, however it didn't place an order on GBP/USD when the entry condition was meet.

Please how do i code the same EA to run independently of each other, so i can place different trades on different currency charts.

I use magic numbers, i guess i would have to assign each instance of a running EA a unique magic number by editing the properties.


Please how do i add a filter? this is how my OrderSelect() is coded. Where Should i add a filter please?

 if(OrdersTotal()==0)
     {

            
      }

You cannot use OrdersTotal() because that looks at orders across all pairs. Use something like this to filter specifically to Symbol().

 

int OpenOrdersThisPair(string pair)
  {
   int total=0;
   
   for(int b=OrdersTotal()-1; b>0; b--)
    {
     if(!OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderSymbol()==pair) total++;     //can add more specific criteria if you want to trade across multiple timeframes on same pair by using magicnumbers.
    }
     return(total);
  }

 

 

avatar
3
Topnotch 2015.07.25 12:22 #
 
DeanDeV:

You cannot use OrdersTotal() because that looks at orders across all pairs. Use something like this to filter specifically to Symbol().

 

 

 

Thank you, this is what i now actually use rather than OrdersTotal(). Good Enough?
int totaltrades()

  {


      int total=0;

for(int i=0; i<OrdersTotal(); i++)

   {

      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      Alert("error Selecting order ",GetLastError());

      if(MagicNumber ==OrderMagicNumber())

      total++;

   }

      return(total);

 } 

  if(totaltrades()==0)

     {
Back to topics list  

To add comments, please log in or register