Thanks for the info. I believe you've found a bug with RiskVal. It does not calculate the risk of partially closed trades. I'll put up a notice for the developers to fix this for the next update.

Until then you need indeed a for(open_trades) loop for calculating the current risk. I can't see an obvious bug in the manual example, though. So your crash might have a different reason. The code you've posted doesn't crash here.