The code you provided in your request is not complete. I cannot explain where you went wrong to help you learn. I can only provide a solution of my own based on your stated goal.
You stated that you added that line of code "to the existing relative strength scan". However there is no existing relative strength scan in Thinkorswim. So we have created an island here, with no way to get folks on and off the island.
Here I have copied most of the code from the RelativeStrength chart study included with Thinkorswim. I have added two lines to complete the scan, which identifies stocks making a new 250 day high in RelativeStrength as compared to the ticker symbol "SPX".
input correlationWithSecurity = "SPX";
def close2 = close(correlationWithSecurity);
def rs = if close2 == 0 then 0 else close/close2;
def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);
def srHighest = Highest(sr, 250);
plot scan = sr == srHighest;