Hi, when doing backtest, something I found helpful and simple to do in case of multiple entry and exit reasons in your code (e.g. risk management, technical indicator, time of day, wrong president got elected etc. etc. etc.)
After every trade instruction assign a numeric code, enter is + and exit is –
Extra: I was thinking of organising it so: Long entry +ve green, Long exit +ve red and Short entry -ve green, Short exit -ve red…but not got round to it yet.
//
//other code
//
// if positionperf is loser
if longonmarket and (positionperf<PositionPerfRisk) then
SELL AT MARKET
exitreason=-3
ENDIF
if shortonmarket and (positionperf<PositionPerfRisk) then
EXITSHORT AT MARKET
exitreason=-4
ENDIF
//
//other code
//
graph enterreason coloured (0,255,0) as "Entry"
graph exitreason coloured (255,0,0) as "Exit"