How to get current open positions and their symbol names

How to get current open positions and their symbol names which are in trade, through our code?

I guess you are talking about portfolio backtester.

Open formula editor via CTRL+E
Then open code snippets window (see menu bar -> Window) and open section "Custom Backtest" and see item "CBT Hi-level + trade list".
(I have commented iteration of closed trades in below code)

// From Formula editor - Code snippets - "CBT Hi-level + trade list"
SetCustomBacktestProc(""); 
/* Custom-backtest procedure follows */
if( Status( "action" ) == actionPortfolio )
{
    bo = GetBacktesterObject();

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

    //for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
    //{
    //    _TRACE( "Symbol = " + trade.Symbol	); //  Use Trade object here
    //}

    // Iterate open positions and output symbol names
    for( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() )
    {
        _TRACE( "Open pos. Symbol = " + trade.Symbol	); //	//  Use Trade object here
    }
}

If you want to get open positions & symbol at each bar then you have to iterate Barcount in addition (see mid/low level CBT).

Thanx fxshrat,
Yes I have also clue to get this, (as code mentioned below). But here I want to get simultaneously traded symbols like : 'On which symbols we are exited on Last candle of the month and just after that now on current candle we want to stand our positions only on Those Symbols.' so is it possible to get just traded symbols in our code.

//***********
//********
StaticVarSet( "Date_" + Name(), DateTime() );

SetCustomBacktestProc("");
if ( Status( "action" ) == actionPortfolio )
{
	bo = GetBacktesterObject();
	bo.PreProcess();
	
	////
	//NSE Katan
	Katan= 1;
	Katan= Lastthrusday() OR nsekatan();
	Timenow= Hour()*100+Minute();
	KatanExitTime		= 1400;
	MyDay= DateNum();
	////
	
	for ( i = 0; i < BarCount; i++ )
	{	
		bo.ProcessTradeSignals( i );
		// iterate through open positions
		for ( openpos = bo.GetFirstOpenPos(); openpos; openpos = bo.GetNextOpenPos() )
		{
			
			//***
			if(Katan[i]==1 AND TimeNow[i+1] >= KatanExitTime)		//i+1 use to get just one candle before to exit
			{
				StaticVarSetText( "KatanNameTime_"+ openpos.Symbol +""+ MyDay[i],  openpos.Symbol);
			}
			//***
		}
		
	}
	
	bo.PostProcess();
}

//********
//***********

Then why do you waste peoples valuable time if you know that already?
Please read this thread:


mth = Month();
end_of_mth = mth != Ref( mth, 1);
//... Snippet
for ( sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal( i ) ) {
    isOpenPos = bo.FindOpenPos( sig.Symbol );
    // exit signals at end of month of open positions
    if ( sig.IsExit() AND end_of_mth[ i ] AND isOpenPos ) {
		_TRACE("Open pos. symbols = " + sig.Symbol);
    }    
}
// ...

yes here is it, thanx. and apologize for taking your valuable time but I think I have mentioned 'Current Open Positions', which was enough to understand. but its ok thank you again. :+1:

No, your second post it different to first post.
Also you didn't mention that you have worked with CBT code already.
No further specific details.

This leads to wasting time as in first response.

Your 2nd post info should have been in 1st post already.

There was no code in 1st post.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.