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

[amibroker] Custom bactester metrics & Van Tharps per trade r multiple



PureBytes Links

Trading Reference Links


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();
}

===========================





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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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/

<*> 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/