1.if you recon the script is correctly coded or if the else statement highlighted in bold should be removed (and if yes, why exactly?);
2. any suggestion on how to improve my script is welcome
if(Position.MarketPosition == MarketPosition.Long && stopOrderLong != null)
{
if(BarsSinceEntry() > exitPeriod && Position.GetProfitLoss(Close[0], PerformanceUnit.Points) < stopLoss)
{
x = Close[0];
}
[B]else x = stopOrderLong.StopPrice - TickSize;[/B]
for(int i=1; i<10; i++)
{
if(Close[0] > (Position.AvgPrice + i*stopLoss) && Close[0] < (Position.AvgPrice + (1+i)*stopLoss))
{
y = Position.AvgPrice + i*stopLoss;
}
[B]else y = stopOrderLong.StopPrice - TickSize;[/B]
}
double newStop = Math.Max(x,y); // calculate new stop loss
if(newStop > stopOrderLong.StopPrice) // check if new stop loss is higher than current stop loss
{
if(newStop < Close[0])
{
stopOrderLong = ExitLongStop(1,true,stopOrderLong.Quantity, newStop,"Stop","Long");
}
else if(newStop >= Close[0])
{
ExitLong(1,stopOrderLong.Quantity,"Exit","Long");
}
}

Comment