Gross Profit & Gross loss

Hello everybody,
I am requesting your support for my problem.
I am trading on 25 symbols regularly with single strategy.
I want to back-test overall profit and overall loss of all trades. approx. 5 to 6 trades at a time.
Because many times my profit rises and again vanish before individual target.
So I want to put Gross Target and Gross Stop loss on all trades using cumulative profit loss.

@dranokar you should look at the Portfolio Custom Backtester Interface (aka CBT/CBI) to learn how to calculate and interact with the cumulative P/L and exit all the open trades when a "gross" target or loss is reached.

There are some past threads that seem related to your problem, with code samples that may help you to experiment with the many objects, methods and properties exposed by portfolio interface.

An old, but still valid article (with many examples) to learn more about the AmiBroker Custom Backtester Interface is found on the User KB.
A search in this forum and with Google in the official KB will find additional examples to learn from.


As usual, @beppe has been very helpful in providing answers and digging up previous posts. However, I would be a little careful with the first link, as this logic that worked for @pmfiorini may not be quite what you're looking for:

	totProfit = 0.0; maxProfit = 0.0;
		for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) {
			totProfit += trade.GetProfit();
			if ( totProfit > maxProfit ) {
				maxProfit = totProfit;
			//if ( maxProfit >= 500 )
			//	break;
			_TRACE("maxProfit: " + NumToStr( maxProfit ) ); 
		if ( maxProfit >= 200 ) {
			//_TRACE("maxProfit: " + NumToStr( maxProfit ) ); 
			for ( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() ) {
				//_TRACE("Made it here...");
				//_TRACE("trade.GetPrice(i, C): " + NumToStr( trade.GetPrice(i, "C") ) ); 
				bo.ExitTrade(i, trade.Symbol, trade.GetPrice(i, "C"), 3);

Specifically, the totProfit variable is the sum of the profits and losses from all open trades (as you would expect), but the maxProfit variable is essentially ignoring/discounting some (but not all) of the losing trades. Therefore, I would only use totProfit when deciding whether to exit all open positions.