Isolation Between EAs

 

Hi there,

I have two opened 1-hr charts and each chart is attached with a diferent EA. One EA moves the stoploss to breakeven when the price has moved into profit by 20 pips. The other EA moves the stoploss to breakeven when the price has moved into profit by 100pips. Both of these are running on the same computer.

I notice that both EAs are moving the stoploss to breakeven at profit of 20pips. This is an undesirable result for me. Can someone help me address this problem? Below is my breakeven code - I believe that I need to somehow identify the order separately and only move the stoploss per the generated EA.

total = OrdersTotal();

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

ticket = OrderTicket();

//----BreakEven Code

if (OrderType()==OP_BUY && OrderSymbol()==Symbol())

{

CurrentProfit = Bid - OrderOpenPrice();

if (CurrentProfit>=stoploss_to_breakeven*Point)

OrderModify(ticket,Bid,OrderOpenPrice(),OrderTakeProfit(),0,Red);

}

//-----

if (OrderType()==OP_SELL && OrderSymbol()==Symbol())

{

CurrentProfit = OrderOpenPrice() - Ask;

if (CurrentProfit>=stoploss_to_breakeven*Point)

OrderModify(ticket,Ask,OrderOpenPrice(),OrderTakeProfit(),0,Green);

}

//----Set Loss Date

}

 

Needs a Magic Number

You need to start using a Magic Number to distinguish your EA's, there's a couple tutorials on this from Codersguru, but the basic concept is this:

1) In each of your EA's, set a different unique magic number at top:

MAGIC = 123456;

[/PHP]

2) When you open an Order, one of the arguments lets you specify a Magic number:

OrderSend(Symbol(),OP_BUY,lots,Ask,3,0,0,"My EA",MAGIC,0,Blue);

3) When you loop through your orders to do your trailing stops, you can filter by this magic number:

[PHP]

if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {

Juan

Reason: