Looking to get some help on stop losses on strategies. The code below enters into a trade and then immediately executes a closing order due to ‘stop loss hit’
var longExitPrice = Position.AveragePrice - 0.5;
var shortExitPrice = Position.AveragePrice + 0.45;
if (Position.MarketPosition == MarketPosition.Long)
{
SetStopLoss(CalculationMode.Price, longExitPrice);
}
if (Position.MarketPosition == MarketPosition.Short)
{
SetStopLoss(CalculationMode.Price, shortExitPrice);
}
Hi @tonyb, Check out @NinjaTrader_ChelseaB’s answer to a similar question here: https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1307722-sell-order-stop-must-be-below-price?p=1307731#post1307731 , specifically the info beneath the bold “Set method considerations” title. To summarize the most relevant parts of their post that applies to your situation, “SetStopLoss()” should be used before the EnterLong() or similar method is used (you can do it in the line of code directly above “EnterLong()” or similar method calls), and should be set to a calculation mode of anything except Price, even if you want to call SetStopLoss() again with a CalculationMode of Price once your entry order is filled, which you are allowed to do.