close biggest winning trades at same time as losing trade?

 

Does anybody know how to do this? My EA will always be in a hedge and I want to close the biggest winning trade at the same time as the losing trade hits stop loss...


e.g. if i have a buy trade at -30 and its SL is -40 and I have a Sell trade at +20 and another sell trade at +10 ...then I want to set my 2 short trades to close as soon as the long trade is stopped out.


how would I do this with the Orderselect function?


e.g:

void close_Profits()
{
/////////////////////////////////////

for(i=total-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()!=Pair) continue;
if(OrderType()==OP_BUY)
{
if(Bid<OrderOpenPrice()-38*Point()) // if my trade hits sl at -40 pips then....

{

Orderclose( close the 2 biggest open sell trades now to cover the loss) // how do I make sure only the 2 biggest winners are closed and not all short trades are closed at this point?

}

}

}

///////////////////////////////////////
}


anybody know how I can do this effectively?

Thanx in advance for the suggestions...

 
23510 wrote >>

Does anybody know how to do this? My EA will always be in a hedge and I want to close the biggest winning trade at the same time as the losing trade hits stop loss...

e.g. if i have a buy trade at -30 and its SL is -40 and I have a Sell trade at +20 and another sell trade at +10 ...then I want to set my 2 short trades to close as soon as the long trade is stopped out.

how would I do this with the Orderselect function?

e.g:

void close_Profits()
{
/////////////////////////////////////

for(i=total-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()!=Pair) continue;
if(OrderType()==OP_BUY)
{
if(Bid<OrderOpenPrice()-38*Point()) // if my trade hits sl at -40 pips then....

{

Orderclose( close the 2 biggest open sell trades now to cover the loss) // how do I make sure only the 2 biggest winners are closed and not all short trades are closed at this point?

}

}

}

///////////////////////////////////////
}

anybody know how I can do this effectively?

Thanx in advance for the suggestions...

are u having a 3 orders strategy? if so, then when there are 2 orders left because one of them hit stoploss, then do a closeall orders function

 
ronaldosim:

are u having a 3 orders strategy? if so, then when there are 2 orders left because one of them hit stoploss, then do a closeall orders function

No that is the problem...it opens up to 6 orders so I want to select the 2 highest winnig trades to cover the loss of the losing trade...

 
23510 wrote >>

No that is the problem...it opens up to 6 orders so I want to select the 2 highest winnig trades to cover the loss of the losing trade...

so there are 6 orders in yr strategy; when one them hit stoploss, there are 5 left;

do a loop and look for an order that that has the highest profit; take not of the orderticket; when the loop is complete, close that orderticket;

then repeat this a second time; since the second highest profit will now be the highest

 
ronaldosim:

so there are 6 orders in yr strategy; when one them hit stoploss, there are 5 left;

do a loop and look for an order that that has the highest profit; take not of the orderticket; when the loop is complete, close that orderticket;

then repeat this a second time; since the second highest profit will now be the highest

Thanks, Ill give it a try...

Not so sure how to do that?

thanx for advice...you always seem to be able to answer the difficult questions. i appreciate it!


like this maybe? :

int total=OrdersTotal();

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

{

if(OrderSelect(i, SELECT_BY_POS)==true)

Print("Profit for the order : ",OrderProfit());


but how do i recognize the highest profit and tie it to a ticket number?

 

Anybody know how I can do this?

How do I check through the currently open orders and select the 2 with the highest open profits?

 
23510 wrote >>

Thanks, Ill give it a try...

Not so sure how to do that?

thanx for advice...you always seem to be able to answer the difficult questions. i appreciate it!

like this maybe? :

int total=OrdersTotal();

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

{

if(OrderSelect(i, SELECT_BY_POS)==true)

Print("Profit for the order : ",OrderProfit());

but how do i recognize the highest profit and tie it to a ticket number?

int total=OrdersTotal();

double profit =0;

int orderticket;

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

{

if(OrderSelect(i, SELECT_BY_POS)==true)

{

if (OrderProfit()>profit) { profit=OrderProfit(); orderticket=OrderTicket();}

}

}//end for

OrderClose(orderticket)....;

//this close the order with the largest profit

then repeat the whole thing again for the second largest profit has now become your largest profit since the prev largest profit order has been closed

 
ronaldosim:

int total=OrdersTotal();

double profit =0;

int orderticket;

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

{

if(OrderSelect(i, SELECT_BY_POS)==true)

{

if (OrderProfit()>profit) { profit=OrderProfit(); orderticket=OrderTicket();}

}

}//end for

OrderClose(orderticket)....;

//this close the order with the largest profit

then repeat the whole thing again for the second largest profit has now become your largest profit since the prev largest profit order has been closed

FANTASTIC! thank you so much!

Reason: