keeping a certain amount of Buystop orders open

 

I want to make sure that there will always be no less than 6 open buy stops and no less than 6 open sell stops...

here
is what I did...


//+-------------------------------------------------------+
//| count buy stop |
//+-------------------------------------------------------+

int countbuystop()
{
int res=0;
for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUYSTOP) res++;
}
return(res);
}
//+-------------------------------------------------------+
//| count sell stop |
//+-------------------------------------------------------+
int countsellstop()
{
int res=0;
for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_SELLSTOP) res++;
}
return(res);
}


then to control the orders i put in the start() function :

if(countbuystop()<6)
{

Temp=MarketInfo(Pair, MODE_BID);
for (Cnt=1;Cnt<=NormalizeDouble((Range/2),0);Cnt++)
{
OrdSend(Pair, OP_BUYSTOP, Lot, Temp+(6*Interval*point()), 0, Temp+(6*Interval*point())-SL*point(),0, CommOrder, Cnt*Magic, 0, Blue);
OrdSend(Pair, OP_SELLSTOP, Lot, Temp-(1*Interval*point()), 0, Temp-(1*Interval*point())+SL*point(),0, CommOrder, (Cnt*Magic)+1, 0, Red);
Comment(Temp+"Cnt : "+Cnt+" interval: "+Interval);
}
}


if(countsellstop()<6)
{
Temp=MarketInfo(Pair, MODE_BID);
for (Cnt=1;Cnt<=NormalizeDouble((Range/2),0);Cnt++)
{
OrdSend(Pair, OP_BUYSTOP, Lot, Temp+(1*Interval*point()), 0, Temp+(1*Interval*point())-SL*point(),0, CommOrder, Cnt*Magic, 0, Blue);
OrdSend(Pair, OP_SELLSTOP, Lot, Temp-(6*Interval*point()), 0, Temp-(6*Interval*point())+SL*point(),0, CommOrder, (Cnt*Magic)+1, 0, Red);
Comment(Temp+"Cnt : "+Cnt+" interval: "+Interval);
}
}

but when i run the EA this code works for the 1st 2 times...it opens buy and sell stop orders to replace the 1st 2 trades that were triggered but then Stops working...When price moves up and triggers buystops into buy orders it no longer replaces the buystops and sell stops like it did the 1st 2 times...

Is it because the sellstops become greater than 6 and I stipulate if(countsellstop<6)??? if so how do i get around this?


I want a minimum 6 pending buystops and minimum 6 pending sell stops...anyone know how I can do this?

 
What volume of this - NormalizeDouble((Range/2),0)?
 
Roger:
What volume of this - NormalizeDouble((Range/2),0)?

sorry, the range is 10 -15 depending on what I set it at....its an extern variable

Reason: