Hi
I'm trying calculate Van Tharp's r multiple & expectancy by listing
the pertrade values in the custom backtester's add custom metric, but
this is as far as I got, when modifying the sample
from the help file. Instead of fixed % trade risk , I'm using a
variable trade risk values.
And I get the commented error. Any ideas anyone what I'm doing wrong.
If there is one thing that AB confuses me with & that's dates!..value
when & custom backtesting !!
Any assistance will be greatly appreciated.
Regards
justinwomomo
=====
TradeRisk = IIf(Buy, EntryPrice - ExitPrice ,0);
// ...
AddToComposite(TradeRisk, "~trisk"+Name(),"C",atcFlagDefaults |
atcFlagEnableInBacktest );
// .......
SetCustomBacktestProc("");
// MaxLossPercentStop = 10; // 10% max. loss stop .... but I want $
value risk
/* custom-backtest procedure follows */
if( Status("action") == actionPortfolio )
{
_TRACE("Custom BT Actioned");
bo = GetBacktesterObject();
bo.Backtest(1); // run default backtest procedure
SumProfitPerRisk = 0;
NumTrades = 0;
// iterate through closed trades first
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
// risk is calculated as the maximum value we can loose per trade
dt = DateTime();
Risk = ValueWhen((Foreign("~trisk_" + trade.Symbol, dt )==
Trade.EntryDateTime), Foreign("~trisk_" + trade.Symbol,"C")) ;
_TRACE(" Trade.EntryDateTime = " + Trade.EntryDateTime + " Risk = "
+ Risk );
/*
Risk = ValueWhen((Foreign("~trisk_" + trade.Symbol, dt )
------------------------------------------------------------^
Error 5.
Argument #2 has incorrect type (the function expects different
argument type here)
*/
// Risk = ( MaxLossPercentStop / 100 ) * trade.GetEntryValue();
// how 2 get $ val risk
RMultiple = trade.GetProfit()/Risk ;
trade.AddCustomMetric("Initial risk $", Risk );
trade.AddCustomMetric("R-Multiple", RMultiple );
SumProfitPerRisk = SumProfitPerRisk + RMultiple;
NumTrades++;
}
expectancy3 = SumProfitPerRisk / NumTrades;
bo.AddCustomMetric( "Expectancy (per risk)", expectancy3 );
bo.ListTrades();
}
===========================