Existing positions control

 

Dear all,


I need your help on developing a code for controling the number of existing positions openned. NOT ALL just the negative ones.

I have a sample code that limits the number of open trades/positions but this one considers all positions and not just the negative positions.

The code is:

"bool ExistPositions()

{

for (int l_pos_0 = maxtrades; l_pos_0 < OrdersTotal(); l_pos_0++)

{

if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES))
if (OrderSymbol() == Symbol()) return (TRUE);
}
return (FALSE);

}

...where "maxtrades" is the number of maximum existing positions.

What I need is a code like this one, that controls the positions that are not already TRAILLED STOP.

That is:

- If the position is already positive and trailled, DO NOT CONSIDER;

- If the position is negative, or NOT trailled, ONSIDER;


Thank you very much


Regards


Paulo

 

for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderMagicNumber()==Magic && OrderStopLoss() == 0 && OrderProfit() > 0) YourCounterVariable ++

}


hope that helps
 

Dear heyarn,


Thank you.

I will try it


Regards


Paulo

 
heyarn:



for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderMagicNumber()==Magic && OrderStopLoss() == 0 && OrderProfit() > 0) YourCounterVariable ++

}


hope that helps

Heyarn,


It worked. Thank you very much

Regards

Paulo