How to open two indipendent orders?

 

Hi all again! I'm sorry to hassle you with questions that may stupid, but i need your help!

My problem is that i wanted to add an hedging subsystem in my EA (originally from coderguru),

so here is the point:

I have an order X if X goes under (e.g.) 25 pips i open order Y

so if was only one order "y" it is no problem because i can use a counter like this

//+------------------------------------------------------------------+

//| FUNCTION : NUMBER OF ORDER BASE ON SYMBOL AND MAGIC NUMBER |

//| SOURCE : n/a |

//| MODIFIED : FIREDAVE |

//+------------------------------------------------------------------+

int subTotalTrade()

{

int

cnt,

total = 0;

for(cnt=0;cnt<OrdersTotal();cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if(OrderType()<=OP_SELL &&

OrderSymbol()==Symbol() &&

OrderMagicNumber()==MagicNumber) total++;

}

return(total);

}

//+------------------------------------------------------------------+

//| FUNCTION : OPEN ORDER BASE ON SYMBOL AND MAGIC NUMBER |

//| SOURCE : n/a |

//| MODIFIED : FIREDAVE |

//+------------------------------------------------------------------+

string subCheckOpenTrade()

{

int

cnt = 0;

string

lasttrade = "None";

for(cnt=0;cnt<OrdersTotal();cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if(OrderType()<=OP_SELL &&

OrderSymbol()==Symbol() &&

OrderMagicNumber()==MagicNumber)

{

if(OrderType()==OP_BUY ) lasttrade = "BUY";

if(OrderType()==OP_SELL) lasttrade = "SELL";

}

}

return(lasttrade);

} [/php]

and then limit to 1 the open order

like this

[php]

//+------------------------------------------------------------------+

//| NEW TRADE - ENTRY |

//+------------------------------------------------------------------+

if(subTotalTrade()<1 && (BuyCondition || SellCondition ) && AllowEntry)

{

but in this way i can open only one hedging order so what about if

X closes Y still open

X1 goes -25 now i'd like to open Y1 order and i can't!

How can i solve this problem?

 

Change the MagicNumber for each system in OrderSend and then for your counting

 

what is the logic behind? i want to open multiple "Y" orders like this

X and Y, x closes

X1 and Y

X1 and Y, Y1

and so on

 

I'd like to try to help you but your question isn't very clear.

Lux

 

Ok i'll try to explain better....

I have an ea, it performs well, but it still have false signals but it's not a problem

For example my signal is buy is buy right ? (X)

if OrderProfit < -25 open hedge order

the hedge order is a sell order (Y) with it's paramaters.

If X closes Y must still open until take profit

and so on X1 Y

X1 Y Y1 etc

is it a little bit more clear?

 

still no ideas or suggestions? please help! your are the best on the net!!!

 

You could have a binary variable and reset when the first order closes so when you have an X order and it goes -25 and reset=false you open Y. Then set reset=true until X is gone

Hope it makes sense

 

thx! at first look it seems it could work it out! i will try tomorrow because today i'm very busy!

but thx anyway!

Reason: