Hello, group members,
I am trying to modify a code I have found here - How to add user-defined metrics to backtest/optimization report
I want to use Example 3 and add Van Tharps R-multiple column in the backtest report. The example from the link works when the Stop Loss is % of the entry price and my desire is to make the code work when the SL is defined by ATR from the previous bar. I know that I have to change lines 19 and 20 but I don
t know do it. Can somebody help me?
SetCustomBacktestProc("");
// original Stop Loss
//MaxLossPercentStop = 10; // 10% max. loss stop
StopLossAmount = Ref(ATR(20),-1); // my version of Stop Loss
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(1);
SumProfitPerRisk = 0;
NumTrades = 0;
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
Risk = StopLossAmount; // is that correct?
RMultiple = // I need help here
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();