How to add PositionScore to backtest results

I am new to CBT engine and I am wanting to add PositionScore to the Analysis window results for a backtest. How do I get the signal object for a trade object so I can access the signal property positionscore or is there a better way of doing this?

Run "Detailed log" report mode. It shows all scores out-of-the-box.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

Thanks Tomasz,

Yes, I see it with the "Detailed log" setting however I want to show it when "Results list shows" setting is set to "Trade list" so it lines up with the other info with Trade list view (Results list tab).

I am assuming I can do this with the CBT using the trade objects AddCustomMetric method however the positionScore is a property of the signal object. So how would I get the signal object for a given trade object?

Thanks

One easy way is to store the calculated PositionScore in static variables for each of the symbols in the test. Then you can recall that array in the custom backtester and tease out the value at the time of trade entry using Lookup. The values will then appear in an additional column in the trade list.

RSI2 	= RSI(2);
Buy 	= RSI2 < 10;
Sell 	= RSI2 > 50;

PositionScore = 100 - RSI2;

StaticVarSet("PositionScore" + Name(), PositionScore); // Store PositionScore for each symbol
SetCustomBacktestProc(""); 
if( Status("action") == actionPortfolio ) 
{ 
	bo = GetBacktesterObject(); 
	bo.Backtest(True); // run default backtest procedure 

    for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
    {
		PosScore 		= StaticVarGet("PositionScore" + trade.Symbol); // Recall stored PositionScore for this trade's symbol
		PosScoreAtEntry = Lookup(PosScore, trade.EntryDateTime); // Find the value of PositionScore at the time of trade entry
		trade.AddCustomMetric("PosScore At Entry", PosScoreAtEntry); // Output it to an extra column on the trade list
    }
    
    bo.ListTrades();

}

image

4 Likes

This technique is described in the Knowledge Base and allows to display ANYTHING (any array from first phase) in CBT:

1 Like

Thanks to both of you

1 Like

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