Need some clarifications in the ProfitChaseStopTrailExitOrdersExample that was posted some time back in the NT forum. I'm trying to chase my profit target based on the implementation given in this example, but it is not working. Not sure why the chase profit target is not working, so, i try to print the profitTarget objects, I get error Null object. Could you please help me to understand this peice of logic, how it works?
Print(" line 188 - profit target order state");
Print("profit target order state"+ profitTarget.OrderState);
Print("tick Secondary "+ tickSizeSecondary);
Print("profit target distance"+ ProfitTargetDistance);
// trailing logic
// the profitTarget/stopLoss is first created when the entry order fills. If it exists then move it.
// trigger the chase action when the current price is further than the set distance to the profit target
if (ChaseProfitTarget &&
profitTarget != null && (profitTarget.OrderState == OrderState.Accepted || profitTarget.OrderState == OrderState.Working) &&
Close[0] < currentPtPrice - ProfitTargetDistance * tickSizeSecondary)
{
Print(Time[0].ToString());
Print(" line 198 - inside chase profit target order state");
currentPtPrice = Close[0] + ProfitTargetDistance * tickSizeSecondary;
ExitLongLimit(1, true, entryOrder.Quantity, currentPtPrice, "profit target", entryOrder.Name);
}
// trigger the trail action when the current price is further than the set distance to the stop loss
if (TrailStopLoss &&
stopLoss != null && (stopLoss.OrderState == OrderState.Accepted || stopLoss.OrderState == OrderState.Working) &&
Close[0] > currentSlPrice + StopLossDistance * tickSizeSecondary)
{
currentSlPrice = Close[0] - StopLossDistance * tickSizeSecondary;
ExitLongStopMarket(1, true, entryOrder.Quantity, currentSlPrice, "stop loss", entryOrder.Name);
}

Comment