How do I get one EA to see the action of another?

 

Here is what I want to do, but I just cannot seem to get it right :

I have 2 EA's, both trading one symbol - for reasons that are not really important, I want the first EA to identify the condition at which an open trade on the symbol should close, but I want the actual close to be undertaken by the second EA.  To do this, I need the 2nd EA to be able to recognize the trade set-up created by the 1st EA.  I have considered that ONE way to do this would be to OrderModify() the open order as soon the trade set-up is recognized by the 1st EA and then to find the changed order using OrderSelect() on the 2nd EA - if anyone has a better idea, I would be happy to hear it!  My thinking though, was to simply create a "flag" on the OrderModify() that is then easy to OrderSelect().  I don't normally use arrows on my Orders, so I thought that I could simply modify the Order from one with no arrows (CLR_NONE) to one with Blue arrows, which I guess would then be easy to filter with OrderSelect().  Here's the OderModify() code, but it doesn't seem to work :

 

{
   bool   Result;
   int    i,Pos,Error;
   int    Total=OrdersTotal();
   
   if(Total>0)
   {for(i=Total-1; i>=0; i--) 
     {if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == TRUE && OrderMagicNumber()==39379)
       { 
       bool res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit(),0,Blue);}
            if(!res)
               Print("Error in OrderModify. Error code=",GetLastError());
            else
               Print("Order modified successfully.");
   }
    }//if
     }//for

  I get the following error : "Error in OrderModify. Error = 1."

 

If anyone is able to help with this, or even suggest a completely different way of tackling the challenge, I would greatly appreciate it.

 
 bool res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit(),0,Blue);
You are not changing anything so the Modify will fail
 
I changed the arrow colour from "CLR_None" to "Blue".  Is that not a change?
 

When the first EA recognises the conditions to close an order, you could use GlobalVariableSet and name it with the ticket number, (number will need to be changed to a string).

Then the 2nd EA can use GlobalVariableCheck to see if the GV exists for each open order

If so, after successfully closing the order, delete the GV 

 
FXBulldog:
I changed the arrow colour from "CLR_None" to "Blue".  Is that not a change?

I don't believe that it is a valid modification

How would you check that the arrow colour has changed? 

 
I would simply look for a blue-coloured arrow which I otherwise never use.  However, that was a work-around idea.  I am keen to try the GlobalVariableSet and GlobalVariableCheck, which it seems is designed for the purpose.  Let me give that a try and I will post if I need further assistance.  Thanks GumRai.
 

Hi GumRai

Thinking about this again, I would still like to know how to run the OrderModify() function anyway.

 

How would you change the above code to get the OrderModify() to run? (I don't mind doing the change to a ticket number, instead of arrow colour, but still seem to have problems with my code as posted above).

 

Any advise, or improved lines of code would be much appreciated. 

 
FXBulldog:

Hi GumRai

Thinking about this again, I would still like to know how to run the OrderModify() function anyway.

 

How would you change the above code to get the OrderModify() to run? (I don't mind doing the change to a ticket number, instead of arrow colour, but still seem to have problems with my code as posted above).

 

Any advise, or improved lines of code would be much appreciated. 

 

As I said, you have to actually modify something (not the arrow colour) for the modify to be successful.