Please help me to code trailing stop loss exit

I am trying to code a long only strategy. Below are the conditions.

Entry = When a green hammer candle is formed and the low of the hamercandle is bellow Bollinger band bottom line.

Initial Stop Loss = Hamer candle's low.

Profit Trailing = When a new candle is formed, check whether it's low is above current stop loss. If low is above current stop loss make it as the new stop loss.

I am able to write the entry part. It will be great if somebody can help me to code the stop loss and profit trailing part.

49%20PM

Here is my code

BBPeriods = 20;
BBWidth = 2;
BBTop = BBandTop( Close, BBPeriods, BBWidth );
BBBottom = BBandBot( Close, BBPeriods, BBWidth );

BuyHammer = ((H - L) > 3 * (O - C)) AND ((C-L) / (.001 + H - L) > 0.6) AND((O - L) / (.001 + H - L) > 0.6) AND C >= O;
 
Buy = BuyHammer AND Low < BBBottom;

Thanks in advance.
Raju

Check out trail stop examples here
http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart