Addtocomposite to compute net unrealized( Open position profit) of all symbols in a watchlist

Hi Fellow Members

I was trying to find the net open position profit for all open positions at any given bar using AddtoComposite and access it using Foreign function.

I run the code in exploration mode and it was working fine( able to see the composite symbol made). However i want to use this symbol in live trading and exit when the Net Profit is above a certain value.

However when i tried to use this value in the strategy the value always shows the open position profit for the chart in display( not the composite , but for single symbol).

Can we use the AddtoComposite's in live trading signals.

I know i can use mid/low level custom back-tester for this approach to find net unrealised profit but i dont want to go there. Any suggestions on how to find net open position profit for all the symbols using any method.


AddToComposite( IIf(bar_count>=1 , (entryprice-Close)*shares, 0), ~OpenPosProf", "V" ,  1 + 2 + 8 + 16 +128);   // bar_count variable stores number of bars since in positions

Open_posn_prof = foreign( "~OpenPosProf", "V" , True  );  // access the foreign composite 

if(Open_posn_prof >100000) 
{ 
     // sell code here
}

Equity already contains unrealized profit of all open positions. It is available out of the box and you don't need to calculate it. Just run backtest instead of exploration. Or if you want single-symbol equity you can use Equity() function Recommended reading: http://www.amibroker.com/guide/a_equity.html

So you should definitely NOT use Foreign and AddToComposite for that.