[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Custom Metric not working in Alpha 5.27.1



PureBytes Links

Trading Reference Links

Hi all,

In previous beta versions the following custom metrics were working fine.  Now I get message Error 10...it also is below.  If anyone sees a problem with the code I would greatly appreciate the help.  I pieced it together from several examples but still have difficulty understanding it.  Thanks

SetCustomBacktestProc("");
	function FindEquityAtDateTime( eq, dt, Value )
{
	found = -1;
	for( i = 0; i < BarCount AND found == -1; i++ )
{
	if( dt[ i ] == Value ) found = i;
}
	return IIf( found != -1, eq[ found - 0 ], Null );
}
	if( Status("action") == actionPortfolio )
{
	bo = GetBacktesterObject();
	bo.Backtest(1);
	dt = DateTime();
	eq = Ref(Foreign("~~~EQUITY", "C" ),-1);

	for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
	EquityAtEntry = FindEquityAtDateTime( eq,dt,trade.EntryDateTime );
	PctLossGain = (trade.GetProfit()/EquityAtEntry)*100;
	trade.AddCustomMetric("Equity at Entry", EquityAtEntry );
	trade.AddCustomMetric("% Gain/Loss of Equity", PctLossGain );
	st = bo.GetPerformanceStats(0);
	pratio=(st.GetValue("WinnersPercent" )/100)*st.GetValue("PayoffRatio");

}
	bo.ListTrades();
	bo.AddCustomMetric( "Performance Ratio", pratio ); 

}


Error 10 Message/////////////////////////////////////////////////////
{

 if( dt[ i ] == Value ) found = i;

}

 return IIf( found != -1, eq[ found - 0
--------------------------------------^

Error 10.
Subscript out of range.
You must not access array elements outside 0..(BarCount-1) range.



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/