Trend code help

 

I am having problems with a part of my code that is supposed to trigger when the Ask moves "Epips" number of 1/10 a pips. The problem is that it always alerts "Sent Buy" no matter the movement, up or down. If somebody could tell me how to get it to act like it should it would be great.

//in init
   Old_Price=Ask;
   New_Price=Ask; 
   Point2Pip=Point;
   if(Digits==4)
   {Point2Pip=0.001;}
   if(Digits==6)
   {Point2Pip=0.00001;}
   return(0);
//in start
New_Price=Ask;
   if(MathAbs(i)<Epips)
   {if(Ask>Old_Price+1*Point2Pip)
   {i++;Alert("up");}
   else
   {i--;Alert("down");}}
    Old_Price=New_Price;
    if(MathAbs(i)==Epips)
    {if(i>0){trenddirection=1;Alert("TD1");}else{trenddirection=-1;Alert("TD-1");}
    i=0;}
  if (OrdersTotal()==0&&donttrade==0&&trenddirection==1||trenddirection==-1)
   {
      if (trenddirection==1)
      {Alert("SendBuy");OrderSend(Symbol(),OP_BUY,InvestLots,Ask,maxslip,IStop,0,NULL,NULL,1,Orange);}
      if (trenddirection==-1)
      {Alert("SendSell");OrderSend(Symbol(),OP_SELL,InvestLots,Bid,maxslip,IStop,0,NULL,NULL,1,Blue);}
      trenddirection=0;
     }
 

For me (others mileage may vary), too much code has been removed (e.g. what is the scope & initial value of 'i' ?)

So you're asking me (or others) to work out the logic without being able to actually run it.

And what is shown is formatted to a style that I neither know nor like.

Too much like hard work for me .. unless someone's paying me by the hour ;-)

 
Adjust pip values (epips, TP, SL) and point values (slippage)
//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
Reason: