Realized profit/loss % label on chart?

I know you can do an unrealized profit/loss % label but what about a realized one?  i cobbled together a lame attempt using the input function but, of course, that won’t work because changing the input for a different symbol changes it for all.  can you see any way to do this?

input buyprice = 0;
input sellprice = 0;
def buy = buyprice;
def sell = sellprice;
def diff = buy – sell;
def gain = (diff / buy) * 100;
addlabel (yes, “realized ” + gain + ” %”, color.white);