Value margin information only displays data according to the position of the pointer

Hi all,

I am so sorry if I am asking something what probably might be answered already.
I still learning the syntax and functions that are available a lot on Amibroker and my background is not a programmer.
I am asking this, because I did not found an answer which matches my problem in this forum and google or maybe I don't know the topic title for this problem.
So I do hope that anyone is able to help me

Here is the problem :

I do have this AFL :

// BACKTESTING

_SECTION_BEGIN("BACKTESTING");   
   
PositionScore = 100 / C;
PositionSize = -10;  
SetBarsRequired(10000, 10000);    
SetOption("HoldMinBars", 1 );  
SetFormulaName("BackTesting"); 
SetOption("CommissionAmount", 0.5);    
SetOption("CommissionMode", 1);    
SetOption("InitialEquity", 100000000);   
SetOption("PriceBoundChecking", 1);    
SetOption("UsePrevBarEquityForPosSizing", 1);    
SetTradeDelays(0, 0, 0, 0);   

SetOption("MaxOpenPositions", 20); 

_SECTION_END();

// End of BACKTESTING 

// TRADING 
EMA10 = EMA(C,10);
EMA50 = EMA(C,50);

Buyx		= Cross(EMA50,EMA10);
PBuy		= ValueWhen(Buyx,C);
Stoploss	        = ValueWhen(Buyx,PBuy-(PBuy*0.01));
TakeProfit	= ValueWhen(Buyx,PBuy+(PBuy*0.1));
SLD			= Cross(Stoploss,C);
TPD			= Cross(C,TakeProfit);

Sellx	= (SLD OR TPD);

Buy	= ExRem(Buyx,Sellx);
Sell	= ExRem(Sellx,Buyx);

BuyPrice	= ValueWhen(Buy,C);
SellPrice	= ValueWhen(Sell,C);

Win		= SellPrice > BuyPrice;
Lose	= SellPrice <= BuyPrice;
PLVal	= SellPrice - BuyPrice;
Mgn		= (PLVal/BuyPrice) * 100;
MgnVal	= ValueWhen(Sell,Mgn);
WLT		= WriteIf(Win,"P = " + WriteVal(MgnVal,1.2) + " %","L = " + WriteVal(MgnVal,1.2) + " %");

SellW = Sell AND Win;
SellL = Sell AND Lose;

//PlotShapes
PlotShapes(IIF(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-20);  
PlotShapes(IIF(SellW, shapeDownArrow, shapeNone),colorBlue, 0,H, Offset=-20);  
PlotShapes(IIF(SellL, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-20);  

// DISPLAY TEXT

_SECTION_BEGIN("DISPLAY TEXT");

fntsize = 8;// font size
dist = 85;// y-offset

bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
dt = DateTime();
dtformat = "\n%d-%m-%Y";
bkcolor = -1;

PlotTextSetFont( "", "ARIAL", fntsize, BarCount-1, 0, -1 );

for ( i = fvb; i <= lvb; i++ ) {
    if( Buy[i] || Sell[i] )	{
		var = "\n@" + C[i] + DateTimeFormat(dtformat, dt[i]);
		PL = "\n@" + C[i] + DateTimeFormat(dtformat, dt[i]);
		if( Buy[i] )  PlotText( "Buy" + var, i, L[i], colorDarkBlue, bkcolor, -dist+3*fntsize );
		if( SellL[i] ) PlotText( "Sell" + var, i, H[i], colorRed, bkcolor, dist );
		if( SellW[i] ) PlotText( "Sell" + var, i, H[i], colorBlue, bkcolor, dist );
		if( SellL[i] ) PlotText( "" + WLT, i, H[i], colorRed, bkcolor, dist-6*fntsize );
		if( SellW[i] ) PlotText( "" + WLT, i, H[i], colorBlue, bkcolor, dist-6*fntsize );
    }
}
_SECTION_END();

and chart view like this
image

My question is how to make value information margin accordance to each transaction ?

I think the key is in

MgnVal	= ValueWhen(Sell,Mgn);

I've tried using functions other than valuewhen function, but nothing has changed.

Can anyone tell me where I went wrong?

Thanks..