How to close a buy order of a option in tradingview webhooks


Im planning to use trading view webhooks with a basket which should contain one buy and sell order please note that this is automated using trading view alerts so the sell order here is i want to sell the previous option which was bought in previous buy and i want to sell that in this basket now
or like is there anyway i can close all the open trades till now with a basket then i can have three buckets and make it work otherwise how to close the previous bought option as its shorting instead of exiting the option