Open sell ord buy trade some points after the last open price

 

Hi,

I have this code of my EA to retrive info about last order:

double LastOrder(string info,int type=-1) 
{ 
 for(int i=OrdersHistoryTotal()-1;i>=0;i--) 
 { 
  bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); 
  string   sy=OrderSymbol(), 
           mm=OrderComment(); 
  int      mn=OrderMagicNumber(), 
           ty=OrderType(); 
  double   lo=OrderLots(), 
           op=OrderOpenPrice(), 
           cp=OrderClosePrice(), 
           pt=OrderProfit(), 
           tp=OrderTakeProfit(), 
           sl=OrderStopLoss();   
  datetime om=OrderOpenTime(), 
           cm=OrderCloseTime(); 
                     
  if(sy==Symbol()&&mn==MagicNo) 
  { 
   if(ty==type||type==-1) 
   { 
    if(info=="Lots")return(lo); 
    else if(info=="OpenPrice")return(op); 
    else if(info=="ClosePrice")return(cp); 
    else if(info=="Profit")return(pt); 
    else if(info=="Type")return(ty); 
    else if(info=="TP")return(tp); 
    else if(info=="SL")return(sl); 
    else if(info=="OpenTime")return(om); 
    else if(info=="CloseTime")return(cm); 
    else if(info=="Comment")return(mm); 
   } 
  }  
 } 
 return(0); 
} 

This EA is programmed to work with strong trend. I'd like that if price is higher than the last one of 50 points it opens a new trade so:

if (
Ask==(NormalizeDouble(LastOrder("OpenPrice")+50*Point(),Digits))&&Orderscnt()>0
)
 {

  if(BarTime!=Time[0]&&((MaxTrades>0&&Orderscnt()<MaxTrades)||MaxTrades==0))
  {
 if(TP_SL_As_Price==false){
   if(Stoploss!=0){SL=Bid-Stoploss*point;}else SL=0;
   if(Takeprofit!=0){TP=Bid+Takeprofit*point;}else TP=0;}
   
    if(TP_SL_As_Price==true){
    SL=Stoploss;
    TP=Takeprofit;}
   
   ticket=OrderSend(Symbol(),OP_BUY,NewLots,NormalizeDouble(Ask,Digits),5*Q,SL,TP,"DS",MagicNo,0,Blue);  
   BarTime=Time[0];}

 }

but it doesn't work. Could please someone help me?Thanks