> ti works fine but it does not delete the previous trace on the scope,
When I ran your model only the last simulation result was shown in the AC sweep window. Perhaps you mean it is not holding the all the traces on the AC Sweep results scope? The reason you only see the last result is the order of your script. You are clearing the traces in your for loop, instead of just before you enter the loop.
If that’s not the case then a better description of your issue and desired outcomes would be necessary.