Yes you can do that in pine script.
You'll have to code your indicator/strategy yourself. It may be helpful to check out the source code of the indicator you're using to have an idea/quick start.
I'll demonstrate with the strategy boilerplate of TradingView how can could achieve that fairly simply:
//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)
longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
////////////////////////////////
// Here is the key part for you
////////////////////////////////
if 0 < strategy.closedtrades.profit(strategy.closedtrades - 1) // profit of the last closed trade is positive
strategy.entry("My new profit dependent strategy", strategy.long) // entry new trade