Im having issues with a trailing stop and target on a indicator. I know there are several posts about this but I cant find anything to fix the issues Im having.
If I set the target on a indicator and hard stop no problem it works great. if I set the trailing stop with a hard target it works great the problem I cant get both of them to work together. I can get one to work but not the other.
#region Breakeven and Trailing Stops
// Resets the stop loss to the original value when all positions are closed
switch (Position.MarketPosition)
{
case MarketPosition.Flat:
SetStopLoss(CalculationMode.Ticks, stopLossTicks);
previousPrice = 0;
break;
case MarketPosition.Long:
// Once the price is greater than entry price+ breakEvenTicks ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + breakEvenTicks * TickSize
&& previousPrice == 0)
{
initialBreakEven = Position.AvgPrice + plusBreakEven * TickSize;
SetStopLoss(CalculationMode.Price, initialBreakEven);
previousPrice = Position.AvgPrice;
PrintWithTimeStamp("previousPrice = "+previousPrice);
}
// Once at breakeven wait till trailProfitTrigger is reached before advancing stoploss by trailStepTicks size step
elseif (previousPrice != 0////StopLoss is at breakeven
&& GetCurrentAsk() > previousPrice + trailProfitTrigger * TickSize
)
{
newPrice = previousPrice + trailStepTicks * TickSize;
SetStopLoss(CalculationMode.Price, newPrice);
previousPrice = newPrice;
PrintWithTimeStamp("previousPrice = "+previousPrice);
}
break;
case MarketPosition.Short:
// Once the price is Less than entry price - breakEvenTicks ticks, set stop loss to breakeven
if (Close[0]