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

[amibroker] Need Help With Custom Backtest Procedure



PureBytes Links

Trading Reference Links

Hello, I am interested in having Amibroker compute the expectancy for
a trading system from backtesting according to Van K. Tharp's method.
I found this in the Amibroker help menu for Van Tharp:  

/* First we need to enable custom backtest procedure and 
** tell AmiBroker to use current formula 
*/ 

SetCustomBacktestProc(""); 

MaxLossPercentStop = 10; // 10% max. loss stop 

/* Now custom-backtest procedure follows */ 
if( Status("action") == actionPortfolio ) 
{ 
    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 
      // in this example we are using  max. loss stop 
      // it means we can not lose more than (MaxLoss%) of invested amount 
      // hence ris 

       Risk = ( MaxLossPercentStop / 100 ) * trade.GetEntryValue(); 
       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(); 

} 

// your trading system here 

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

The problem is that I do not want to use a stop loss based on a fixed
percentage. The stop loss I want to use is a multiple of the average
true range for the stock.

However, no output results if in the above code, I replace:

Risk = ( MaxLossPercentStop / 100 ) * trade.GetEntryValue(); 

with:

Risk = multiple*ATR(14);


Does anyone know of a solution? Another way to define risk would be as:

Risk = bo.Equity/trade.GetEntryValue();

However, bo.Equity is always constant, and so that doesn't work
either, so I don't what to do.



Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.27/517 - Release Date: 11/3/2006