Hi All,
I am asking about adding text and number in backtest custom column.
I set a unique parameter (MovingAverage and Size) for each Name and you can see in the chart, each Name already plotting the unique parameters as it suppose. But the backtest custom column didn't return it's unique parameters, it keep returning the default one.
Kindly help, thank you.
switch (Name())
{
case "AAPL":
MovingAverage = 5;
Size = "Big Cap";
break;
case "UBER":
MovingAverage = 10;
Size = "Medium Cap";
break;
default:
MovingAverage = 20;
Size = "Default Cap";
break;
}
SetCustomBacktestProc( "" );
if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject();
bo.Backtest(True);
for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
{
if (!trade.IsOpen())
trade.AddCustomMetric("Size", Size);
trade.AddCustomMetric("MovingAverage", MovingAverage);
}
for (trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos())
{
trade.AddCustomMetric("Size", Size);
trade.AddCustomMetric("MovingAverage", MovingAverage);
}
bo.ListTrades();
}
Buy = Cross(C, MA(C, MovingAverage));
Sell = Cross(MA(C, MovingAverage), C);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
//StaticVarSet( Name() + "MovingAverage", MovingAverage );
//StaticVarSet( Name() + "Size", Size );
Plot(C, StrFormat( "(%s)",size) +"\nClose", colorYellow, styleCandle);
Plot(MA(C, MovingAverage), "\nMoving Average (" + NumToStr(MovingAverage, 0) + ")", colorRed, styleLine);