Hello siscop,
so when SetStopLoss is hit
Do you mean when the order is generated and sent or when the order is filled?
whenever the SL is hit it keeps on entering another position since the limit entry is hit too.
SetStopLoss and
SetProfitTarget are generated when there is an open position. As they are not under condition in your code-they are evaluated intra-bar (even if IOG is off).
That is not possible to trace the event of SetStopLoss or SetProfitTarget generation. If you need to assign a value to a variable when one of your exits is generated you need to use begin - end statement.
If you do not want to use IOG but need to put SetStopLoss/SetProfitTarget under condition then you can use
RecalcLastBarAfter to make your strategy recalculated and have necessary orders generated.