interesting way and good.

i see
declare variable "clear" type boolean in variable page

insert clear into into traceset clear at input as in picture.

insert codes in fixed conditions

if(t<dt)clear=true;       // appears to clear if t smaller than dt, so that is in the beginning?
else clear=false;
if(count>=n || (t>tf && t>ts+td)){ // another condition to clear true :)

am i roughly correct?