I was wondering if somebody could be kind enough to advise on how I can optimize the script of my trailing stop loss, maybe using some sort of iteration or indexing:
double stopLoss = 20 * TickSize;
if(Close[0] > Position.AvgPrice + stopLoss && Close[0] < Position.AvgPrice + 2 * stopLoss)
{
double newStop = Position.AvgPrice + stopLoss;
stopOrder = ExitLongStop(0,true,newStop,"stop","long");
}
if(Close[0] > Position.AvgPrice + 2 * stopLoss && Close[0] < Position.AvgPrice + 3 * stopLoss)
{
double newStop = Position.AvgPrice + 2 * stopLoss;
stopOrder = ExitLongStop(0,true,newStop,"stop","long");
}
if(Close[0] > Position.AvgPrice + 3 * stopLoss && Close[0] < Position.AvgPrice + 4 * stopLoss)
{
double newStop = Position.AvgPrice + 3 * stopLoss;
stopOrder = ExitLongStop(0,true,newStop,"stop","long");
}
if(Close[0] > Position.AvgPrice + 4 * stopLoss && Close[0] < Position.AvgPrice + 5 * stopLoss)
{
double newStop = Position.AvgPrice + 4 * stopLoss;
stopOrder = ExitLongStop(0,true,newStop,"stop","long");
}
Comment