Profits/bar calculation when the trade is occuring

I want to make a chart that shows profits/bar. i dont see a way to extract it directly thro afl and if there is a better way, please let me know.

I have code in the backtester which extracts the no of bars in trade and also the profits /trade. I pass it to static variables and i am plotting it.
How do i determine profits/bar immediately after the exit signal before i enter the next trade?

IN the code below, i am doing it by looping thro the backtester after all the trades are done.

Buy = H > Ref( HHV( H, 20 ), -1 );
Sell = Cross( Signal(), MACD() );

// trade on next bar open
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = SellPrice = Open;
Short = Cover = False;

// trade size: 25% of current portfolio equity
SetPositionSize( 25, spsPercentOfEquity );
//TradeMatrix=Matrix(100000,1);
myTrades = null;
SetCustomBacktestProc( "" );

if( Status( "action" ) == actionPortfolio )
{
    bo = GetBacktesterObject();

    bo = GetBacktesterObject();
    eq = bo.InitialEquity;
    bo.PreProcess();    //  Do pre-processing

    for( i = 0; i < BarCount; i++ )   //  Loop through all bars
    {
        for( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
        {
            //  Loop through all signals at this bar
            if( sig.IsEntry )
            {
                // handle entry signal

                sig.PosSize = 2000;

            }

            if( sig.IsScale() )
            {
                // handle entry signal

                sig.PosSize = 1000;

            }
        }    //  End of for loop over signals at this bar

        bo.ProcessTradeSignals( i );  //  Process trades at bar (always required)
    }    //  End of for loop over bars

    bo.PostProcess();    //  Do post-processing (always required)




    bo.Backtest( 1 ); // run default backtest procedure


    dt = DateTime();


    currenttrade = 0; // initialize
    prof = 0;
    noofbars = 0;
    dt = 0;

    for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
    {


        //TradeMatrix[currenttrade++][0]=trade.GetProfit();
        profitPerBar = trade.GetProfit() / trade.BarsInTrade;

        if( trade.GetProfit() == 0 AND trade.BarsInTrade == 0 )
        {
            // do nothing. this is something that i cannot fix.
        }
        else
        {
            myTrades[currenttrade] = profitPerBar;
            prof[currenttrade] = trade.GetProfit();
            noofbars[currenttrade] = trade.BarsInTrade;
            dt[currenttrade] = trade.EntryDateTime;
            currenttrade++;
        }


    }


    StaticVarSet( "ClosedEquity1", myTrades );
    StaticVarSet( "profits", prof );
    StaticVarSet( "noofbars", noofbars );
    StaticVarSet( "entrydt", dt );


}

Title = "Closed Equity";
SetGradientFill( colorLightBlue, colorPink );
myval = StaticVarGet( "ClosedEquity1" ) * 100;
Plot( myval, "Closed Equity", IIf( myval > 0, colorGreen, colorRed ),  styleLine, Null, Null, 0, -1 );
Plot( MA( myval, 9 ), "ema9", colorYellow,  styleLine, Null, Null, 0, -1 );
Filter = True;
AddColumn( StaticVarGet( "entrydt" ), "entrydt", formatDateTime );
AddColumn( myval, "myval" );
AddColumn( MA( myval, 9 ), "MA(myval,9)" );
AddColumn( StaticVarGet( "profits" ), "profits" );
AddColumn( StaticVarGet( "noofbars" ), "noofbars" );

AddColumn( StaticVarGet( "noofbars" ) / StaticVarGet( "noofbars" ), "profitsbybar" );