PureBytes Links
Trading Reference Links
|
Jason,
Try this, and watch out for word wrap:
//Your system here
//-------------------------CUSTOM INTERFACE FOR CALCULATING EXPECTANCY
--------------------
VPd = Optimize("VPd",55,1,71,2); // volatility period
StopMultiplier = Optimize("StopMultiplier",1.75,1,3,0.25); // dynamic
stop multiplier
Stoploss = StopMultiplier * Ref(ATR(VPd),-1); //dynamic stop parameter
for stoploss
r = Optimize("r",0.75,0.5,3,0.25); // risk as percent of current equity
SetCustomBacktestProc("");
MaxLossPointStop = Stoploss;
function FindEquityAtDateTime( eq, dt, Value )
{
found = -1;
for( i = 0; i < BarCount AND found == -1; i++ )
{
if( dt[ i ] == Value ) found = i;
}
req = GetOption("InitialEquity");
if(found > 0) req = eq[found-1];
return req;
}
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(1); // run default backtest procedure
SumProfitPerRisk = 0;
NumTrades = 0;
dt = DateTime();
eq = Foreign("~~~EQUITY", "C" );
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
EquityAtEntry = FindEquityAtDateTime( eq, dt, trade.EntryDateTime);
Risk = r/100 * EquityAtEntry ; // risk defined as a constant r%
of current Equity
RiskAsPecentOfCurrentEquity = 100 * Risk / EquityAtEntry;
RMultiple = trade.GetProfit()/Risk;
trade.AddCustomMetric("Initial risk $", Risk );
trade.AddCustomMetric("Equity at entry", EquityAtEntry );
trade.AddCustomMetric("Risk as % of Eq.",RiskAsPecentOfCurrentEquity );
trade.AddCustomMetric("R-Multiple", RMultiple );
SumProfitPerRisk = SumProfitPerRisk + RMultiple;
NumTrades++;
}
Expectancy = SumProfitPerRisk / NumTrades;
bo.AddCustomMetric( "Expectancy (per risk)", Expectancy );
bo.ListTrades();
}
Al Venosa
On Fri, 18 Mar 2005 15:01:16 -0000, jhart_1972 <jhart_1972@xxxxxxxxx> wrote:
>
>
> I'm trying to include an "R" multiple of expectency in a backtest
> result but forgot how to manipulate the report by code in the
> backtest mode. I believe this new function was added in version
> 4.67. Could someone please post a sample code that allows for this
> to show up in the backtester report. I've searched the archives but
> can't find the expectency code I'm looking for..... Purebytes
> doesn't allow you to search thru 2005 posts yet
>
> Thanks,
> Jason
>
>
> Please note that this group is for discussion between users only.
>
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~->
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> 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/
|