problem in taking order

 

hello all

i am willing for some help to solve this issue.

i would like to take an order every  x pips  if the market continue in the same way of the first order

this is the code but it doesn't work with me , any help please 

double Xpips=50;

 if(Ask-Xpips*Point>=lastorderopenprice(OP_BUY)){ BUY=TRUE ;}
 
 if(Bid+Xpips*Point<=lastorderopenprice(OP_SELL)){ SELL=TRUE ;}

double lastorderopenprice(int type)

{
double lototo;
for(int i=0;i<=OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic&&OrderType()==type){
lototo=OrderOpenPrice();
}
}
return(lototo);
}
 
no one to help????
 

What doesn't work?

How do you know it doesn't work?

How can you be sure that your loop returns the last order of that type?

What does your function return if there is not an order open of the type? 

Reason: