ONCE LongStrategyProfit = 0
ONCE ShortStrategyProfit = 0
IF StrategyProfit <> StrategyProfit[1] THEN
EntryPrice = TradePrice[2]
ExitPrice = TradePrice[2]
Difference = StrategyProfit - StrategyProfit[1]
IF LongOnMarket[1] THEN //LONG trades
LongStrategyProfit = LongStrategyProfit[1] + Difference
ELSIF ShortOnmarket[1] THEN //SHORT trades
ShortStrategyProfit = ShortStrategyProfit[1] + Difference
ELSE //UNDEFINED trades for which both the Difference and the Entry and Exit prices need to be compared to determine the direction
IF Difference > 0 THEN
IF ExitPrice > EntryPrice THEN
LongStrategyProfit = LongStrategyProfit[1] + Difference //when it's a PROFIT, a higher EXIT price implies a LONG trade
ELSE
ShortStrategyProfit = ShortStrategyProfit[1] + Difference //when it's a PROFIT, a lower EXIT price implies a SHORT trade
ENDIF
ELSE
IF ExitPrice < EntryPrice THEN
LongStrategyProfit = LongStrategyProfit[1] + Difference //when it's a LOSS, a lower EXIT price implies a LONG trade
ELSE
ShortStrategyProfit = ShortStrategyProfit[1] + Difference //when it's a LOSS, a higher EXIT price implies a SHORT trade
ENDIF
ENDIF
ENDIF
ENDIF
graph LongStrategyProfit coloured("Green")
graph ShortStrategyProfit coloured("Red")
graph LongStrategyProfit + ShortStrategyProfit