I attached the piece of code that I use for my TrailStop, any help would be greatly appreciated:
// UPDATE TargetStopPrice
if (Position.MarketPosition == MarketPosition.Long
&& UnRealizedPnl > _targetPnl)
{
_targetPnl += _stepPnl;
var target = Open[0] > _lastClose && GetCurrentAsk() > Open[0]
? Open[0]
: _lastClose;
_currentStopPrice = (target + (_trailStopDistance * TickSize));
}
if (Position.MarketPosition == MarketPosition.Short
&& UnRealizedPnl > _targetPnl)
{
_targetPnl += _stepPnl;
var target = Open[0] < _lastClose && GetCurrentAsk() < Open[0]
? Open[0]
: _lastClose;
_currentStopPrice = (target - (_trailStopDistance * TickSize));
}
// SET TargetStop
if (_currentStopPrice != 0)
{
if (Position.MarketPosition == MarketPosition.Long
&& _currentOrder.OrderState != OrderState.Rejected)
{
VPrint(Time[0].ToString() + " StopLoss:" + _currentStopPrice.ToString("N6") + " Entry: " + _lastClose.ToString("N6"));
ExitLongStopMarket(DefaultQuantity, _currentStopPrice);
}
if (Position.MarketPosition == MarketPosition.Short
&& _currentOrder.OrderState != OrderState.Rejected)
{
VPrint(Time[0].ToString() + " StopLoss:" + _currentStopPrice.ToString("N6") + " Entry: " + _lastClose.ToString("N6"));
ExitShortStopMarket(DefaultQuantity, _currentStopPrice);
}
}

Comment