I am trying to write a code in which I set limit that won't close the position. Instead the algorithm will monitor the position. Once the position losses 1/2 of the limit, it will close the position. However, The code draw the line but it does not close the position. I inserted the Print() and it is not showing up in the output. I have been trying several ways but I cannot catch the mistake. Would you please help me?
Code 1 (did not close the position)
if (Position.MarketPosition == MarketPosition.Short)
{
if (Close[0] > Position.AveragePrice - Limit * TickSize)
{
if (Close[0] < Position.AveragePrice - (Limit * 0.5) * TickSize)
CancelOpenEntries(); Print();
Draw.VerticalLine(this, CurrentBar.ToString(), 0, Brushes.Gray, DashStyleHelper.Dash, 4, true);
}
Code 2 (did not close the position)
if (Position.MarketPosition == MarketPosition.Short)
{
if (Close[0] > Position.AveragePrice - Limit * TickSize)
{
if (Close[0] < Position.AveragePrice - (Limit * 0.5) * TickSize)
ExitShort(); Print();
Draw.VerticalLine(this, CurrentBar.ToString(), 0, Brushes.Gray, DashStyleHelper.Dash, 4, true);
}
Comment