Here is my code:
if (Position.MarketPosition == MarketPosition.Long)
{
double unrealizedProfit = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);
if (!trailStopActivated && unrealizedProfit >= TpPoints * TickSize * Position.Quantity * 5)
{
currentStopLoss = Position.AveragePrice;
SetStopLoss("Long", CalculationMode.Price, currentStopLoss, false);
trailStopActivated = true;
tickCount = 0;
}
if (trailStopActivated)
{
double newStopLoss = High[0] - TrailOffset * TickSize;
if (newStopLoss > currentStopLoss)
{
currentStopLoss = newStopLoss;
SetStopLoss("Long", CalculationMode.Price, currentStopLoss, false);
tickCount++;
}
}
}
if (Position.MarketPosition == MarketPosition.Short)
{
double unrealizedProfit = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);
if (!trailStopActivated && unrealizedProfit >= TpPoints * TickSize * Position.Quantity * 5 )
{
currentStopLoss = Position.AveragePrice;
SetStopLoss("Short", CalculationMode.Price, currentStopLoss, false);
trailStopActivated = true;
tickCount = 0;
}
if (trailStopActivated)
{
double newStopLoss = Math.Min(currentStopLoss, Low[0] + TrailOffset * TickSize);
if (newStopLoss < currentStopLoss)
{
currentStopLoss = newStopLoss;
SetStopLoss("Short", CalculationMode.Price, currentStopLoss, false);
tickCount++;
}

Comment