Australian (ASX) Stock Market Forum

Amibroker Backtest report: Get profit/loss as a percentage of initial stop loss

Joined
17 January 2013
Posts
1
Reactions
0
Hi guys,

I'm trying to get a column in the backtest report that will show me the profit/loss as a percentage of my initial stop loss (From the Van Tharp idea: I would like to get the distribution of my R results)

From the custom backtest I can access the entry value and the close value of the trade, but not the initial stop loss. I used this as a base for my code: http://www.amibroker.com/guide/a_custommetrics.html

My problem is that the initial stop loss is not fixed, it's related with ATR.

Someone knows how can I do that?

Thanks in advance.

My code:


_SECTION_BEGIN("AFL Example");


/* ADD COLUMNS TO REPORT */

SetCustomBacktestProc("");

if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();

bo.Backtest(1); /* run default backtest procedure*/

/* iterate through closed trades */
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{

/*This is not working */
InitialStopLossPoints = 2.0 * ATR(20);

RResult = trade.GetProfit() / InitialStopLossPoints ;

trade.AddCustomMetric("Initial risk", InitialStopLossPoints );
trade.AddCustomMetric("R-Result ", RResult );
}
bo.ListTrades();
}



/* TRADE SECTION */

Price = C;


MA1 = MA(Price, 4);
MA2 = MA(Price, 15);

currentEquity = Equity();

InitialStopLossPoints = 2.0 * ATR(20);

ApplyStop(stopTypeLoss ,stopModePoint, InitialStopLossPoints , 1);

Buy = Cross(MA1, MA2);
Sell = Cross(MA2, MA1);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

_SECTION_END();
 
Top