It enters a long trade (trading NQ), and has a target exit at 28 ticks. It also has a trailing stop which activates at 28 ticks and moves the SL to 27, or 1 tick above entry price. Usually it works as designed, but in some cases in which price goes only 28 ticks and reverses, the trailing move of the stoploss happens, but not the exit.
The blue lines shows the 28 tick target, at 20833. You can see it moved the SL to breakeven+1, where both contracts are exited.
What I want to happen it that half the trade exits on the target, and the other half trails by 27 ticks. So as soon as it reaches 20833, half closes and the SL is moved to 20826.25. Logging info shows that the trade is placed as expected as well and the initial SL and TP (Target 1 & 2).
Here is the code I use to trigger the trailing stop.
if (UseTrailingStop && Position.MarketPosition != MarketPosition.Flat)
{
if (!trailTriggered)
{
double curPrice = (Position.MarketPosition == MarketPosition.Long) ? GetCurrentBid() : GetCurrentAsk();
if (Position.MarketPosition == MarketPosition.Long && curPrice >= AvePrice() + LngActivationTicks*TickSize)
{
Log(" TRAILING STOP TRIGGERED cause Bid (" + curPrice + ") >= Entry Price (" + AvePrice() + ") + activation ticks (" + LngActivationTicks + ")");
trailTriggered = true;
}
else if (Position.MarketPosition == MarketPosition.Short && curPrice <= AvePrice() - ShtActivationTicks*TickSize)
{
Log(" TRAILING STOP TRIGGERED cause Ask (" + curPrice + ") <= Entry Price (" + AvePrice() + ") - activation ticks (" + ShtActivationTicks + ")");
trailTriggered = true;
}
}
if (trailTriggered)
{
/// Trail when first leg closes -usually, but not nec; we may need to move both stops
double newSL = GetNewTrailPrice(Position.MarketPosition.ToString());
if (newSL != 0)
{
ModifyStopLoss(newSL);
if (slOrder1 != null)
ModifyStopLoss(newSL, 1);
}
}
}
Strategy - NQ 12-24 - [OnBarUpdate] - 2024-11-25 09:25:18 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TRAILING STOP TRIGGERED cause Bid (20833) >= Entry Price (20826) + activation ticks (28)
In order to see what really occurred, I loaded a tick chart to see the order of events. This is a buy trade, so I should be concerned with Bid price to close the position. I opened a chart with both Bid and Ask lines, with the Bid line in a brighter color, and here is the relevant section of the chart:
Each half of the trade is its own entry with its own SL & TP. I'm not an expert on how the historical NT8 engine works, but when the Bid reached 20833, I would think it would close the first part of the trade, and trigger the trail. But here I saw that Bid only reached a high of 20832.75. Yet the line from the logging says it hit 20833, whereupon the trail moved the stop to BE+1.
I was tracking what I thought was a problem with NT historical not exiting a trade when it should have; as I mentioned, a problem I have seen more than once.
But according to the tick chart, I should be wondering why GetCurentBid() returned 20833 when it never got that high.

Comment