Valuewhen & Add Column

I would like to show the profit earned since the buy signal on the backtest report
but showed error, how can solve it?
Many Thanks

ma5= MA(C,5);
Buy = C>ma5 AND Ref(C,-1)<Ref(ma5,-1);
Sell= C<ma5 AND Ref(C,-1)>Ref(ma5,-1);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

mixbuyprice=ValueWhen (Buy,C);
mixprofit = (C-mixbuyprice)/mixbuyprice*100;

AddTextColumn(mixprofit,"Mix Profit",1.2, IIf(mixprofit>0,colorgreen,colorred));

Instead of AddTextColumn, try AddColumn

3 Likes