Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Z Score for backtesting for Amibroker (AFL)
EliStern
almost 14 years ago
Amibroker (AFL)

Rating:
5 / 5 (Votes 1)
Tags:
amibroker, backtest

I am not the author of this AFL. It was provided by dubi197 on one of the blog.

It calculates the z score through the custom backtester.

Similar Indicators / Formulas

Summary of Holdings
Submitted by AndrewThomas over 13 years ago
Accurate results of system (backtest)
Submitted by lmd2286 over 14 years ago
Visual BackTest V2
Submitted by sethmo almost 11 years ago
bad tick clean
Submitted by pious243 over 11 years ago
Williams Alligator System
Submitted by durgesh1712 about 13 years ago
*Level Breakout system*
Submitted by Tinych about 13 years ago

Indicator / Formula

Copy & Paste Friendly
SetOption("UseCustomBacktestProc", True );
SetCustomBacktestProc("",True);

if( Status("action") == actionPortfolio ) // point to correct iteration of backtest engine
{
	//initialize custom backtest engine
	//bo is backtestobject
	
	bo = GetBacktesterObject();
	
	bo.Backtest(); // run default backtest procedure
	st = bo.GetPerformanceStats(0); // get stats for all trades
	totalLossTrades = totalWinTrades = totalRuns = 0;
	for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
    {	//  Loop through all closed trades
        if (trade.GetProfit() > 0)	//  If this was a winning trade
        {
			if (totalWinTrades == 0) totalRuns++;
            totalWinTrades++;
			totalLossTrades = 0;			
        }
		if (trade.GetProfit() < 0)	//  If this was a winning trade
        {
			if (totalLossTrades == 0) totalRuns++;
            totalLossTrades++;
			totalWinTrades = 0;
        }
		
    }	//  End of for loop over all trades

	
	
	N = st.GetValue("AllQty");
	R = totalRuns;
	WIN = st.GetValue("WinnersQty");
	LOSS = st.GetValue("LosersQty");
	X = 2 * WIN * LOSS;
	Z_Score = (N*(R-0.5)-X)/SQRT((X*(X-N))/(N-1));
	
	
	bo.AddCustomMetric( "Z-Score",Z_Score );
	bo.AddCustomMetric( "totalRuns",totalRuns );
}


0 comments

Leave Comment

Please login here to leave a comment.

Back