Using highest since in backtesting

I am trying to back test movements of price since last buy/sell. 10% up move from lowest point since last buy and vice versa

Sell=1;
Buy = H>Ref(1.1*LowestSince(Sell, L),-1);
Sell= L<0.9*(HighestSince(Buy,H)

Technically the sell should be same as trailing stop but I get very different signals. Any suggestions much appreciated

This has been covered very many times and you will only get members asking you to search the Forum for it.
Also, you can read the article and adapt code.
http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/comment-page-1/

I have tried that code without success.
It seems it is not possible to use it to generate both buy and sell signals.

for( i = 1; i < BarCount; i++ )
{

   if( trailbuy == 0 AND Sell[ i ] ) 
   { 
      trailbuy = Low[ i ] * buylevel;
   }
   else if(sellreq[i]==0)
   {
   Sell[ i ] = 0; // remove excess buy signals
   }

   if( trailbuy > 0 AND High[ i ] > trailbuy AND Buyreq[i]  )
   {
      Buy[ i ] = 1;
      BuyPrice[ i ] = O[i];
      trailbuy = 0;
   }
   if( trailbuy > 0 )
   {   
      trailbuy = Min( Low[ i ] * buylevel, trailbuy );
      trailbARRAY[ i ] = trailbuy;
   }
 
   
   if( trailsell == 0 AND Buy[ i ] ) 
   { 
      trail = Low[ i ] * selllevel;
   }
   else Buy[ i ] = 0; 
   
   if( (trailsell > 0 AND L[ i ] <trailsell) OR sellreq[i])
   {
      Sell[ i ] = 1;
      SellPrice[ i ] = trailsell;
      trailsell = 0;
   }

   if( trailsell > 0 )
   {   
      trailsell = Max( H[ i ] * selllevel, trailsell );
      trailsARRAY[ i ] = trailsell;
   }
   	if(sellreq[i])
	{
	Sell[i]=1;
	}
   

}