I would like to find a way on how to track the number of times that the below strategy has taken maxProfit. The idea is to stop the strategy to run once, we hit certain number of maxProfit.
strategy.exit(id="XL STP", profit = maxProfit, loss = nRes*100)
I do not know a way to track this number while the strategy is being executed.
Use an integer counter variable that you increment once per trade at most only if the current profit is above your maxProfit variable
The
strategy.position_avg_pricegives you the entry price So the difference for example for a long between thehighandstrategy.position_avg_priceshould give you the current PnL of your tradeYou can track the higher/lower points of your trades like this