Two problems. First is here:

var TP = 100*PIP; //takeprofit in pips converted to price value
var buffer = 20*PIP;

These variables are not changed anymore in the script, so when you load a different asset or use a portfolio, they will be bwrong. Better set them up in the trading function.

Second is the reason why your trades are not plotted: They never close. You see that in the log.